Skip to content

Commit 0954938

Browse files
keesgregkh
authored andcommitted
hardening: Avoid harmless Clang option under CONFIG_INIT_STACK_ALL_ZERO
commit f02003c upstream. Currently under Clang, CC_HAS_AUTO_VAR_INIT_ZERO requires an extra -enable flag compared to CC_HAS_AUTO_VAR_INIT_PATTERN. GCC 12[1] will not, and will happily ignore the Clang-specific flag. However, its presence on the command-line is both cumbersome and confusing. Due to GCC's tolerant behavior, though, we can continue to use a single Kconfig cc-option test for the feature on both compilers, but then drop the Clang-specific option in the Makefile. In other words, this patch does not change anything other than making the compiler command line shorter once GCC supports -ftrivial-auto-var-init=zero. [1] https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a25e0b5e6ac8a77a71c229e0a7b744603365b0e9 Cc: Greg Kroah-Hartman <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: [email protected] Fixes: dcb7c0b ("hardening: Clarify Kconfig text for auto-var-init") Suggested-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Reviewed-by: Nick Desaulniers <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Acked-by: Will Deacon <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 73687c5 commit 0954938

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,12 @@ endif
844844

845845
# Initialize all stack variables with a zero value.
846846
ifdef CONFIG_INIT_STACK_ALL_ZERO
847-
# Future support for zero initialization is still being debated, see
848-
# https://bugs.llvm.org/show_bug.cgi?id=45497. These flags are subject to being
849-
# renamed or dropped.
850847
KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
848+
ifdef CONFIG_CC_IS_CLANG
849+
# https://bugs.llvm.org/show_bug.cgi?id=45497
851850
KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
852851
endif
852+
endif
853853

854854
# While VLAs have been removed, GCC produces unreachable stack probes
855855
# for the randomize_kstack_offset feature. Disable it for all compilers.

security/Kconfig.hardening

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ config CC_HAS_AUTO_VAR_INIT_PATTERN
2323
def_bool $(cc-option,-ftrivial-auto-var-init=pattern)
2424

2525
config CC_HAS_AUTO_VAR_INIT_ZERO
26+
# GCC ignores the -enable flag, so we can test for the feature with
27+
# a single invocation using the flag, but drop it as appropriate in
28+
# the Makefile, depending on the presence of Clang.
2629
def_bool $(cc-option,-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang)
2730

2831
choice
2932
prompt "Initialize kernel stack variables at function entry"
3033
default GCC_PLUGIN_STRUCTLEAK_BYREF_ALL if COMPILE_TEST && GCC_PLUGINS
3134
default INIT_STACK_ALL_PATTERN if COMPILE_TEST && CC_HAS_AUTO_VAR_INIT_PATTERN
32-
default INIT_STACK_ALL_ZERO if CC_HAS_AUTO_VAR_INIT_PATTERN
35+
default INIT_STACK_ALL_ZERO if CC_HAS_AUTO_VAR_INIT_ZERO
3336
default INIT_STACK_NONE
3437
help
3538
This option enables initialization of stack variables at

0 commit comments

Comments
 (0)