wifi: iwlwifi: validate more indices from the firmware
cover wifi: iwlwifi: validate more indices from the firmware
These patches add range checks for a TID, a BAID and a TX queue number that the firmware reports. Other code paths already have these checks. The patches are independent.
The missing checks were found with a CodeQL-based static analysis tool that we are developing. Each out-of-range access was reproduced in a userspace harness under sanitizers, which report nothing with the patches. Nothing was tested on hardware. The patches were compile-tested with W=1 on next-20261116.
I used an LLM to help write the harnesses and these patches.
Maoyi Xie (4):
wifi: iwlwifi: mvm: validate TID in TX response handlers
wifi: iwlwifi: mvm: validate BAID in the RX path
wifi: iwlwifi: mld: validate BAID in the RX timestamp update
wifi: iwlwifi: pcie: validate txq_id in reclaim
drivers/net/wireless/intel/iwlwifi/mld/rx.c | 4 ++++ drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 8 ++++++++ drivers/net/wireless/intel/iwlwifi/mvm/tx.c | 8 +++++++- drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 9 ++++++++- 4 files changed, 27 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 wifi: iwlwifi: mvm: validate TID in TX response handlers
iwl_mvm_rx_tx_cmd_single() and iwl_mvm_rx_tx_cmd_agg() index mvmsta->tid_data[] with the 4-bit TID from ra_tid. Only the first function skips IWL_MGMT_TID. A TID above 8 writes to the members that follow the array.
Add the check that iwl_mvm_rx_ba_notif() has.
Found with a CodeQL-based static analysis tool.
Reproduced in a userspace harness under UBSan. Not tested on hardware.
---
I used an LLM to help write the harness and this patch.
drivers/net/wireless/intel/iwlwifi/mvm/tx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/wireless/intel/iwlwifi/mvm/tx.c +7 -1
@@ -1731,7 +1731,9 @@ static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm, mvmsta->sta_state < IEEE80211_STA_AUTHORIZED)iwl_mvm_toggle_tx_ant (mvm, &mvmsta->tx_ant); -if (sta->wme && tid !=IWL_MGMT_TID ) { +if (sta->wme && tid !=IWL_MGMT_TID && + !IWL_FW_CHECK (mvm, tid >=ARRAY_SIZE (mvmsta->tid_data), +"invalid TID %d in TX response\n" , tid)) {struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];bool send_eosp_ndp = false;
@@ -1865,6 +1867,10 @@ static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm, (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)))return ; +if (IWL_FW_CHECK (mvm, tid >=ARRAY_SIZE (mvmsta->tid_data), +"invalid TID %d in agg TX response\n" , tid)) +return ; +iwl_mvm_rx_tx_cmd_agg_dbg (mvm, pkt);rcu_read_lock ();
Signature · 1 line
2.34.1
PATCH 2/4 wifi: iwlwifi: mvm: validate BAID in the RX path
In reply to Maoyi Xieiwl_mvm_agg_rx_received() and iwl_mvm_reorder() index mvm->baid_map[] with the 7-bit BAID from the MPDU descriptor. A BAID from 32 to 126 reads past the array.
Check the BAID as iwl_mvm_release_frames_from_notif() does.
Found with a CodeQL-based static analysis tool. Reproduced in a userspace harness under AddressSanitizer and UBSan. Not tested on hardware.
---
I used an LLM to help write the harness and this patch.
drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c +8 -0
@@ -817,6 +817,10 @@ static bool iwl_mvm_reorder(struct iwl_mvm *mvm,if (baid ==IWL_RX_REORDER_DATA_INVALID_BAID )return false; +if (IWL_FW_CHECK (mvm, baid >=ARRAY_SIZE (mvm->baid_map), +"invalid BAID from FW: %d\n" , baid)) +return false; +/* no sta yet */ if (WARN_ONCE (IS_ERR_OR_NULL (sta),"Got valid BAID without a valid station assigned\n" ))
@@ -940,6 +944,10 @@ static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm,unsigned long timeout;struct iwl_mvm_baid_data *data; +if (IWL_FW_CHECK (mvm, baid >=ARRAY_SIZE (mvm->baid_map), +"invalid BAID from FW: %d\n" , baid)) +return ; +rcu_read_lock (); data =rcu_dereference (mvm->baid_map[baid]);
Signature · 1 line
2.34.1
PATCH 3/4 wifi: iwlwifi: mld: validate BAID in the RX timestamp update
In reply to Maoyi Xieiwl_mld_update_last_rx_timestamp() indexes mld->fw_id_to_ba[] with the 7-bit BAID from the MPDU descriptor, before iwl_mld_reorder() checks it. A BAID from 32 to 126 reads past the array.
Add the same check here.
Found with a CodeQL-based static analysis tool. Reproduced in a userspace harness under AddressSanitizer and UBSan. Not tested on hardware.
---
I used an LLM to help write the harness and this patch.
drivers/net/wireless/intel/iwlwifi/mld/rx.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/intel/iwlwifi/mld/rx.c +4 -0
@@ -2311,6 +2311,10 @@ static void iwl_mld_update_last_rx_timestamp(struct iwl_mld *mld, u8 baid)unsigned long timeout;struct iwl_mld_baid_data *ba_data; +if (IWL_FW_CHECK (mld, baid >=ARRAY_SIZE (mld->fw_id_to_ba), +"Got out-of-range BAID %u\n" , baid)) +return ; + ba_data =rcu_dereference (mld->fw_id_to_ba[baid]);if (!ba_data) {IWL_DEBUG_HT (mld,"BAID %d not found in map\n" , baid);
Signature · 1 line
2.34.1
PATCH 4/4 wifi: iwlwifi: pcie: validate txq_id in reclaim
In reply to Maoyi Xieiwl_pcie_reclaim() indexes trans_pcie->txqs.txq[] with a 16-bit queue number that mvm takes unchecked from TX responses, BA notifications and flush responses. A queue number of 512 or more reads past the array.
Add a range check against num_of_queues with IWL_FW_CHECK() before the access.
Found with a CodeQL-based static analysis tool. Reproduced with a TX response in a userspace harness under AddressSanitizer and UBSan. Not tested on hardware.
---
I used an LLM to help write the harness and this patch.
drivers/net/wireless/intel/iwlwifi/pcie/tx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/wireless/intel/iwlwifi/pcie/tx.c +8 -1
@@ -2364,14 +2364,21 @@ void iwl_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn, struct sk_buff_head *skbs, bool is_flush) {struct iwl_trans_pcie *trans_pcie =IWL_TRANS_GET_PCIE_TRANS (trans); -struct iwl_txq *txq = trans_pcie->txqs.txq[txq_id]; +struct iwl_txq *txq;int tfd_num, read_ptr, last_to_free;int txq_read_ptr, txq_write_ptr; +if (IWL_FW_CHECK (trans, + txq_id <0 || + txq_id >= trans->mac_cfg->base->num_of_queues, +"queue %d out of range\n" , txq_id)) +return ; +/* This function is not meant to release cmd queue*/ if (WARN_ON (txq_id == trans->conf.cmd_queue))return ; + txq = trans_pcie->txqs.txq[txq_id];if (WARN_ON (!txq))return ;
Signature · 1 line
2.34.1