Linux wireless drivers development
 help / color / mirror / Atom feed
From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Ping-Ke Shih <pkshih@realtek.com>
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH rtw-next v2 1/4] wifi: rtw89: pci: reject oversized RX packets
Date: Wed,  2 Dec 2026 17:05:04 +0800	[thread overview]
Message-ID: <20261202090507.1613331-2-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261202090507.1613331-1-maoyixie.tju@gmail.com>

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


  reply	other threads:[~2026-12-02  9:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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 ` [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202090507.1613331-2-maoyixie.tju@gmail.com \
    --to=maoyixie.tju@gmail.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox