Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH rtw-next 0/4] wifi: rtw89: check lengths and indices reported by the chip
@ 2026-12-01  9:01 Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:01 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless

These patches add checks for two lengths and two indices that the chip
reports. The patches are independent.

Found with a CodeQL-based static analysis tool that we are developing.
Each case was reproduced in a userspace harness under AddressSanitizer.
Not tested on hardware. Compile-tested with W=1 on rtw-next.

I used an LLM to help write the harnesses and these patches.

Maoyi Xie (4):
  wifi: rtw89: pci: reject oversized RX packets
  wifi: rtw89: pci: validate hardware index of BD ring
  wifi: rtw89: phy: check LPS report C2H event length
  wifi: rtw89: phy: check cur_idx of TAS power report

 drivers/net/wireless/realtek/rtw89/pci.c | 18 ++++++++++++++++++
 drivers/net/wireless/realtek/rtw89/phy.c |  6 ++++++
 2 files changed, 24 insertions(+)

-- 
2.34.1


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

* [PATCH rtw-next 1/4] wifi: rtw89: pci: reject oversized RX packets
  2026-12-01  9:01 [PATCH rtw-next 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
@ 2026-12-01  9:01 ` Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 2/4] wifi: rtw89: pci: validate hardware index of BD ring Maoyi Xie
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:01 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless

rtw89_skb_put_rx_data() and rtw89_pci_release_tx_skbs() take the data
length of an RX buffer from 14-bit fields that the chip writes. Nothing
checks it against RTW89_PCI_RX_BUF_SIZE. A larger length makes them
read up to about 5 KB past the buffer.

Drop such a packet.

Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. Not tested on hardware.

Fixes: e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.

 drivers/net/wireless/realtek/rtw89/pci.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireless/realtek/rtw89/pci.c
index 76523d057825..daa3a978bd31 100644
--- a/drivers/net/wireless/realtek/rtw89/pci.c
+++ b/drivers/net/wireless/realtek/rtw89/pci.c
@@ -298,6 +298,12 @@ rtw89_skb_put_rx_data(struct rtw89_dev *rtwdev, bool fs, bool ls,
 		}
 	}
 
+	if (unlikely(offset + copy_len > RTW89_PCI_RX_BUF_SIZE)) {
+		rtw89_debug(rtwdev, RTW89_DBG_TXRX,
+			    "oversized RX packet: %u\n", offset + copy_len);
+		return false;
+	}
+
 	skb_put_data(new, skb->data + offset, copy_len);
 
 	return true;
@@ -674,6 +680,12 @@ static u32 rtw89_pci_release_tx_skbs(struct rtw89_dev *rtwdev,
 		return cnt;
 	}
 
+	if (unlikely(rx_info->len > RTW89_PCI_RX_BUF_SIZE)) {
+		rtw89_debug(rtwdev, RTW89_DBG_TXRX,
+			    "oversized RP frame: %u\n", rx_info->len);
+		goto err_sync_device;
+	}
+
 	rtw89_chip_query_rxdesc(rtwdev, &desc_info, skb->data, rxinfo_size);
 
 	/* first segment has RX desc */
-- 
2.34.1


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

* [PATCH rtw-next 2/4] wifi: rtw89: pci: validate hardware index of BD ring
  2026-12-01  9:01 [PATCH rtw-next 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
@ 2026-12-01  9:01 ` Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 3/4] wifi: rtw89: phy: check LPS report C2H event length Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 4/4] wifi: rtw89: phy: check cur_idx of TAS power report Maoyi Xie
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:01 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless

The hardware index of a BD ring has 12 bits, but a ring has 256
entries. With an index of 512 or more (4095 for a read of 0xffffffff),
a failed release can leave the RX write pointer outside the ring. On
chips without rx_ring_eq_is_full, the next poll reads rx_ring->buf[]
out of bounds.

Ignore an index outside the ring.

Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. Not tested on hardware.

Fixes: e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.

 drivers/net/wireless/realtek/rtw89/pci.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireless/realtek/rtw89/pci.c
index daa3a978bd31..d0cd73ea04b7 100644
--- a/drivers/net/wireless/realtek/rtw89/pci.c
+++ b/drivers/net/wireless/realtek/rtw89/pci.c
@@ -70,6 +70,12 @@ static u32 rtw89_pci_dma_recalc(struct rtw89_dev *rtwdev,
 	len = bd_ring->len;
 
 	cur_rp = FIELD_GET(TXBD_HW_IDX_MASK, cur_idx);
+	if (unlikely(cur_rp >= len)) {
+		rtw89_debug(rtwdev, RTW89_DBG_UNEXP,
+			    "invalid BD ring idx=0x%08x, len=%u\n", cur_idx, len);
+		return 0;
+	}
+
 	if (tx) {
 		cnt = cur_rp >= rp ? cur_rp - rp : len - (rp - cur_rp);
 	} else {
-- 
2.34.1


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

* [PATCH rtw-next 3/4] wifi: rtw89: phy: check LPS report C2H event length
  2026-12-01  9:01 [PATCH rtw-next 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 2/4] wifi: rtw89: pci: validate hardware index of BD ring Maoyi Xie
@ 2026-12-01  9:01 ` Maoyi Xie
  2026-12-01  9:01 ` [PATCH rtw-next 4/4] wifi: rtw89: phy: check cur_idx of TAS power report Maoyi Xie
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:01 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless

The LPS report handler checks the length from the C2H header and the
counts in the report against each other, but not against the skb. If
the header claims more data than arrived, the debug prints read up to
16 KB past the skb data, even with the debug mask off.

Check the skb length before processing the report.

Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. 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/realtek/rtw89/phy.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c
index 133b591ffa7f..b4f1802025c9 100644
--- a/drivers/net/wireless/realtek/rtw89/phy.c
+++ b/drivers/net/wireless/realtek/rtw89/phy.c
@@ -3449,6 +3449,9 @@ rtw89_phy_c2h_lps_rpt(struct rtw89_dev *rtwdev, struct sk_buff *c2h, u32 len)
 	const __le16 *addr;
 	const u8 *info;
 
+	if (c2h->len < sizeof(*c2h_rpt) || len > c2h->len)
+		return;
+
 	/* elements size of BBCR/BBMCUCR/RFCR are 6/6/10 bytes respectively */
 	cr_len = c2h_rpt->cnt_bbcr * 6 +
 		 c2h_rpt->cnt_bbmcucr * 6 +
-- 
2.34.1


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

* [PATCH rtw-next 4/4] wifi: rtw89: phy: check cur_idx of TAS power report
  2026-12-01  9:01 [PATCH rtw-next 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
                   ` (2 preceding siblings ...)
  2026-12-01  9:01 ` [PATCH rtw-next 3/4] wifi: rtw89: phy: check LPS report C2H event length Maoyi Xie
@ 2026-12-01  9:01 ` Maoyi Xie
  3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-12-01  9:01 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless

rtw89_phy_c2h_rfk_tas_pwr() averages txpwr_history[i] for i below
cur_idx. cur_idx comes from the firmware report, and nothing checks it
against the 20 entries of txpwr_history[]. A larger value makes the
loop read past the report.

Ignore the report when cur_idx exceeds the size of txpwr_history[].

Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. 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/realtek/rtw89/phy.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c
index b4f1802025c9..26675a31ced9 100644
--- a/drivers/net/wireless/realtek/rtw89/phy.c
+++ b/drivers/net/wireless/realtek/rtw89/phy.c
@@ -3541,6 +3541,9 @@ void rtw89_phy_c2h_rfk_tas_pwr(struct rtw89_dev *rtwdev,
 		return;
 
 	cur_idx = le32_to_cpu(content->cur_idx);
+	if (cur_idx > ARRAY_SIZE(content->txpwr_history))
+		return;
+
 	for (i = 0; i < cur_idx; i++) {
 		txpwr = le16_to_cpu(content->txpwr_history[i]);
 		linear += rtw89_db_quarter_to_linear(txpwr);
-- 
2.34.1


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

end of thread, other threads:[~2026-12-01  9:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  9:01 [PATCH rtw-next 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
2026-12-01  9:01 ` [PATCH rtw-next 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
2026-12-01  9:01 ` [PATCH rtw-next 2/4] wifi: rtw89: pci: validate hardware index of BD ring Maoyi Xie
2026-12-01  9:01 ` [PATCH rtw-next 3/4] wifi: rtw89: phy: check LPS report C2H event length Maoyi Xie
2026-12-01  9:01 ` [PATCH rtw-next 4/4] wifi: rtw89: phy: check cur_idx of TAS power report Maoyi Xie

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