From: Nathan Chancellor <nathan@kernel.org>
To: Kees Cook <kees@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>,
Jakub Jelinek <jakub@redhat.com>,
Nicolas Schier <nicolas@fjasle.eu>,
linux-kbuild@vger.kernel.org,
Stephen Hemminger <stephen@networkplumber.org>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] kbuild: Use -fzero-init-padding-bits=all
Date: Tue, 21 Jan 2025 14:51:22 -0700 [thread overview]
Message-ID: <20250121215122.GA1517789@ax162> (raw)
In-Reply-To: <20250121003646.work.168-kees@kernel.org>
On Mon, Jan 20, 2025 at 04:36:53PM -0800, Kees Cook wrote:
> 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
>
> Suggested-by: Jakub Jelinek <jakub@redhat.com>
> Link: https://lore.kernel.org/linux-toolchains/Z0hRrrNU3Q+ro2T7@tucnak/ [1]
> Signed-off-by: Kees Cook <kees@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
As far as I understand it, clang has decided to do this unconditionally:
https://github.com/llvm/llvm-project/commit/7a086e1b2dc05f54afae3591614feede727601fa
> ---
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nicolas Schier <nicolas@fjasle.eu>
> Cc: linux-kbuild@vger.kernel.org
> ---
> scripts/Makefile.extrawarn | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 1d13cecc7cc7..eb719f6d8d53 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -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
>
> --
> 2.34.1
>
prev parent reply other threads:[~2025-01-21 21:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 0:36 [PATCH] kbuild: Use -fzero-init-padding-bits=all Kees Cook
2025-01-21 21:51 ` Nathan Chancellor [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250121215122.GA1517789@ax162 \
--to=nathan@kernel.org \
--cc=jakub@redhat.com \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
--cc=nicolas@fjasle.eu \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.