Skip to content

Commit a8f0b1f

Browse files
committed
kstack_erase: Support Clang stack depth tracking
Wire up CONFIG_KSTACK_ERASE to Clang 21's new stack depth tracking callback[1] option. Link: https://clang.llvm.org/docs/SanitizerCoverage.html#tracing-stack-depth [1] Acked-by: Nicolas Schier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 6676fd3 commit a8f0b1f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

scripts/Makefile.kstack_erase

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ kstack-erase-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK_VERBOSE) += -fplugin-arg-stack
88
DISABLE_KSTACK_ERASE := -fplugin-arg-stackleak_plugin-disable
99
endif
1010

11+
ifdef CONFIG_CC_IS_CLANG
12+
kstack-erase-cflags-y += -fsanitize-coverage=stack-depth
13+
kstack-erase-cflags-y += -fsanitize-coverage-stack-depth-callback-min=$(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE)
14+
DISABLE_KSTACK_ERASE := -fno-sanitize-coverage=stack-depth
15+
endif
16+
1117
KSTACK_ERASE_CFLAGS := $(kstack-erase-cflags-y)
1218

1319
export STACKLEAK_CFLAGS DISABLE_KSTACK_ERASE

security/Kconfig.hardening

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ choice
8282

8383
endchoice
8484

85+
config CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
86+
def_bool $(cc-option,-fsanitize-coverage-stack-depth-callback-min=1)
87+
8588
config KSTACK_ERASE
8689
bool "Poison kernel stack before returning from syscalls"
8790
depends on HAVE_ARCH_KSTACK_ERASE
88-
depends on GCC_PLUGINS
91+
depends on GCC_PLUGINS || CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
8992
help
9093
This option makes the kernel erase the kernel stack before
9194
returning from system calls. This has the effect of leaving

0 commit comments

Comments
 (0)