wifi: mwifiex: fix OOB reads and writes from firmware response fields
v2 cover wifi: mwifiex: fix OOB reads and writes from firmware response fields
From: Tristan Madani <[email protected]>
Hi Brian,
Note: this is a v2 resubmission. The original was sent via Gmail which caused HTML rendering issues. This version uses git send-email for proper plain-text formatting.
Six issues in mwifiex where firmware-controlled fields are used as array indices or loop bounds without validation. Two are OOB writes, four are OOB reads:
Proposed fixes in the following patches.
Thanks,
Tristan
PATCH v2 1/6 wifi: mwifiex: fix OOB write from firmware queue_index in WMM status response
From: Tristan Madani <[email protected]>
The firmware-controlled queue_index (u8) from the WMM queue status TLV is used to index the 4-entry ac_status[] array without validation. An out-of-range value causes out-of-bounds writes of three firmware- controlled bytes into adjacent struct fields.
Add a bounds check before using queue_index as an array index.
---drivers/net/wireless/marvell/mwifiex/wmm.c | 5 +++++
1 file changed, 5 insertions(+)
drivers/net/wireless/marvell/mwifiex/wmm.c +5 -0
@@ -945,6 +945,11 @@ int mwifiex_ret_wmm_get_status(struct mwifiex_private *priv, tlv_wmm_qstatus->disabled); +if (tlv_wmm_qstatus->queue_index >= +IEEE80211_NUM_ACS ) { +break ; + } + ac_status = &priv->wmm.ac_status[tlv_wmm_qstatus-> queue_index]; ac_status->disabled = tlv_wmm_qstatus->disabled;
PATCH v2 2/6 wifi: mwifiex: fix OOB write from firmware TID in ADDBA response handler
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The TID value extracted from the Block Ack parameter set is a 4-bit field (0-15), but aggr_prio_tbl[] has only 8 entries. A TID >= 8 causes an out-of-bounds write to adjacent struct mwifiex_private fields.
Add a bounds check after extracting the TID.
---drivers/net/wireless/marvell/mwifiex/11n.c | 5 +++++
1 file changed, 5 insertions(+)
drivers/net/wireless/marvell/mwifiex/11n.c +5 -0
@@ -155,6 +155,11 @@ int mwifiex_ret_11n_addba_req(struct mwifiex_private *priv, tid = (block_ack_param_set &IEEE80211_ADDBA_PARAM_TID_MASK ) >>BLOCKACKPARAM_TID_POS ; +if (tid >=MAX_NUM_TID ) { +mwifiex_dbg (priv->adapter,ERROR , +"ADDBA RSP: invalid tid %d\n" , tid); +return -EINVAL ; + } tid_down =mwifiex_wmm_downgrade_tid (priv, tid); ra_list =mwifiex_wmm_get_ralist_node (priv, tid_down, add_ba_rsp-> peer_mac_addr);
PATCH v2 3/6 wifi: mwifiex: fix OOB read from firmware sta_count in station list response
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The firmware-controlled sta_count (u16) is used as an unbounded loop counter for iterating station info entries. An inflated count drives reads past the response buffer into kernel heap memory.
Add a check that sta_count fits within the response size.
---drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c | 8 ++++++++
1 file changed, 8 insertions(+)
drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c +9 -1
@@ -976,7 +976,15 @@ static int mwifiex_ret_uap_sta_list(struct mwifiex_private *priv,struct mwifiex_ie_types_sta_info *sta_info = (void *)&sta_list->tlv;int i;struct mwifiex_sta_node *sta_node; +u16 resp_size =le16_to_cpu (resp->size); +u16 count =le16_to_cpu (sta_list->sta_count); +u16 max_count; +if (resp_size <sizeof (*resp) -sizeof (resp->params) +sizeof (*sta_list)) +return -EINVAL ; + max_count = (resp_size -sizeof (*resp) +sizeof (resp->params) - +sizeof (*sta_list)) /sizeof (*sta_info); + count =min (count, max_count); -for (i =0 ; i < (le16_to_cpu (sta_list->sta_count)); i++) { +for (i =0 ; i < count; i++) { sta_node =mwifiex_get_sta_entry (priv, sta_info->mac);if (unlikely (!sta_node))
continue;
PATCH v2 4/6 wifi: mwifiex: fix OOB read in scan response from mismatched TLV data sizes
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The TSF and ChanBand TLV arrays are indexed by the firmware-controlled number_of_sets without cross-checking against the TLV header length fields. When number_of_sets exceeds the TLV data, the loop reads past the TLV data into adjacent command response memory.
Stop using the TLV data once the index exceeds its reported length.
---drivers/net/wireless/marvell/mwifiex/scan.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +5 -2
@@ -2188,10 +2188,12 @@ static int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,* received. */ if (tsf_tlv) -memcpy (&fw_tsf, &tsf_tlv->tsf_data[idx *TSF_DATA_SIZE ], +if ((idx +1 ) *TSF_DATA_SIZE <= +le16_to_cpu (tsf_tlv->header.len)) +memcpy (&fw_tsf, &tsf_tlv->tsf_data[idx *TSF_DATA_SIZE ],sizeof (fw_tsf)); -if (chan_band_tlv) { +if (chan_band_tlv && (idx +1 ) *sizeof (*chan_band) <= +le16_to_cpu (chan_band_tlv->header.len)) { chan_band = &chan_band_tlv->chan_band_param[idx]; radio_type = &chan_band->radio_type;
} else {
PATCH v2 5/6 wifi: mwifiex: fix OOB read from firmware intf_num in multichannel event
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The firmware-controlled intf_num is used to iterate the flexible array bss_type_numlist[] without checking it against the TLV data length. An inflated value causes out-of-bounds reads past the TLV data.
Clamp intf_num to the available TLV data.
---drivers/net/wireless/marvell/mwifiex/sta_event.c | 8 ++++++++
1 file changed, 8 insertions(+)
drivers/net/wireless/marvell/mwifiex/sta_event.c +8 -0
@@ -450,7 +450,15 @@ void mwifiex_process_multi_chan_event(struct mwifiex_private *priv, grp_info = (struct mwifiex_ie_types_mc_group_info *)tlv; intf_num = grp_info->intf_num; + { +u16 fixed_len =sizeof (*grp_info) - +sizeof (grp_info->header); +if (tlv_len < fixed_len || + intf_num > tlv_len - fixed_len) + intf_num =0 ; + } +for (i =0 ; i < intf_num; i++) { bss_type = grp_info->bss_type_numlist[i] >>4 ;
PATCH v2 6/6 wifi: mwifiex: fix OOB read from inflated TLV length in IBSS peer event
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The IBSS connected handler replaces the buffer-bounded evt_len with the firmware-controlled TLV header length. An inflated value drives the IE parsing loop past the event buffer into adjacent kernel heap memory.
Cap the TLV-derived length at the remaining event data size.
---drivers/net/wireless/marvell/mwifiex/sta_event.c | 4 ++++
1 file changed, 4 insertions(+)
drivers/net/wireless/marvell/mwifiex/sta_event.c +4 -0
@@ -46,6 +46,10 @@ static int mwifiex_check_ibss_peer_capabilties(struct mwifiex_private *priv, evt_len =le16_to_cpu (tlv_mgmt_frame->header.len); curr += (sizeof (*tlv_mgmt_frame) +12 ); +if (evt_len > event->len - + (curr - event->data)) + evt_len = event->len - + (curr - event->data); }else { mwifiex_dbg(priv->adapter, MSG,
Brian Norris
maintainerQuoted 7 lines · Tristan Madani
From: Tristan Madani <[email protected]>
Hi Brian,
Note: this is a v2 resubmission. The original was sent via Gmail which caused HTML rendering issues. This version uses git send-email for proper plain-text formatting.
You also sent it privately / directly to me, and I don't think you even sent the whole thing. You've fixed some of that now, thanks.
Quoted 5 lines
Six issues in mwifiex where firmware-controlled fields are used as array indices or loop bounds without validation. Two are OOB writes, four are OOB reads:
Proposed fixes in the following patches.
Several of these don't actually apply to wireless/for-next correctly, so I can't actually review them. On at least one, I think you seem to have stripped a line or two somehow.
Please confirm you can apply your series togit://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git
for-next with 'git am', and then resend.
Brian