Re: [PATCH] hpet: Replace one-element array with flexible-array member

From: Kees Cook
Date: Thu Nov 17 2022 - 23:23:17 EST


On Thu, Nov 17, 2022 at 09:54:04PM -0600, Gustavo A. R. Silva wrote:
> On Thu, Nov 17, 2022 at 07:42:55PM -0800, Kees Cook wrote:
> > One-element arrays are deprecated[1] and are being replaced with
> > flexible array members in support of the ongoing efforts to tighten the
> > FORTIFY_SOURCE routines on memcpy(), correctly instrument array indexing
> > with UBSAN_BOUNDS, and to globally enable -fstrict-flex-arrays=3.
> >
> > Replace one-element array with flexible-array member in struct hpet.
> >
> > This results in no differences in binary output. The use of struct hpet
> > is never used with sizeof() and accesses via hpet_timers array are
> > already done after explicit bounds checking.
> >
> > [1] https://github.com/KSPP/linux/issues/79
> >
> > Cc: Clemens Ladisch <clemens@xxxxxxxxxx>
> > Cc: "Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx>
> > Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
>
> Such a sneaky 1-element... ~.~

Yes! This one made my system unbootable after adding
-fstrict-flex-arrays=3. :) All better now.

> Reviewed-by: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx>

Thanks!

--
Kees Cook