Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH iwlwifi-next 0/4] wifi: iwlwifi: validate more indices from the firmware
@ 2026-11-25  8:37 Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 1/4] wifi: iwlwifi: mvm: validate TID in TX response handlers Maoyi Xie
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-11-25  8:37 UTC (permalink / raw)
  To: Miri Korenblit; +Cc: linux-wireless

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(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH iwlwifi-next 1/4] wifi: iwlwifi: mvm: validate TID in TX response handlers
  2026-11-25  8:37 [PATCH iwlwifi-next 0/4] wifi: iwlwifi: validate more indices from the firmware Maoyi Xie
@ 2026-11-25  8:37 ` Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 2/4] wifi: iwlwifi: mvm: validate BAID in the RX path Maoyi Xie
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-11-25  8:37 UTC (permalink / raw)
  To: Miri Korenblit; +Cc: linux-wireless

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.

Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
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(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
index d3c2fe830477..d06ce3d1eb68 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
@@ -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();
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH iwlwifi-next 2/4] wifi: iwlwifi: mvm: validate BAID in the RX path
  2026-11-25  8:37 [PATCH iwlwifi-next 0/4] wifi: iwlwifi: validate more indices from the firmware Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 1/4] wifi: iwlwifi: mvm: validate TID in TX response handlers Maoyi Xie
@ 2026-11-25  8:37 ` Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 3/4] wifi: iwlwifi: mld: validate BAID in the RX timestamp update Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 4/4] wifi: iwlwifi: pcie: validate txq_id in reclaim Maoyi Xie
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-11-25  8:37 UTC (permalink / raw)
  To: Miri Korenblit; +Cc: linux-wireless

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

Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
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(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
index 77a3d8dcab57..0dfbf704d5d3 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
@@ -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]);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH iwlwifi-next 3/4] wifi: iwlwifi: mld: validate BAID in the RX timestamp update
  2026-11-25  8:37 [PATCH iwlwifi-next 0/4] wifi: iwlwifi: validate more indices from the firmware Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 1/4] wifi: iwlwifi: mvm: validate TID in TX response handlers Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 2/4] wifi: iwlwifi: mvm: validate BAID in the RX path Maoyi Xie
@ 2026-11-25  8:37 ` Maoyi Xie
  2026-11-25  8:37 ` [PATCH iwlwifi-next 4/4] wifi: iwlwifi: pcie: validate txq_id in reclaim Maoyi Xie
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-11-25  8:37 UTC (permalink / raw)
  To: Miri Korenblit; +Cc: linux-wireless

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

Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
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(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c
index e1964e570012..af0373d5e693 100644
--- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c
+++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH iwlwifi-next 4/4] wifi: iwlwifi: pcie: validate txq_id in reclaim
  2026-11-25  8:37 [PATCH iwlwifi-next 0/4] wifi: iwlwifi: validate more indices from the firmware Maoyi Xie
                   ` (2 preceding siblings ...)
  2026-11-25  8:37 ` [PATCH iwlwifi-next 3/4] wifi: iwlwifi: mld: validate BAID in the RX timestamp update Maoyi Xie
@ 2026-11-25  8:37 ` Maoyi Xie
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-11-25  8:37 UTC (permalink / raw)
  To: Miri Korenblit; +Cc: linux-wireless

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

Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
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(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
index 0c29fb6b9ca7..48165a40e2cc 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
@@ -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;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-25  8:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  8:37 [PATCH iwlwifi-next 0/4] wifi: iwlwifi: validate more indices from the firmware Maoyi Xie
2026-11-25  8:37 ` [PATCH iwlwifi-next 1/4] wifi: iwlwifi: mvm: validate TID in TX response handlers Maoyi Xie
2026-11-25  8:37 ` [PATCH iwlwifi-next 2/4] wifi: iwlwifi: mvm: validate BAID in the RX path Maoyi Xie
2026-11-25  8:37 ` [PATCH iwlwifi-next 3/4] wifi: iwlwifi: mld: validate BAID in the RX timestamp update Maoyi Xie
2026-11-25  8:37 ` [PATCH iwlwifi-next 4/4] wifi: iwlwifi: pcie: validate txq_id in reclaim Maoyi Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox