wifi: mwifiex: validate firmware response sizes
Subsystems (2)
v2 cover wifi: mwifiex: validate firmware response sizes
From: Tristan Madani <[email protected]>
Two missing bounds checks on firmware-provided size fields in mwifiex:
1. ext_scan event: buf_size is used to determine scan response parsing length but never checked against the event buffer.
2. command response: resp->size is passed to individual handlers but never validated against the response skb length.
Both patches add early validation that the declared size fits within the actual buffer before proceeding with parsing.
Changes in v2:
- Patch 2/2: moved the response size check after timer_delete_sync() so the command timer is properly cancelled before the early return (Jeff Chen)
Tristan Madani (2):
wifi: mwifiex: validate ext_scan buf_size against event buffer length
wifi: mwifiex: validate command response size against buffer length
drivers/net/wireless/marvell/mwifiex/cmdevt.c | 14 ++++++++++++++ drivers/net/wireless/marvell/mwifiex/scan.c | 9 +++++++++ 2 files changed, 23 insertions(+)
Signature · 1 line
2.47.3
PATCH v2 1/2 wifi: mwifiex: validate ext_scan buf_size against event buffer length
From: Tristan Madani <[email protected]>
mwifiex_handle_event_ext_scan_report() uses the firmware-provided buf_size to determine how much scan response data to parse, but never checks it against the actual event buffer length. A firmware response with an inflated buf_size causes reads past the event buffer.
Add a check that the declared buf_size plus the event header does not exceed the event skb length before parsing scan results.
--- drivers/net/wireless/marvell/mwifiex/scan.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/wireless/marvell/mwifiex/scan.c +9 -0
@@ -2631,6 +2631,15 @@ int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,u8 *scan_resp = buf +sizeof (struct mwifiex_event_scan_result );u16 scan_resp_size =le16_to_cpu (event_scan->buf_size); +if (sizeof (struct mwifiex_event_scan_result ) + scan_resp_size > + adapter->event_skb->len) { +mwifiex_dbg (adapter,ERROR , +"EXT_SCAN: buf_size %u exceeds event length %u\n" , + scan_resp_size, adapter->event_skb->len); + ret =-1 ; + goto check_next_scan; + } +if (num_of_set >MWIFIEX_MAX_AP ) { mwifiex_dbg(adapter, ERROR, "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
Signature · 1 line
2.47.3
PATCH v2 2/2 wifi: mwifiex: validate command response size against buffer length
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
mwifiex_process_cmdresp() reads the firmware-provided resp->size field and passes it to individual command handlers that use it to determine how much data to process, but never validates it against the actual response buffer length. A firmware response with an inflated size field causes subsequent handlers to read past the buffer.
Add a check in command response processing that validates the declared response size fits within the response skb.
---
Changes in v2:
- Move the response size check after timer_delete_sync() so the command timer is properly cancelled before the early return (Jeff Chen)
drivers/net/wireless/marvell/mwifiex/cmdevt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/wireless/marvell/mwifiex/cmdevt.c +14 -0
@@ -831,6 +831,20 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)timer_delete_sync (&adapter->cmd_timer);clear_bit (MWIFIEX_IS_CMD_TIMEDOUT , &adapter->work_flags); +if (le16_to_cpu (resp->size) > adapter->curr_cmd->resp_skb->len) { +mwifiex_dbg (adapter,ERROR , +"CMD_RESP: resp size %u exceeds buffer %u\n" , +le16_to_cpu (resp->size), + adapter->curr_cmd->resp_skb->len); +if (adapter->curr_cmd->wait_q_enabled) + adapter->cmd_wait_q.status =-1 ; +mwifiex_recycle_cmd_node (adapter, adapter->curr_cmd); +spin_lock_bh (&adapter->mwifiex_cmd_lock); + adapter->curr_cmd =NULL ; +spin_unlock_bh (&adapter->mwifiex_cmd_lock); +return -1 ; + } +if (adapter->curr_cmd->cmd_flag &CMD_F_HOSTCMD ) {/* Copy original response back to response buffer */ struct mwifiex_ds_misc_cmd *hostcmd;
Signature · 1 line
2.47.3