History

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

Dan Li committed 4 years ago

Commit afcf5441 parent 575d6b73 files · +15 −10Browse files

Unified · Split

3 files
  1. arch/Kconfig +10 −9
  2. arch/arm64/Kconfig +1 −1
  3. include/linux/compiler-gcc.h +4 −0
arch/Kconfig+10−9
@@ -599,21 +599,22 @@ config STACKPROTECTOR_STRONG · 598 unmodified lines
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+1−1
@@ -1239,7 +1239,7 @@ config HW_PERF_EVENTS · 1238 unmodified lines
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+4−0
@@ -97,6 +97,10 @@ · 96 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t