summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorJerome Forissier <jerome@forissier.org>2020-06-04 16:44:57 +0200
committerJérôme Forissier <jerome@forissier.org>2020-08-14 12:19:21 +0200
commite2f03e0736a6774eb8fb07ce8dc55d8ed186b67b (patch)
tree75e489ec751f457e76a2254118db663b2e10429e /mk
parent0733f3d1de1a076c8fd07727464cc1f27e909830 (diff)
core: add stack overflow detection
This commit introduces CFG_CORE_DEBUG_CHECK_STACKS to check the stack limits using compiler instrumentation (-finstrument-functions). When enabled, the C compiler will insert entry and exit hooks in all functions in the TEE core. On entry, the stack pointer is checked and if an overflow is detected, panic() is called. How is this helpful since we have stack canaries already? 1. When a dead canary is found, the call stack will give no indication of the root cause of the corruption which may have happened quite some time before. Running the test case again with a debugger attached and a watchpoint on the canary is not always an option. 2. The system may corrupt the stack and hang in an exception handler before the first canary check, for instance, during boot when the temporary stack is used. This code will likely catch such issues, too. The downside is increased stack usage and a significant runtime overhead which is why this feature should be enabled only for troubleshooting. Signed-off-by: Jerome Forissier <jerome@forissier.org> Tested-by: Jerome Forissier <jerome@forissier.org> (QEMU, QEMUv8) Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Diffstat (limited to 'mk')
-rw-r--r--mk/config.mk5
1 files changed, 5 insertions, 0 deletions
diff --git a/mk/config.mk b/mk/config.mk
index 1fe65576..c70fd473 100644
--- a/mk/config.mk
+++ b/mk/config.mk
@@ -343,6 +343,11 @@ CFG_CORE_SANITIZE_KADDRESS ?= n
# Add stack guards before/after stacks and periodically check them
CFG_WITH_STACK_CANARIES ?= y
+# Use compiler instrumentation to troubleshoot stack overflows.
+# When enabled, most C functions check the stack pointer against the current
+# stack limits on entry and panic immediately if it is out of range.
+CFG_CORE_DEBUG_CHECK_STACKS ?= n
+
# Device Tree support
#
# When CFG_DT is enabled core embeds the FDT library (libfdt) allowing