feat(rcar3): enable the stack protection

This commit changes ENABLE_STACK_PROTECTOR value to "strong" for
enabling the stack protector by canary.

Signed-off-by: Koichi Yamaguchi <koichi.yamaguchi.zb@hitachi.com>
Signed-off-by: Toshiyuki Ogasahara <toshiyuki.ogasahara.bo@hitachi.com>
Signed-off-by: Yoshifumi Hosoya <yoshifumi.hosoya.wj@renesas.com>
Change-Id: Ice351d23c98daf12737a5e65cef743035d62dabe
This commit is contained in:
Toshiyuki Ogasahara 2021-07-12 18:40:26 +09:00 committed by Marek Vasut
parent 57410eebe6
commit cfa466ab73
2 changed files with 42 additions and 0 deletions

View file

@ -6,6 +6,8 @@
include plat/renesas/common/common.mk
ENABLE_STACK_PROTECTOR := strong
ifndef LSI
$(error "Error: Unknown LSI. Please use LSI=<LSI name> to specify the LSI")
else
@ -333,6 +335,10 @@ BL2_SOURCES += common/image_decompress.c \
$(ZLIB_SOURCES)
endif
ifneq (${ENABLE_STACK_PROTECTOR},0)
BL_COMMON_SOURCES += plat/renesas/rcar/rcar_stack_protector.c
endif
ifeq (${RCAR_GEN3_ULCB},1)
BL31_SOURCES += drivers/renesas/rcar/cpld/ulcb_cpld.c
endif

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2021-2023, Renesas Electronics Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdint.h>
#include <arch_helpers.h>
#include <common/debug.h>
#define RANDOM_CANARY_VALUE ((u_register_t)0xDFF5FC8A720E205EULL)
u_register_t plat_get_stack_protector_canary(void)
{
u_register_t cnt;
u_register_t seed;
u_register_t mul;
u_register_t ret;
uintptr_t val1 = (uintptr_t)__builtin_return_address(0U);
uintptr_t val2 = (uintptr_t)__builtin_frame_address(0U);
cnt = read_cntpct_el0();
seed = (cnt ^ RANDOM_CANARY_VALUE) & ULONG_MAX;
ret = seed;
if ((ULONG_MAX/val1) > seed) {
mul = (u_register_t)(val1 * seed);
if ((mul < ULONG_MAX) &&
((ULONG_MAX - (u_register_t)mul) > val2)) {
ret = mul + val2;
}
}
return ret;
}