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

From: Tristan Madani

Date: Fri Nov 20 2026 - 18:00:09 EST


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")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
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(+)

diff --git a/drivers/net/wireless/nxp/nxpwifi/cmdevt.c b/drivers/net/wireless/nxp/nxpwifi/cmdevt.c
index fc1950a125b65..ebcfee8cb3872 100644
--- a/drivers/net/wireless/nxp/nxpwifi/cmdevt.c
+++ b/drivers/net/wireless/nxp/nxpwifi/cmdevt.c
@@ -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;
--
2.47.3