Skip to content

Commit 7434626

Browse files
keesgregkh
authored andcommitted
hardening: Remove Clang's enable flag for -ftrivial-auto-var-init=zero
commit 607e57c upstream. Now that Clang's -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang option is no longer required, remove it from the command line. Clang 16 and later will warn when it is used, which will cause Kconfig to think it can't use -ftrivial-auto-var-init=zero at all. Check for whether it is required and only use it when so. Cc: Nathan Chancellor <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Fixes: f02003c ("hardening: Avoid harmless Clang option under CONFIG_INIT_STACK_ALL_ZERO") Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0954938 commit 7434626

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ endif
845845
# Initialize all stack variables with a zero value.
846846
ifdef CONFIG_INIT_STACK_ALL_ZERO
847847
KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
848-
ifdef CONFIG_CC_IS_CLANG
849-
# https://bugs.llvm.org/show_bug.cgi?id=45497
848+
ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
849+
# https://github.com/llvm/llvm-project/issues/44842
850850
KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
851851
endif
852852
endif

security/Kconfig.hardening

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ menu "Memory initialization"
2222
config CC_HAS_AUTO_VAR_INIT_PATTERN
2323
def_bool $(cc-option,-ftrivial-auto-var-init=pattern)
2424

25-
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.
25+
config CC_HAS_AUTO_VAR_INIT_ZERO_BARE
26+
def_bool $(cc-option,-ftrivial-auto-var-init=zero)
27+
28+
config CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
29+
# Clang 16 and later warn about using the -enable flag, but it
30+
# is required before then.
2931
def_bool $(cc-option,-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang)
32+
depends on !CC_HAS_AUTO_VAR_INIT_ZERO_BARE
33+
34+
config CC_HAS_AUTO_VAR_INIT_ZERO
35+
def_bool CC_HAS_AUTO_VAR_INIT_ZERO_BARE || CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
3036

3137
choice
3238
prompt "Initialize kernel stack variables at function entry"

0 commit comments

Comments
 (0)