* [PATCH rtw-next v2 1/4] wifi: rtw89: pci: reject oversized RX packets
2026-12-02 9:05 [PATCH rtw-next v2 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
@ 2026-12-02 9:05 ` Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 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-02 9:05 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 the 14-bit write size that the chip reports.
Nothing checks it against RTW89_PCI_RX_BUF_SIZE. A larger value makes
them read up to about 5 KB past the buffer.
Check the write size in
rtw89_pci_sync_skb_for_device_and_validate_rx_info(). Also check the end
of the copy in rtw89_skb_put_rx_data().
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.
v2: Move the rx_info->len check to
rtw89_pci_sync_skb_for_device_and_validate_rx_info() (Ping-Ke Shih).
Keep the check in rtw89_skb_put_rx_data(). With a write size below the
data offset, copy_len wraps and the pkt_size fallback can still read
past the buffer.
drivers/net/wireless/realtek/rtw89/pci.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireless/realtek/rtw89/pci.c
index 2b6a5e22221d..c47d1a0ce18c 100644
--- a/drivers/net/wireless/realtek/rtw89/pci.c
+++ b/drivers/net/wireless/realtek/rtw89/pci.c
@@ -243,7 +243,16 @@ int rtw89_pci_sync_skb_for_device_and_validate_rx_info(struct rtw89_dev *rtwdev,
/* update target rx_tag for next RX */
rx_ring->target_rx_tag = rx_info->tag + 1;
- return ret;
+ if (ret)
+ return ret;
+
+ if (unlikely(rx_info->len > RTW89_PCI_RX_BUF_SIZE)) {
+ rtw89_debug(rtwdev, RTW89_DBG_UNEXP, "oversized RXBD len: %u\n",
+ rx_info->len);
+ return -EINVAL;
+ }
+
+ return 0;
}
static void rtw89_pci_ctrl_txdma_ch_ax(struct rtw89_dev *rtwdev, bool enable)
@@ -298,6 +307,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;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH rtw-next v2 2/4] wifi: rtw89: pci: validate hardware index of BD ring
2026-12-02 9:05 [PATCH rtw-next v2 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
@ 2026-12-02 9:05 ` Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 3/4] wifi: rtw89: fw: check C2H event length Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 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-02 9:05 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>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
---
I used an LLM to help write the harness and this patch.
v2: Add Acked-by.
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 c47d1a0ce18c..54cbaf817288 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 v2 3/4] wifi: rtw89: fw: check C2H event length
2026-12-02 9:05 [PATCH rtw-next v2 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 2/4] wifi: rtw89: pci: validate hardware index of BD ring Maoyi Xie
@ 2026-12-02 9:05 ` Maoyi Xie
2026-12-02 9:05 ` [PATCH rtw-next v2 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-02 9:05 UTC (permalink / raw)
To: Ping-Ke Shih; +Cc: linux-wireless
Nothing checks the length field of the C2H header against the skb. If
the header claims more data than arrived, the debug prints of the LPS
report handler read up to 16 KB past the skb data, even with the debug
mask off.
Drop such events in rtw89_fw_c2h_cmd_handle(). In the LPS report
handler, check that the skb holds the counts before reading them.
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.
v2: Check the length in rtw89_fw_c2h_cmd_handle() with unlikely()
(Ping-Ke Shih). Keep the size check in rtw89_phy_c2h_lps_rpt().
drivers/net/wireless/realtek/rtw89/fw.c | 3 +++
drivers/net/wireless/realtek/rtw89/phy.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
index 89559454ebe2..2eb77d4c29de 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.c
+++ b/drivers/net/wireless/realtek/rtw89/fw.c
@@ -9701,6 +9701,9 @@ static void rtw89_fw_c2h_cmd_handle(struct rtw89_dev *rtwdev,
if (!test_bit(RTW89_FLAG_RUNNING, rtwdev->flags))
return;
+ if (unlikely(len > skb->len))
+ return;
+
switch (category) {
case RTW89_C2H_CAT_TEST:
break;
diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c
index 133b591ffa7f..139f5a9abc32 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))
+ 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 v2 4/4] wifi: rtw89: phy: check cur_idx of TAS power report
2026-12-02 9:05 [PATCH rtw-next v2 0/4] wifi: rtw89: check lengths and indices reported by the chip Maoyi Xie
` (2 preceding siblings ...)
2026-12-02 9:05 ` [PATCH rtw-next v2 3/4] wifi: rtw89: fw: check C2H event length Maoyi Xie
@ 2026-12-02 9:05 ` Maoyi Xie
3 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-12-02 9:05 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>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
---
I used an LLM to help write the harness and this patch.
v2: Add Acked-by.
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 139f5a9abc32..4cacc5584296 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