2022-11-19 00:42:12

by Kees Cook

[permalink] [raw]
Subject: [PATCH v2] p54: Replace zero-length array of trailing structs with flex-array

Zero-length 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 zero-length array with flexible-array member.

This results in no differences in binary output (most especially because
struct pda_antenna_gain is unused). The struct is kept for future
reference.

[1] https://github.com/KSPP/linux/issues/78

Cc: Christian Lamparter <[email protected]>
Cc: Kalle Valo <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
---
v2:
- convert normally (chunkeey)
v1: https://lore.kernel.org/lkml/[email protected]/
---
drivers/net/wireless/intersil/p54/eeprom.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/intersil/p54/eeprom.h b/drivers/net/wireless/intersil/p54/eeprom.h
index 1d0aaf54389a..641c4e79879e 100644
--- a/drivers/net/wireless/intersil/p54/eeprom.h
+++ b/drivers/net/wireless/intersil/p54/eeprom.h
@@ -108,10 +108,10 @@ struct pda_country {
} __packed;

struct pda_antenna_gain {
- struct {
+ DECLARE_FLEX_ARRAY(struct {
u8 gain_5GHz; /* 0.25 dBi units */
u8 gain_2GHz; /* 0.25 dBi units */
- } __packed antenna[0];
+ } __packed, antenna);
} __packed;

struct pda_custom_wrapper {
--
2.34.1



2022-11-19 01:54:50

by Christian Lamparter

[permalink] [raw]
Subject: Re: [PATCH v2] p54: Replace zero-length array of trailing structs with flex-array

On 11/19/22 00:42, Kees Cook wrote:
> Zero-length 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 zero-length array with flexible-array member.
>
> This results in no differences in binary output (most especially because
> struct pda_antenna_gain is unused). The struct is kept for future
> reference.
>
> [1] https://github.com/KSPP/linux/issues/78
>

Thank you!

> Cc: Christian Lamparter <[email protected]>
> Cc: Kalle Valo <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: Eric Dumazet <[email protected]>
> Cc: Jakub Kicinski <[email protected]>
> Cc: Paolo Abeni <[email protected]>
> Cc: "Gustavo A. R. Silva" <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>
Acked-by: Christian Lamparter <[email protected]>
> ---
> v2:
> - convert normally (chunkeey)
> v1: https://lore.kernel.org/lkml/[email protected]/
> ---
> drivers/net/wireless/intersil/p54/eeprom.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/intersil/p54/eeprom.h b/drivers/net/wireless/intersil/p54/eeprom.h
> index 1d0aaf54389a..641c4e79879e 100644
> --- a/drivers/net/wireless/intersil/p54/eeprom.h
> +++ b/drivers/net/wireless/intersil/p54/eeprom.h
> @@ -108,10 +108,10 @@ struct pda_country {
> } __packed;
>
> struct pda_antenna_gain {
> - struct {
> + DECLARE_FLEX_ARRAY(struct {
> u8 gain_5GHz; /* 0.25 dBi units */
> u8 gain_2GHz; /* 0.25 dBi units */
> - } __packed antenna[0];
> + } __packed, antenna);
> } __packed;
>
> struct pda_custom_wrapper {


2022-11-19 06:41:30

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v2] p54: Replace zero-length array of trailing structs with flex-array

Kees Cook <[email protected]> writes:

> Zero-length 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 zero-length array with flexible-array member.
>
> This results in no differences in binary output (most especially because
> struct pda_antenna_gain is unused). The struct is kept for future
> reference.
>
> [1] https://github.com/KSPP/linux/issues/78
>
> Cc: Christian Lamparter <[email protected]>
> Cc: Kalle Valo <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: Eric Dumazet <[email protected]>
> Cc: Jakub Kicinski <[email protected]>
> Cc: Paolo Abeni <[email protected]>
> Cc: "Gustavo A. R. Silva" <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>

I'll add "wifi:".

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

2022-11-22 10:20:12

by Kalle Valo

[permalink] [raw]
Subject: Re: [v2] wifi: p54: Replace zero-length array of trailing structs with flex-array

Kees Cook <[email protected]> wrote:

> Zero-length 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 zero-length array with flexible-array member.
>
> This results in no differences in binary output (most especially because
> struct pda_antenna_gain is unused). The struct is kept for future
> reference.
>
> [1] https://github.com/KSPP/linux/issues/78
>
> Cc: Christian Lamparter <[email protected]>
> Cc: Kalle Valo <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: Eric Dumazet <[email protected]>
> Cc: Jakub Kicinski <[email protected]>
> Cc: Paolo Abeni <[email protected]>
> Cc: "Gustavo A. R. Silva" <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>
> Acked-by: Christian Lamparter <[email protected]>

Patch applied to wireless-next.git, thanks.

3b79d4bad3a0 wifi: p54: Replace zero-length array of trailing structs with flex-array

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches