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 Acked-by: Ping-Ke Shih --- I used an LLM to help write the harness and this patch. v3: No change. 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 51851d2bee7c..df6f5f099390 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