Skip to content

Commit f627b51

Browse files
committed
compiler_types: Provide __no_kstack_erase to disable coverage only on Clang
In order to support Clang's stack depth tracking (for Linux's kstack_erase feature), the coverage sanitizer needed to be disabled for __init (and __head) section code. Doing this universally (i.e. for GCC too) created a number of unexpected problems, ranging from changes to inlining logic to failures to DCE code on earlier GCC versions. Since this change is only needed for Clang, specialize it so that GCC doesn't see the change as it isn't needed there (the GCC implementation of kstack_erase uses a GCC plugin that removes stack depth tracking instrumentation from __init sections during a late pass in the IR). Successfully build and boot tested with GCC 12 and Clang 22. Fixes: 381a38e ("init.h: Disable sanitizer coverage for __init and __head") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-by: Marco Elver <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 94fd446 commit f627b51

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
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 __no_sanitize_coverage
8+
#define __head __section(".head.text") __no_sanitize_undefined __no_kstack_erase
99
#endif
1010

1111
struct x86_mapping_info {

include/linux/compiler-clang.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
#define __no_sanitize_coverage
9090
#endif
9191

92+
/* Only Clang needs to disable the coverage sanitizer for kstack_erase. */
93+
#define __no_kstack_erase __no_sanitize_coverage
94+
9295
#if __has_feature(shadow_call_stack)
9396
# define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
9497
#endif

include/linux/compiler_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ struct ftrace_likely_data {
424424
# define randomized_struct_fields_end
425425
#endif
426426

427+
#ifndef __no_kstack_erase
428+
# define __no_kstack_erase
429+
#endif
430+
427431
#ifndef __noscs
428432
# define __noscs
429433
#endif

include/linux/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
discard it in modules) */
5252
#define __init __section(".init.text") __cold __latent_entropy \
5353
__noinitretpoline \
54-
__no_sanitize_coverage
54+
__no_kstack_erase
5555
#define __initdata __section(".init.data")
5656
#define __initconst __section(".init.rodata")
5757
#define __exitdata __section(".exit.data")

0 commit comments

Comments
 (0)