Skip to content

Commit 2b2fd5c

Browse files
keesintel-lab-lkp
authored andcommitted
stackleak: Support Clang stack depth tracking
Wire up stackleak to Clang's proposed[1] stack depth tracking callback option. While __noinstr already contained __no_sanitize_coverage, it was still needed for __init and __head section markings. This is needed to make sure the callback is not executed in unsupported contexts. Link: llvm/llvm-project#138323 [1] Signed-off-by: Kees Cook <[email protected]>
1 parent bcec56b commit 2b2fd5c

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

arch/x86/include/asm/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#if defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 170000
66
#define __head __section(".head.text") __no_sanitize_undefined __no_stack_protector
77
#else
8-
#define __head __section(".head.text") __no_sanitize_undefined
8+
#define __head __section(".head.text") __no_sanitize_undefined __no_sanitize_coverage
99
#endif
1010

1111
struct x86_mapping_info {

include/linux/init.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949

5050
/* These are for everybody (although not all archs will actually
5151
discard it in modules) */
52-
#define __init __section(".init.text") __cold __latent_entropy __noinitretpoline
52+
#define __init __section(".init.text") __cold __latent_entropy \
53+
__noinitretpoline \
54+
__no_sanitize_coverage
5355
#define __initdata __section(".init.data")
5456
#define __initconst __section(".init.rodata")
5557
#define __exitdata __section(".exit.data")

scripts/Makefile.ubsan

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ ubsan-integer-wrap-cflags-$(CONFIG_UBSAN_INTEGER_WRAP) += \
2222
-fsanitize=implicit-unsigned-integer-truncation \
2323
-fsanitize-ignorelist=$(srctree)/scripts/integer-wrap-ignore.scl
2424
export CFLAGS_UBSAN_INTEGER_WRAP := $(ubsan-integer-wrap-cflags-y)
25+
26+
ifdef CONFIG_CC_IS_CLANG
27+
stackleak-cflags-$(CONFIG_STACKLEAK) += \
28+
-fsanitize-coverage=stack-depth \
29+
-fsanitize-coverage-stack-depth-callback-min=$(CONFIG_STACKLEAK_TRACK_MIN_SIZE)
30+
export STACKLEAK_CFLAGS := $(stackleak-cflags-y)
31+
ifdef CONFIG_STACKLEAK
32+
DISABLE_STACKLEAK := -fno-sanitize-coverage=stack-depth
33+
endif
34+
export DISABLE_STACKLEAK
35+
KBUILD_CFLAGS += $(STACKLEAK_CFLAGS)
36+
endif

security/Kconfig.hardening

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ config GCC_PLUGIN_STRUCTLEAK_VERBOSE
158158
initialized. Since not all existing initializers are detected
159159
by the plugin, this can produce false positive warnings.
160160

161+
config CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
162+
def_bool $(cc-option,-fsanitize-coverage-stack-depth-callback-min=1)
163+
161164
config STACKLEAK
162165
bool "Poison kernel stack before returning from syscalls"
163166
depends on HAVE_ARCH_STACKLEAK
164-
depends on GCC_PLUGINS
167+
depends on GCC_PLUGINS || CC_HAS_SANCOV_STACK_DEPTH_CALLBACK
165168
help
166169
This option makes the kernel erase the kernel stack before
167170
returning from system calls. This has the effect of leaving

0 commit comments

Comments
 (0)