Skip to contentSkip to conversation

wifi: nxpwifi: firmware response validation fixes

PATCH Superseded Tristan Madani 2 participants 4 messages Nov 20 – Nov 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover wifi: nxpwifi: firmware response validation fixes

The nxpwifi driver trusts several size fields from firmware responses without validating them against actual buffer lengths. This series adds bounds checks to prevent reads past the buffer when firmware provides inflated sizes.

Changes in v2:
- Dropped the HE capability TLV length patch (was 1/3), superseded by commit f17e2eda1630a ("wifi: nxpwifi: bound the TLV lengths in the 11AX_CFG response")
- Patch 2/2: moved the response size check after timer_delete_sync() so the command timer is properly cancelled before the early return, as pointed out by Jeff Chen

Tristan Madani (2):
wifi: nxpwifi: validate ext_scan buf_size against event buffer length
wifi: nxpwifi: validate command response size against buffer length

 drivers/net/wireless/nxp/nxpwifi/cmdevt.c | 14 ++++++++++++++
 drivers/net/wireless/nxp/nxpwifi/scan.c   |  9 +++++++++
 2 files changed, 23 insertions(+)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v2 1/2 wifi: nxpwifi: validate ext_scan buf_size against event buffer length

nxpwifi_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.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")
---
 drivers/net/wireless/nxp/nxpwifi/scan.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/wireless/nxp/nxpwifi/scan.c +9 -0
index 4eeba6700aa72..398c3f8ec0781 100644
@@ -2443,6 +2443,15 @@ int nxpwifi_handle_event_ext_scan_report(struct nxpwifi_private *priv,
 	u8 *scan_resp = buf + sizeof(struct nxpwifi_event_scan_result);
 	u16 scan_resp_size = le16_to_cpu(event_scan->buf_size);
 
+	if (sizeof(struct nxpwifi_event_scan_result) + scan_resp_size >
+	    adapter->event_skb->len) {
+		nxpwifi_dbg(adapter, ERROR,
+			    "EXT_SCAN: buf_size %u exceeds event length %u\n",
+			    scan_resp_size, adapter->event_skb->len);
+		ret = -EINVAL;
+		goto check_next_scan;
+	}
+
 	if (num_of_set > NXPWIFI_MAX_AP) {
 		nxpwifi_dbg(adapter, ERROR,
 			    "EXT_SCAN: Invalid number of AP returned (%d)!!\n",
Signature · 1 line
2.47.3
#2 lore raw

PATCH v2 2/2 wifi: nxpwifi: validate command response size against buffer length

In reply to Tristan Madani

nxpwifi_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 early in command response processing that validates the declared response size fits within the response skb.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")

---
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/nxp/nxpwifi/cmdevt.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/net/wireless/nxp/nxpwifi/cmdevt.c +14 -0
index fc1950a125b65..ebcfee8cb3872 100644
@@ -732,6 +732,20 @@ int nxpwifi_process_cmdresp(struct nxpwifi_adapter *adapter)
 	timer_delete_sync(&adapter->cmd_timer);
 	clear_bit(NXPWIFI_IS_CMD_TIMEDOUT, &adapter->work_flags);
 
+	if (le16_to_cpu(resp->size) > adapter->curr_cmd->resp_skb->len) {
+		nxpwifi_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 = -EINVAL;
+		nxpwifi_recycle_cmd_node(adapter, adapter->curr_cmd);
+		spin_lock_bh(&adapter->nxpwifi_cmd_lock);
+		adapter->curr_cmd = NULL;
+		spin_unlock_bh(&adapter->nxpwifi_cmd_lock);
+		return -EINVAL;
+	}
+
 	if (adapter->curr_cmd->cmd_flag & CMD_F_HOSTCMD) {
 		/* Copy original response back to response buffer */
 		struct nxpwifi_ds_misc_cmd *hostcmd;
Signature · 1 line
2.47.3
#3 lore raw
In reply to Tristan Madani

From: Jeff Chen <[email protected]>

Quoted 13 lines · Tristan Madani

The nxpwifi driver trusts several size fields from firmware responses without validating them against actual buffer lengths. This series adds bounds checks to prevent reads past the buffer when firmware provides inflated sizes.

Changes in v2:
- Dropped the HE capability TLV length patch (was 1/3), superseded by commit f17e2eda1630a ("wifi: nxpwifi: bound the TLV lengths in the 11AX_CFG response")
- Patch 2/2: moved the response size check after timer_delete_sync() so the command timer is properly cancelled before the early return, as pointed out by Jeff Chen

Quoted 8 lines

Tristan Madani (2):
wifi: nxpwifi: validate ext_scan buf_size against event buffer length
wifi: nxpwifi: validate command response size against buffer length

 drivers/net/wireless/nxp/nxpwifi/cmdevt.c | 14 ++++++++++++++
 drivers/net/wireless/nxp/nxpwifi/scan.c   |  9 +++++++++
 2 files changed, 23 insertions(+)

Hi Tristan,

Thanks for the v2. I will take it this time.

For future patches, please note:

- checkpatch warns that your From: ([email protected]) does not match your Signed-off-by ([email protected]). Please make them match.
- cc_maintainers: some maintainers were not Cc'd. Please use scripts/get_maintainer.pl to build the Cc list.

Thanks,
Jeff