public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hpet: Replace one-element array with flexible-array member
@ 2022-11-18  3:42 Kees Cook
  2022-11-18  3:54 ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2022-11-18  3:42 UTC (permalink / raw)
  To: Clemens Ladisch
  Cc: Kees Cook, Gustavo A. R. Silva, linux-kernel, linux-hardening

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@ladisch.de>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/linux/hpet.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/hpet.h b/include/linux/hpet.h
index 8604564b985d..21e69eaf7a36 100644
--- a/include/linux/hpet.h
+++ b/include/linux/hpet.h
@@ -30,7 +30,7 @@ struct hpet {
 			unsigned long _hpet_compare;
 		} _u1;
 		u64 hpet_fsb[2];	/* FSB route */
-	} hpet_timers[1];
+	} hpet_timers[];
 };
 
 #define	hpet_mc		_u0._hpet_mc
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hpet: Replace one-element array with flexible-array member
  2022-11-18  3:42 [PATCH] hpet: Replace one-element array with flexible-array member Kees Cook
@ 2022-11-18  3:54 ` Gustavo A. R. Silva
  2022-11-18  4:23   ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2022-11-18  3:54 UTC (permalink / raw)
  To: Kees Cook; +Cc: Clemens Ladisch, linux-kernel, linux-hardening

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@ladisch.de>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Signed-off-by: Kees Cook <keescook@chromium.org>

Such a sneaky 1-element... ~.~

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

Thanks!
--
Gustavo

> ---
>  include/linux/hpet.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/hpet.h b/include/linux/hpet.h
> index 8604564b985d..21e69eaf7a36 100644
> --- a/include/linux/hpet.h
> +++ b/include/linux/hpet.h
> @@ -30,7 +30,7 @@ struct hpet {
>  			unsigned long _hpet_compare;
>  		} _u1;
>  		u64 hpet_fsb[2];	/* FSB route */
> -	} hpet_timers[1];
> +	} hpet_timers[];
>  };
>  
>  #define	hpet_mc		_u0._hpet_mc
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hpet: Replace one-element array with flexible-array member
  2022-11-18  3:54 ` Gustavo A. R. Silva
@ 2022-11-18  4:23   ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2022-11-18  4:23 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: Clemens Ladisch, linux-kernel, linux-hardening

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@ladisch.de>
> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> 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@kernel.org>

Thanks!

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-18  4:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-18  3:42 [PATCH] hpet: Replace one-element array with flexible-array member Kees Cook
2022-11-18  3:54 ` Gustavo A. R. Silva
2022-11-18  4:23   ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox