[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdWvcKOc6v5o3-9-SqP_4oh5-GZQjZZb=-krhY=mVRED_Q@mail.gmail.com>
Date: Tue, 28 Jan 2025 08:46:39 +0100
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Kees Cook <kees@...nel.org>
Cc: Masahiro Yamada <masahiroy@...nel.org>, Andrew Morton <akpm@...ux-foundation.org>,
Jakub Jelinek <jakub@...hat.com>, Nathan Chancellor <nathan@...nel.org>, Nicolas Schier <nicolas@...sle.eu>,
Nick Desaulniers <ndesaulniers@...gle.com>, Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>, linux-kernel@...r.kernel.org,
linux-kbuild@...r.kernel.org, llvm@...ts.linux.dev,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH v2 2/3] stackinit: Add union initialization to selftests
Hi Kees,
On Mon, 27 Jan 2025 at 20:11, Kees Cook <kees@...nel.org> wrote:
> The stack initialization selftests were checking scalars, strings,
> and structs, but not unions. Add union tests (which are mostly identical
> setup to structs). This catches the recent union initialization behavioral
> changes seen in GCC 15. Before GCC 15, this new test passes:
>
> ok 18 test_small_start_old_zero
>
> With GCC 15, it fails:
>
> not ok 18 test_small_start_old_zero
>
> Specifically, a union with a larger member where a smaller member is
> initialized with the older "= { 0 }" syntax:
>
> union test_small_start {
> char one:1;
> char two;
> short three;
> unsigned long four;
> struct big_struct {
> unsigned long array[8];
> } big;
> };
>
> This is a regression in compiler behavior that Linux has depended on.
> GCC does not seem likely to fix it, instead suggesting that affected
> projects start using -fzero-init-padding-bits=unions:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118403
>
> Signed-off-by: Kees Cook <kees@...nel.org>
Thanks for your patch!
> --- a/lib/stackinit_kunit.c
> +++ b/lib/stackinit_kunit.c
> @@ -295,6 +330,33 @@ struct test_user {
> unsigned long four;
> };
>
> +/* No padding: all members are the same size. */
> +union test_same_sizes {
> + unsigned long one;
> + unsigned long two;
> + unsigned long three;
> + unsigned long four;
> +};
> +
> +/* Mismatched sizes, with one and two being small */
> +union test_small_start {
> + char one:1;
> + char two;
> + short three;
> + unsigned long four;
> + struct big_struct {
> + unsigned long array[8];
> + } big;
> +};
> +
> +/* Mismatched sizes, with one and two being small */
three and four
> +union test_small_end {
> + short one;
> + unsigned long two;
> + char three:1;
> + char four;
> +};
> +
> #define ALWAYS_PASS WANT_SUCCESS
> #define ALWAYS_FAIL XFAIL
>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Powered by blists - more mailing lists