aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorten Borup Petersen <morten.petersen@arm.com>2020-01-29 16:44:17 +0000
committerAbdellatif El Khlifi <abdellatif.elkhlifi@arm.com>2020-02-13 10:29:47 +0000
commit7f0daaa97110efc6a077241227d6fa9db29a7808 (patch)
tree7dfbc9bec27da7f352eff2b33febeb8d34fdf1c3
parentce620fa9f2b223aaba2b4db7729860663751f559 (diff)
downloadtrusted-firmware-a-7f0daaa97110efc6a077241227d6fa9db29a7808.tar.gz
corstone700: adding support for stack protector for the FVP
Adding support for generating a semi-random number required for enabling building TF-A with stack protector support. TF-A for corstone-700 may now be built using ENABLE_STACK_PROTECTOR=all Change-Id: I03e1be1a8d4e4a822cf286f3b9ad4da4337ca765 Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
-rw-r--r--plat/arm/board/corstone700/corstone700_stack_protector.c35
-rw-r--r--plat/arm/board/corstone700/sp_min/sp_min-corstone700.mk8
2 files changed, 42 insertions, 1 deletions
diff --git a/plat/arm/board/corstone700/corstone700_stack_protector.c b/plat/arm/board/corstone700/corstone700_stack_protector.c
new file mode 100644
index 000000000..6fd09da5b
--- /dev/null
+++ b/plat/arm/board/corstone700/corstone700_stack_protector.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdint.h>
+
+#include <arch_helpers.h>
+#include <plat/common/platform.h>
+
+static uint32_t plat_generate_random_number(void)
+{
+ uintptr_t return_addr = (uintptr_t)__builtin_return_address(0U);
+ uintptr_t frame_addr = (uintptr_t)__builtin_frame_address(0U);
+ uint64_t cntpct = read_cntpct_el0();
+
+ /* Generate 32-bit pattern: saving the 2 least significant bytes
+ * in random_lo and random_hi
+ */
+ uint16_t random_lo = (uint16_t)(
+ (((uint64_t)return_addr) << 13) ^ frame_addr ^ cntpct
+ );
+
+ uint16_t random_hi = (uint16_t)(
+ (((uint64_t)frame_addr) << 15) ^ return_addr ^ cntpct
+ );
+
+ return (((uint32_t)random_hi) << 16) | random_lo;
+}
+
+u_register_t plat_get_stack_protector_canary(void)
+{
+ return plat_generate_random_number(); /* a 32-bit pattern is returned */
+}
diff --git a/plat/arm/board/corstone700/sp_min/sp_min-corstone700.mk b/plat/arm/board/corstone700/sp_min/sp_min-corstone700.mk
index 57e1ec3e4..acee6c39c 100644
--- a/plat/arm/board/corstone700/sp_min/sp_min-corstone700.mk
+++ b/plat/arm/board/corstone700/sp_min/sp_min-corstone700.mk
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2019-2020, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -15,4 +15,10 @@ BL32_SOURCES += drivers/cfi/v2m/v2m_flash.c \
plat/arm/board/corstone700/sp_min/corstone700_sp_min_setup.c \
${CORSTONE700_GIC_SOURCES}
+ifneq (${ENABLE_STACK_PROTECTOR},0)
+ ifneq (${ENABLE_STACK_PROTECTOR},none)
+ BL32_SOURCES += plat/arm/board/corstone700/corstone700_stack_protector.c
+ endif
+endif
+
include plat/arm/common/sp_min/arm_sp_min.mk