summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/libutils/ext/include/compiler.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/libutils/ext/include/compiler.h b/lib/libutils/ext/include/compiler.h
index 21cbc11e..c363df9c 100644
--- a/lib/libutils/ext/include/compiler.h
+++ b/lib/libutils/ext/include/compiler.h
@@ -62,6 +62,7 @@
#define __nex_data
#endif /* CFG_VIRTUALIZATION */
#define __noprof __attribute__((no_instrument_function))
+#define __nostackcheck __attribute__((no_instrument_function))
#define __compiler_bswap64(x) __builtin_bswap64((x))
#define __compiler_bswap32(x) __builtin_bswap32((x))