* [PATCH][next] wifi: mwifiex: Replace one-element array with flexible-array member
@ 2023-02-03 1:34 Gustavo A. R. Silva
2023-02-03 17:57 ` Kees Cook
2023-02-13 16:53 ` Kalle Valo
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-02-03 1:34 UTC (permalink / raw)
To: Amitkumar Karwar, Ganapathi Bhat, Sharvari Harisangam, Xinming Hu,
Kalle Valo, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: linux-kernel, linux-wireless, netdev, 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 mwifiex_ie_types_rates_param_set.
These are the only binary differences I see after the change:
mwifiex.o
_@@ -50154,7 +50154,7 @@
23514: R_X86_64_32S kmalloc_caches+0x50
23518: call 2351d <mwifiex_scan_networks+0x11d>
23519: R_X86_64_PLT32 __tsan_read8-0x4
- 2351d: mov $0x225,%edx
+ 2351d: mov $0x224,%edx
23522: mov $0xdc0,%esi
23527: mov 0x0(%rip),%rdi # 2352e <mwifiex_scan_networks+0x12e>
2352a: R_X86_64_PC32 kmalloc_caches+0x4c
scan.o
_@@ -5582,7 +5582,7 @@
4394: R_X86_64_32S kmalloc_caches+0x50
4398: call 439d <mwifiex_scan_networks+0x11d>
4399: R_X86_64_PLT32 __tsan_read8-0x4
- 439d: mov $0x225,%edx
+ 439d: mov $0x224,%edx
43a2: mov $0xdc0,%esi
43a7: mov 0x0(%rip),%rdi # 43ae <mwifiex_scan_networks+0x12e>
43aa: R_X86_64_PC32 kmalloc_caches+0x4c
and the reason for that is the following line:
drivers/net/wireless/marvell/mwifiex/scan.c:
1517 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
1518 GFP_KERNEL);
sizeof(union mwifiex_scan_cmd_config_tlv) is now one-byte smaller due to the
flex-array transformation:
46 union mwifiex_scan_cmd_config_tlv {
47 /* Scan configuration (variable length) */
48 struct mwifiex_scan_cmd_config config;
49 /* Max allocated block */
50 u8 config_alloc_buf[MAX_SCAN_CFG_ALLOC];
51 };
Notice that MAX_SCAN_CFG_ALLOC is defined in terms of
sizeof(struct mwifiex_ie_types_rates_param_set), see:
26 /* Memory needed to store supported rate */
27 #define RATE_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_rates_param_set) \
28 + HOSTCMD_SUPPORTED_RATES)
37 /* Maximum memory needed for a mwifiex_scan_cmd_config with all TLVs at max */
38 #define MAX_SCAN_CFG_ALLOC (sizeof(struct mwifiex_scan_cmd_config) \
39 + sizeof(struct mwifiex_ie_types_num_probes) \
40 + sizeof(struct mwifiex_ie_types_htcap) \
41 + CHAN_TLV_MAX_SIZE \
42 + RATE_TLV_MAX_SIZE \
43 + WILDCARD_SSID_TLV_MAX_SIZE)
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/79
Link: https://github.com/KSPP/linux/issues/252
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/marvell/mwifiex/fw.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/wireless/marvell/mwifiex/fw.h b/drivers/net/wireless/marvell/mwifiex/fw.h
index 9616bd8b49f1..8c7c744683bc 100644
--- a/drivers/net/wireless/marvell/mwifiex/fw.h
+++ b/drivers/net/wireless/marvell/mwifiex/fw.h
@@ -794,7 +794,7 @@ struct mwifiex_ie_types_chan_band_list_param_set {
struct mwifiex_ie_types_rates_param_set {
struct mwifiex_ie_types_header header;
- u8 rates[1];
+ u8 rates[];
} __packed;
struct mwifiex_ie_types_ssid_param_set {
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] wifi: mwifiex: Replace one-element array with flexible-array member
2023-02-03 1:34 [PATCH][next] wifi: mwifiex: Replace one-element array with flexible-array member Gustavo A. R. Silva
@ 2023-02-03 17:57 ` Kees Cook
2023-02-13 16:53 ` Kalle Valo
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-02-03 17:57 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Amitkumar Karwar, Ganapathi Bhat, Sharvari Harisangam, Xinming Hu,
Kalle Valo, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, linux-wireless, netdev,
linux-hardening
On Thu, Feb 02, 2023 at 07:34:05PM -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 mwifiex_ie_types_rates_param_set.
>
> These are the only binary differences I see after the change:
>
> mwifiex.o
> _@@ -50154,7 +50154,7 @@
> 23514: R_X86_64_32S kmalloc_caches+0x50
> 23518: call 2351d <mwifiex_scan_networks+0x11d>
> 23519: R_X86_64_PLT32 __tsan_read8-0x4
> - 2351d: mov $0x225,%edx
> + 2351d: mov $0x224,%edx
> 23522: mov $0xdc0,%esi
> 23527: mov 0x0(%rip),%rdi # 2352e <mwifiex_scan_networks+0x12e>
> 2352a: R_X86_64_PC32 kmalloc_caches+0x4c
> scan.o
> _@@ -5582,7 +5582,7 @@
> 4394: R_X86_64_32S kmalloc_caches+0x50
> 4398: call 439d <mwifiex_scan_networks+0x11d>
> 4399: R_X86_64_PLT32 __tsan_read8-0x4
> - 439d: mov $0x225,%edx
> + 439d: mov $0x224,%edx
> 43a2: mov $0xdc0,%esi
> 43a7: mov 0x0(%rip),%rdi # 43ae <mwifiex_scan_networks+0x12e>
> 43aa: R_X86_64_PC32 kmalloc_caches+0x4c
>
> and the reason for that is the following line:
>
> drivers/net/wireless/marvell/mwifiex/scan.c:
> 1517 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
> 1518 GFP_KERNEL);
>
> sizeof(union mwifiex_scan_cmd_config_tlv) is now one-byte smaller due to the
> flex-array transformation:
>
> 46 union mwifiex_scan_cmd_config_tlv {
> 47 /* Scan configuration (variable length) */
> 48 struct mwifiex_scan_cmd_config config;
> 49 /* Max allocated block */
> 50 u8 config_alloc_buf[MAX_SCAN_CFG_ALLOC];
> 51 };
Interesting! So this looks like it's fixing a minor bug in the original
implementation which was allocation 1 byte too much.
>
> Notice that MAX_SCAN_CFG_ALLOC is defined in terms of
> sizeof(struct mwifiex_ie_types_rates_param_set), see:
>
> 26 /* Memory needed to store supported rate */
> 27 #define RATE_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_rates_param_set) \
> 28 + HOSTCMD_SUPPORTED_RATES)
>
> 37 /* Maximum memory needed for a mwifiex_scan_cmd_config with all TLVs at max */
> 38 #define MAX_SCAN_CFG_ALLOC (sizeof(struct mwifiex_scan_cmd_config) \
> 39 + sizeof(struct mwifiex_ie_types_num_probes) \
> 40 + sizeof(struct mwifiex_ie_types_htcap) \
> 41 + CHAN_TLV_MAX_SIZE \
> 42 + RATE_TLV_MAX_SIZE \
> 43 + WILDCARD_SSID_TLV_MAX_SIZE)
Yeah, the config_alloc_buf size appears to be very specifically
calculated, so this seems sane to me.
>
> 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/79
> Link: https://github.com/KSPP/linux/issues/252
> 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] 3+ messages in thread
* Re: [PATCH][next] wifi: mwifiex: Replace one-element array with flexible-array member
2023-02-03 1:34 [PATCH][next] wifi: mwifiex: Replace one-element array with flexible-array member Gustavo A. R. Silva
2023-02-03 17:57 ` Kees Cook
@ 2023-02-13 16:53 ` Kalle Valo
1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2023-02-13 16:53 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Amitkumar Karwar, Ganapathi Bhat, Sharvari Harisangam, Xinming Hu,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
linux-kernel, linux-wireless, netdev, 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 mwifiex_ie_types_rates_param_set.
>
> These are the only binary differences I see after the change:
>
> mwifiex.o
> _@@ -50154,7 +50154,7 @@
> 23514: R_X86_64_32S kmalloc_caches+0x50
> 23518: call 2351d <mwifiex_scan_networks+0x11d>
> 23519: R_X86_64_PLT32 __tsan_read8-0x4
> - 2351d: mov $0x225,%edx
> + 2351d: mov $0x224,%edx
> 23522: mov $0xdc0,%esi
> 23527: mov 0x0(%rip),%rdi # 2352e <mwifiex_scan_networks+0x12e>
> 2352a: R_X86_64_PC32 kmalloc_caches+0x4c
> scan.o
> _@@ -5582,7 +5582,7 @@
> 4394: R_X86_64_32S kmalloc_caches+0x50
> 4398: call 439d <mwifiex_scan_networks+0x11d>
> 4399: R_X86_64_PLT32 __tsan_read8-0x4
> - 439d: mov $0x225,%edx
> + 439d: mov $0x224,%edx
> 43a2: mov $0xdc0,%esi
> 43a7: mov 0x0(%rip),%rdi # 43ae <mwifiex_scan_networks+0x12e>
> 43aa: R_X86_64_PC32 kmalloc_caches+0x4c
>
> and the reason for that is the following line:
>
> drivers/net/wireless/marvell/mwifiex/scan.c:
> 1517 scan_cfg_out = kzalloc(sizeof(union mwifiex_scan_cmd_config_tlv),
> 1518 GFP_KERNEL);
>
> sizeof(union mwifiex_scan_cmd_config_tlv) is now one-byte smaller due to the
> flex-array transformation:
>
> 46 union mwifiex_scan_cmd_config_tlv {
> 47 /* Scan configuration (variable length) */
> 48 struct mwifiex_scan_cmd_config config;
> 49 /* Max allocated block */
> 50 u8 config_alloc_buf[MAX_SCAN_CFG_ALLOC];
> 51 };
>
> Notice that MAX_SCAN_CFG_ALLOC is defined in terms of
> sizeof(struct mwifiex_ie_types_rates_param_set), see:
>
> 26 /* Memory needed to store supported rate */
> 27 #define RATE_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_rates_param_set) \
> 28 + HOSTCMD_SUPPORTED_RATES)
>
> 37 /* Maximum memory needed for a mwifiex_scan_cmd_config with all TLVs at max */
> 38 #define MAX_SCAN_CFG_ALLOC (sizeof(struct mwifiex_scan_cmd_config) \
> 39 + sizeof(struct mwifiex_ie_types_num_probes) \
> 40 + sizeof(struct mwifiex_ie_types_htcap) \
> 41 + CHAN_TLV_MAX_SIZE \
> 42 + RATE_TLV_MAX_SIZE \
> 43 + WILDCARD_SSID_TLV_MAX_SIZE)
>
> 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/79
> Link: https://github.com/KSPP/linux/issues/252
> 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>
Patch applied to wireless-next.git, thanks.
235fd607c6cb wifi: mwifiex: Replace one-element array with flexible-array member
--
https://patchwork.kernel.org/project/linux-wireless/patch/Y9xkjXeElSEQ0FPY@work/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-13 16:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-03 1:34 [PATCH][next] wifi: mwifiex: Replace one-element array with flexible-array member Gustavo A. R. Silva
2023-02-03 17:57 ` Kees Cook
2023-02-13 16:53 ` Kalle Valo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).