Skip to content

Commit afcf544

Browse files
ashimida123kees
authored andcommitted
arm64: Add gcc Shadow Call Stack support
Shadow call stacks will be available in GCC >= 12, this patch makes the corresponding kernel configuration available when compiling the kernel with the gcc. Note that the implementation in GCC is slightly different from Clang. With SCS enabled, functions will only pop x30 once in the epilogue, like: str x30, [x18], #8 stp x29, x30, [sp, #-16]! ...... - ldp x29, x30, [sp], #16 //clang + ldr x29, [sp], #16 //GCC ldr x30, [x18, #-8]! Link: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ce09ab17ddd21f73ff2caf6eec3b0ee9b0e1a11e Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Signed-off-by: Dan Li <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 575d6b7 commit afcf544

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

arch/Kconfig

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,22 @@ config STACKPROTECTOR_STRONG
599599
config ARCH_SUPPORTS_SHADOW_CALL_STACK
600600
bool
601601
help
602-
An architecture should select this if it supports Clang's Shadow
603-
Call Stack and implements runtime support for shadow stack
602+
An architecture should select this if it supports the compiler's
603+
Shadow Call Stack and implements runtime support for shadow stack
604604
switching.
605605

606606
config SHADOW_CALL_STACK
607-
bool "Clang Shadow Call Stack"
608-
depends on CC_IS_CLANG && ARCH_SUPPORTS_SHADOW_CALL_STACK
607+
bool "Shadow Call Stack"
608+
depends on ARCH_SUPPORTS_SHADOW_CALL_STACK
609609
depends on DYNAMIC_FTRACE_WITH_REGS || !FUNCTION_GRAPH_TRACER
610610
help
611-
This option enables Clang's Shadow Call Stack, which uses a
612-
shadow stack to protect function return addresses from being
613-
overwritten by an attacker. More information can be found in
614-
Clang's documentation:
611+
This option enables the compiler's Shadow Call Stack, which
612+
uses a shadow stack to protect function return addresses from
613+
being overwritten by an attacker. More information can be found
614+
in the compiler's documentation:
615615

616-
https://clang.llvm.org/docs/ShadowCallStack.html
616+
- Clang: https://clang.llvm.org/docs/ShadowCallStack.html
617+
- GCC: https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#Instrumentation-Options
617618

618619
Note that security guarantees in the kernel differ from the
619620
ones documented for user space. The kernel must store addresses

arch/arm64/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ config HW_PERF_EVENTS
12391239
config ARCH_HAS_FILTER_PGPROT
12401240
def_bool y
12411241

1242-
# Supported by clang >= 7.0
1242+
# Supported by clang >= 7.0 or GCC >= 12.0.0
12431243
config CC_HAVE_SHADOW_CALL_STACK
12441244
def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18)
12451245

include/linux/compiler-gcc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
#define KASAN_ABI_VERSION 4
9898
#endif
9999

100+
#ifdef CONFIG_SHADOW_CALL_STACK
101+
#define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
102+
#endif
103+
100104
#if __has_attribute(__no_sanitize_address__)
101105
#define __no_sanitize_address __attribute__((no_sanitize_address))
102106
#else

0 commit comments

Comments
 (0)