wifi: mwifiex: Refactor 1-element array into flexible array in struct mwifiex_ie_types_chan_list_param_set
PATCH 1/1 wifi: mwifiex: Refactor 1-element array into flexible array in struct mwifiex_ie_types_chan_list_param_set
struct mwifiex_ie_types_chan_list_param_set::chan_scan_param is treated as a flexible array, so convert it into one so that it doesn't trip the array bounds sanitizer[1]. The code was already calculating sizes by not including the trailing single element, so no sizeof() change are needed.
--- drivers/net/wireless/marvell/mwifiex/scan.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +6 -8
@@ -664,15 +664,14 @@ mwifiex_scan_channel_list(struct mwifiex_private *priv,/* Copy the current channel TLV to the command being prepared */ -memcpy (chan_tlv_out->chan_scan_param + tlv_idx, +memcpy (&chan_tlv_out->chan_scan_param[tlv_idx], tmp_chan_list, -sizeof (chan_tlv_out->chan_scan_param)); +sizeof (*chan_tlv_out->chan_scan_param));/* Increment the TLV header length by the size appended */ le16_unaligned_add_cpu (&chan_tlv_out->header.len, -sizeof ( - chan_tlv_out->chan_scan_param)); +sizeof (*chan_tlv_out->chan_scan_param));/* * The tlv buffer length is set to the number of bytes
@@ -2369,12 +2368,11 @@ int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv, chan_idx <MWIFIEX_BG_SCAN_CHAN_MAX && bgscan_cfg_in->chan_list[chan_idx].chan_number; chan_idx++) { - temp_chan = chan_list_tlv->chan_scan_param + chan_idx; + temp_chan = &chan_list_tlv->chan_scan_param[chan_idx];/* Increment the TLV header length by size appended */ le16_unaligned_add_cpu (&chan_list_tlv->header.len, -sizeof ( - chan_list_tlv->chan_scan_param)); +sizeof (*chan_list_tlv->chan_scan_param)); temp_chan->chan_number = bgscan_cfg_in->chan_list[chan_idx].chan_number;
@@ -2413,7 +2411,7 @@ int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv, chan_scan_param);le16_unaligned_add_cpu (&chan_list_tlv->header.len, chan_num * -sizeof (chan_list_tlv->chan_scan_param[0 ])); +sizeof (*chan_list_tlv->chan_scan_param)); } tlv_pos += (sizeof(chan_list_tlv->header)
Signature · 1 line
2.34.1
Apologies -- this patch is incomplete. My "git add" failed me. ;) I'll send a v2!
-Kees
Quoted 71 lines · Kees Cook
struct
mwifiex_ie_types_chan_list_param_set::chan_scan_paramis treated as a flexible array, so convert it into one so that it doesn't trip the array bounds sanitizer[1]. The code was already calculating sizes by not including the trailing single element, so nosizeof()change are needed.Cc Brian Norris <[email protected]>Cc Kalle Valo <[email protected]>Cc Dmitry Antipov <[email protected]>Cc Johannes Berg <[email protected]>Cc zuoqilin <[email protected]>Cc Ruan Jinjie <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Christophe JAILLET <[email protected]>Cc Gustavo A. R. Silva <[email protected]>Signed-off-by Kees Cook <[email protected]>--- drivers/net/wireless/marvell/mwifiex/scan.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/net/wireless/marvell/mwifiex/scan.c +6
-8@@ -664,15 +664,14 @@ mwifiex_scan_channel_list(struct mwifiex_private *priv,/* Copy the current channel TLV to the command being prepared */ -memcpy (chan_tlv_out->chan_scan_param + tlv_idx, +memcpy (&chan_tlv_out->chan_scan_param[tlv_idx], tmp_chan_list, -sizeof (chan_tlv_out->chan_scan_param)); +sizeof (*chan_tlv_out->chan_scan_param));/* Increment the TLV header length by the size appended */ le16_unaligned_add_cpu (&chan_tlv_out->header.len, -sizeof ( - chan_tlv_out->chan_scan_param)); +sizeof (*chan_tlv_out->chan_scan_param));/* * The tlv buffer length is set to the number of bytes @@ -2369,12 +2368,11 @@ int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv, chan_idx <MWIFIEX_BG_SCAN_CHAN_MAX && bgscan_cfg_in->chan_list[chan_idx].chan_number; chan_idx++) { - temp_chan = chan_list_tlv->chan_scan_param + chan_idx; + temp_chan = &chan_list_tlv->chan_scan_param[chan_idx];/* Increment the TLV header length by size appended */ le16_unaligned_add_cpu (&chan_list_tlv->header.len, -sizeof ( - chan_list_tlv->chan_scan_param)); +sizeof (*chan_list_tlv->chan_scan_param)); temp_chan->chan_number = bgscan_cfg_in->chan_list[chan_idx].chan_number;@@ -2413,7 +2411,7 @@ int mwifiex_cmd_802_11_bg_scan_config(struct mwifiex_private *priv, chan_scan_param);le16_unaligned_add_cpu (&chan_list_tlv->header.len, chan_num * -sizeof (chan_list_tlv->chan_scan_param[0 ])); +sizeof (*chan_list_tlv->chan_scan_param)); } tlv_pos += (sizeof(chan_list_tlv->header)Signature · 1 line
2.34.1
Signature · 1 line
Kees Cook