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 2/4] wifi: rtw89: pci: validate hardware index of BD ring
Date: Wed, 2 Dec 2026 17:05:05 +0800 [thread overview]
Message-ID: <20261202090507.1613331-3-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261202090507.1613331-1-maoyixie.tju@gmail.com>
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
next prev parent reply other threads:[~2026-12-02 9:05 UTC|newest]
Thread overview: 9+ 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 ` [PATCH rtw-next v2 1/4] wifi: rtw89: pci: reject oversized RX packets Maoyi Xie
2026-12-03 9:05 ` Ping-Ke Shih
2026-12-03 10:52 ` Maoyi Xie
2026-12-04 0:38 ` Ping-Ke Shih
2026-12-02 9:05 ` Maoyi Xie [this message]
2026-12-02 9:05 ` [PATCH rtw-next v2 3/4] wifi: rtw89: fw: check C2H event length Maoyi Xie
2026-12-03 9:10 ` Ping-Ke Shih
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-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.