kbuild: Use -fzero-init-padding-bits=all
PATCH 1/1 kbuild: Use -fzero-init-padding-bits=all
Enable -fzero-init-padding-bits=all when available (GCC 15+). This will correctly zero padding bits in structs and unions that might have been left uninitialized, and will make sure there is no regression in union initializations[1]. This fixes the following stackinit KUnit selftest cases that had been XFAIL until now because there was no compiler support:
ok 38 test_small_hole_static_all # SKIP XFAIL uninit bytes: 3 ok 39 test_big_hole_static_all # SKIP XFAIL uninit bytes: 124 ok 40 test_trailing_hole_static_all # SKIP XFAIL uninit bytes: 7 ok 42 test_small_hole_dynamic_all # SKIP XFAIL uninit bytes: 3 ok 43 test_big_hole_dynamic_all # SKIP XFAIL uninit bytes: 124 ok 44 test_trailing_hole_dynamic_all # SKIP XFAIL uninit bytes: 7 ok 58 test_small_hole_assigned_static_all # SKIP XFAIL uninit bytes: 3 ok 59 test_big_hole_assigned_static_all # SKIP XFAIL uninit bytes: 124 ok 60 test_trailing_hole_assigned_static_all # SKIP XFAIL uninit bytes: 7 ok 62 test_small_hole_assigned_dynamic_all # SKIP XFAIL uninit bytes: 3 ok 63 test_big_hole_assigned_dynamic_all # SKIP XFAIL uninit bytes: 124 ok 64 test_trailing_hole_assigned_dynamic_all # SKIP XFAIL uninit bytes: 7
All of the above now pass when built under GCC 15:
./tools/testing/kunit/kunit.py run stackinit --arch=x86_64 \
--make_option CC=gcc-15---
Cc: Masahiro Yamada <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: [email protected]
--- scripts/Makefile.extrawarn | 3 +++ 1 file changed, 3 insertions(+)
scripts/Makefile.extrawarn +3 -0
@@ -77,6 +77,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) # Warn if there is an enum types mismatch KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion) +# Explicitly clear padding bits during variable initialization +KBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all) + KBUILD_CFLAGS += -Wextra KBUILD_CFLAGS += -Wunused
Signature · 1 line
2.34.1
Quoted 20 lines · Kees Cook
Enable -fzero-init-padding-bits=all when available (GCC 15+). This will correctly zero padding bits in structs and unions that might have been left uninitialized, and will make sure there is no regression in union initializations[1]. This fixes the following stackinit KUnit selftest cases that had been XFAIL until now because there was no compiler support:
ok 38
test_small_hole_static_all# SKIP XFAIL uninit bytes: 3 ok 39test_big_hole_static_all# SKIP XFAIL uninit bytes: 124 ok 40test_trailing_hole_static_all# SKIP XFAIL uninit bytes: 7 ok 42test_small_hole_dynamic_all# SKIP XFAIL uninit bytes: 3 ok 43test_big_hole_dynamic_all# SKIP XFAIL uninit bytes: 124 ok 44test_trailing_hole_dynamic_all# SKIP XFAIL uninit bytes: 7 ok 58test_small_hole_assigned_static_all# SKIP XFAIL uninit bytes: 3 ok 59test_big_hole_assigned_static_all# SKIP XFAIL uninit bytes: 124 ok 60test_trailing_hole_assigned_static_all# SKIP XFAIL uninit bytes: 7 ok 62test_small_hole_assigned_dynamic_all# SKIP XFAIL uninit bytes: 3 ok 63test_big_hole_assigned_dynamic_all# SKIP XFAIL uninit bytes: 124 ok 64test_trailing_hole_assigned_dynamic_all# SKIP XFAIL uninit bytes: 7
Quoted 8 lines
All of the above now pass when built under GCC 15:
./tools/testing/kunit/kunit.py run stackinit --arch=x86_64 \ --make_option CC=gcc-15Suggested-by Jakub Jelinek <[email protected]>Signed-off-by Kees Cook <[email protected]>
As far as I understand it, clang has decided to do this unconditionally:
https://github.com/llvm/llvm-project/commit/7a086e1b2dc05f54afae3591614feede727601fa
Quoted 26 lines
---
Cc: Masahiro Yamada <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: [email protected]--- scripts/Makefile.extrawarn | 3 +++ 1 file changed, 3 insertions(+)scripts/Makefile.extrawarn +3
-0@@ -77,6 +77,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) # Warn if there is an enum types mismatch KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion) +# Explicitly clear padding bits during variable initialization +KBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all) + KBUILD_CFLAGS += -Wextra KBUILD_CFLAGS += -WunusedSignature · 1 line
2.34.1