]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
kstack_erase: Support Clang stack depth tracking
authorKees Cook <kees@kernel.org>
Thu, 24 Jul 2025 05:50:28 +0000 (22:50 -0700)
committerKees Cook <kees@kernel.org>
Sat, 26 Jul 2025 21:28:35 +0000 (14:28 -0700)
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
Acked-by: Nicolas Schier <n.schier@avm.de>
Link: https://lore.kernel.org/r/20250724055029.3623499-4-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
scripts/Makefile.kstack_erase
security/Kconfig.hardening

index 5223d3a358172c0c117dd862d32a2a71c93615e1..c7bc2379e1133730eb6091c08b96b26afe8126cf 100644 (file)
@@ -8,6 +8,12 @@ kstack-erase-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK_VERBOSE) += -fplugin-arg-stack
 DISABLE_KSTACK_ERASE := -fplugin-arg-stackleak_plugin-disable
 endif
 
+ifdef CONFIG_CC_IS_CLANG
+kstack-erase-cflags-y += -fsanitize-coverage=stack-depth
+kstack-erase-cflags-y += -fsanitize-coverage-stack-depth-callback-min=$(CONFIG_KSTACK_ERASE_TRACK_MIN_SIZE)
+DISABLE_KSTACK_ERASE  := -fno-sanitize-coverage=stack-depth
+endif
+
 KSTACK_ERASE_CFLAGS   := $(kstack-erase-cflags-y)
 
 export STACKLEAK_CFLAGS DISABLE_KSTACK_ERASE
index f7aa2024ab25fb88ad4d3dab8ba4f1c569cfb57c..b9a5bc3430aa2649e94b8962e718b4112ddead3c 100644 (file)
@@ -82,10 +82,13 @@ choice
 
 endchoice
 
+config CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
+       def_bool $(cc-option,-fsanitize-coverage-stack-depth-callback-min=1)
+
 config KSTACK_ERASE
        bool "Poison kernel stack before returning from syscalls"
        depends on HAVE_ARCH_KSTACK_ERASE
-       depends on GCC_PLUGINS
+       depends on GCC_PLUGINS || CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
        help
          This option makes the kernel erase the kernel stack before
          returning from system calls. This has the effect of leaving