Hi Kees, On Mon, 27 Jan 2025 at 20:11, Kees Cook <kees@xxxxxxxxxx> 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@xxxxxxxxxx> 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@xxxxxxxxxxxxxx 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