* [PATCH 0/2][next] wifi: brcmfmac: common: Replace one-element array with flexible-array member
@ 2022-11-15 21:52 Gustavo A. R. Silva
2022-11-15 21:53 ` [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le Gustavo A. R. Silva
2022-11-15 21:55 ` [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to " Gustavo A. R. Silva
0 siblings, 2 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2022-11-15 21:52 UTC (permalink / raw)
To: Hante Meuleman, Franky Lin, Arend van Spriel, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: SHA-cyfmac-dev-list, brcm80211-dev-list.pdl, netdev,
linux-wireless, linux-kernel, Gustavo A. R. Silva,
linux-hardening
Hi!
This series aims to replace a one-element array with flexible-array
member in drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
(in struct brcmf_dload_data_le) and use the struct_size() helper.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -fstrict-flex-arrays=3 [1].
Link: https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/230
Link: https://github.com/KSPP/linux/issues/79
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Gustavo A. R. Silva (2):
wifi: brcmfmac: replace one-element array with flexible-array member
in struct brcmf_dload_data_le
wifi: brcmfmac: Use struct_size() in code ralated to struct
brcmf_dload_data_le
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c | 7 ++++---
.../net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le
2022-11-15 21:52 [PATCH 0/2][next] wifi: brcmfmac: common: Replace one-element array with flexible-array member Gustavo A. R. Silva
@ 2022-11-15 21:53 ` Gustavo A. R. Silva
2022-11-16 22:23 ` Kees Cook
2022-11-22 10:14 ` Kalle Valo
2022-11-15 21:55 ` [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to " Gustavo A. R. Silva
1 sibling, 2 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2022-11-15 21:53 UTC (permalink / raw)
To: Hante Meuleman, Franky Lin, Arend van Spriel, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: SHA-cyfmac-dev-list, brcm80211-dev-list.pdl, netdev,
linux-wireless, linux-kernel, Gustavo A. R. Silva,
linux-hardening
One-element arrays are deprecated, and we are replacing them with flexible
array members instead. So, replace one-element array with flexible-array
member in struct brcmf_dload_data_le.
Important to mention is that doing a build before/after this patch results
in no binary output differences.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines
on memcpy() and help us make progress towards globally enabling
-fstrict-flex-arrays=3 [1].
Link: https://github.com/KSPP/linux/issues/230
Link: https://github.com/KSPP/linux/issues/79
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c | 4 ++--
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
index 22344e68fd59..2e836566e218 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
@@ -110,7 +110,7 @@ static int brcmf_c_download(struct brcmf_if *ifp, u16 flag,
dload_buf->dload_type = cpu_to_le16(DL_TYPE_CLM);
dload_buf->len = cpu_to_le32(len);
dload_buf->crc = cpu_to_le32(0);
- len = sizeof(*dload_buf) + len - 1;
+ len = sizeof(*dload_buf) + len;
err = brcmf_fil_iovar_data_set(ifp, "clmload", dload_buf, len);
@@ -139,7 +139,7 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp)
return 0;
}
- chunk_buf = kzalloc(sizeof(*chunk_buf) + MAX_CHUNK_LEN - 1, GFP_KERNEL);
+ chunk_buf = kzalloc(sizeof(*chunk_buf) + MAX_CHUNK_LEN, GFP_KERNEL);
if (!chunk_buf) {
err = -ENOMEM;
goto done;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
index f518e025d6e4..a69339f72c66 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h
@@ -943,7 +943,7 @@ struct brcmf_dload_data_le {
__le16 dload_type;
__le32 len;
__le32 crc;
- u8 data[1];
+ u8 data[];
};
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
2022-11-15 21:52 [PATCH 0/2][next] wifi: brcmfmac: common: Replace one-element array with flexible-array member Gustavo A. R. Silva
2022-11-15 21:53 ` [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le Gustavo A. R. Silva
@ 2022-11-15 21:55 ` Gustavo A. R. Silva
2022-11-16 22:23 ` Kees Cook
1 sibling, 1 reply; 7+ messages in thread
From: Gustavo A. R. Silva @ 2022-11-15 21:55 UTC (permalink / raw)
To: Hante Meuleman, Franky Lin, Arend van Spriel, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: SHA-cyfmac-dev-list, brcm80211-dev-list.pdl, netdev,
linux-wireless, linux-kernel, Gustavo A. R. Silva,
linux-hardening
Prefer struct_size() over open-coded versions of idiom:
sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
where count is the max number of items the flexible array is supposed to
contain.
In this particular case, in the open-coded version sizeof(typeof-flex-array-elements)
is implicit in _count_ because the type of the flex array data is u8:
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h:941:
941 struct brcmf_dload_data_le {
942 __le16 flag;
943 __le16 dload_type;
944 __le32 len;
945 __le32 crc;
946 u8 data[];
947 };
Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
index 2e836566e218..4a309e5a5707 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
@@ -110,9 +110,9 @@ static int brcmf_c_download(struct brcmf_if *ifp, u16 flag,
dload_buf->dload_type = cpu_to_le16(DL_TYPE_CLM);
dload_buf->len = cpu_to_le32(len);
dload_buf->crc = cpu_to_le32(0);
- len = sizeof(*dload_buf) + len;
- err = brcmf_fil_iovar_data_set(ifp, "clmload", dload_buf, len);
+ err = brcmf_fil_iovar_data_set(ifp, "clmload", dload_buf,
+ struct_size(dload_buf, data, len));
return err;
}
@@ -139,7 +139,8 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp)
return 0;
}
- chunk_buf = kzalloc(sizeof(*chunk_buf) + MAX_CHUNK_LEN, GFP_KERNEL);
+ chunk_buf = kzalloc(struct_size(chunk_buf, data, MAX_CHUNK_LEN),
+ GFP_KERNEL);
if (!chunk_buf) {
err = -ENOMEM;
goto done;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le
2022-11-15 21:53 ` [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le Gustavo A. R. Silva
@ 2022-11-16 22:23 ` Kees Cook
2022-11-22 10:14 ` Kalle Valo
1 sibling, 0 replies; 7+ messages in thread
From: Kees Cook @ 2022-11-16 22:23 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Hante Meuleman, Franky Lin, Arend van Spriel, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
SHA-cyfmac-dev-list, brcm80211-dev-list.pdl, netdev,
linux-wireless, linux-kernel, linux-hardening
On Tue, Nov 15, 2022 at 03:53:27PM -0600, Gustavo A. R. Silva wrote:
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element array with flexible-array
> member in struct brcmf_dload_data_le.
>
> Important to mention is that doing a build before/after this patch results
> in no binary output differences.
>
> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines
> on memcpy() and help us make progress towards globally enabling
> -fstrict-flex-arrays=3 [1].
>
> Link: https://github.com/KSPP/linux/issues/230
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
2022-11-15 21:55 ` [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to " Gustavo A. R. Silva
@ 2022-11-16 22:23 ` Kees Cook
2022-11-17 1:06 ` Gustavo A. R. Silva
0 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2022-11-16 22:23 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Hante Meuleman, Franky Lin, Arend van Spriel, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
SHA-cyfmac-dev-list, brcm80211-dev-list.pdl, netdev,
linux-wireless, linux-kernel, linux-hardening
On Tue, Nov 15, 2022 at 03:55:34PM -0600, Gustavo A. R. Silva wrote:
> Prefer struct_size() over open-coded versions of idiom:
>
> sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
>
> where count is the max number of items the flexible array is supposed to
> contain.
>
> In this particular case, in the open-coded version sizeof(typeof-flex-array-elements)
> is implicit in _count_ because the type of the flex array data is u8:
>
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h:941:
> 941 struct brcmf_dload_data_le {
> 942 __le16 flag;
> 943 __le16 dload_type;
> 944 __le32 len;
> 945 __le32 crc;
> 946 u8 data[];
> 947 };
>
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
2022-11-16 22:23 ` Kees Cook
@ 2022-11-17 1:06 ` Gustavo A. R. Silva
0 siblings, 0 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2022-11-17 1:06 UTC (permalink / raw)
To: Kees Cook, Gustavo A. R. Silva
Cc: Hante Meuleman, Franky Lin, Arend van Spriel, Kalle Valo,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
SHA-cyfmac-dev-list, brcm80211-dev-list.pdl, netdev,
linux-wireless, linux-kernel, linux-hardening
On 11/16/22 16:23, Kees Cook wrote:
> On Tue, Nov 15, 2022 at 03:55:34PM -0600, Gustavo A. R. Silva wrote:
>> Prefer struct_size() over open-coded versions of idiom:
>>
>> sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
>>
>> where count is the max number of items the flexible array is supposed to
>> contain.
>>
>> In this particular case, in the open-coded version sizeof(typeof-flex-array-elements)
>> is implicit in _count_ because the type of the flex array data is u8:
>>
>> drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h:941:
>> 941 struct brcmf_dload_data_le {
>> 942 __le16 flag;
>> 943 __le16 dload_type;
>> 944 __le32 len;
>> 945 __le32 crc;
>> 946 u8 data[];
>> 947 };
>>
>> Link: https://github.com/KSPP/linux/issues/160
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
>
Thanks for the reviews! :)
--
Gustavo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le
2022-11-15 21:53 ` [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le Gustavo A. R. Silva
2022-11-16 22:23 ` Kees Cook
@ 2022-11-22 10:14 ` Kalle Valo
1 sibling, 0 replies; 7+ messages in thread
From: Kalle Valo @ 2022-11-22 10:14 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Hante Meuleman, Franky Lin, Arend van Spriel, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, SHA-cyfmac-dev-list,
brcm80211-dev-list.pdl, netdev, linux-wireless, linux-kernel,
Gustavo A. R. Silva, linux-hardening
"Gustavo A. R. Silva" <gustavoars@kernel.org> wrote:
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element array with flexible-array
> member in struct brcmf_dload_data_le.
>
> Important to mention is that doing a build before/after this patch results
> in no binary output differences.
>
> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines
> on memcpy() and help us make progress towards globally enabling
> -fstrict-flex-arrays=3 [1].
>
> Link: https://github.com/KSPP/linux/issues/230
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Reviewed-by: Kees Cook <keescook@chromium.org>
2 patches applied to wireless-next.git, thanks.
0001650b3d89 wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le
633a9b6f514c wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
--
https://patchwork.kernel.org/project/linux-wireless/patch/905f5b68cf93c812360d081caae5b15221db09b6.1668548907.git.gustavoars@kernel.org/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-11-22 10:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 21:52 [PATCH 0/2][next] wifi: brcmfmac: common: Replace one-element array with flexible-array member Gustavo A. R. Silva
2022-11-15 21:53 ` [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le Gustavo A. R. Silva
2022-11-16 22:23 ` Kees Cook
2022-11-22 10:14 ` Kalle Valo
2022-11-15 21:55 ` [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to " Gustavo A. R. Silva
2022-11-16 22:23 ` Kees Cook
2022-11-17 1:06 ` Gustavo A. R. Silva
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.