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(). A write size below the data offset makes copy_len wrap, and a single segment then copies desc_info->pkt_size bytes. Use that fallback only when it fits in the buffer. 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 --- I used an LLM to help write the harness and this patch. v3: Replace the end-of-copy check with a bound on the pkt_size fallback in rtw89_skb_put_rx_data() (Ping-Ke Shih). v2: Move the rx_info->len check to rtw89_pci_sync_skb_for_device_and_validate_rx_info() (Ping-Ke Shih). drivers/net/wireless/realtek/rtw89/pci.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw89/pci.c b/drivers/net/wireless/realtek/rtw89/pci.c index 2b6a5e22221d..51851d2bee7c 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) @@ -290,7 +299,8 @@ rtw89_skb_put_rx_data(struct rtw89_dev *rtwdev, bool fs, bool ls, rtw89_hex_dump(rtwdev, RTW89_DBG_TXRX, "rx_data: ", skb->data, rx_info->len); /* length of a single segment skb is desc_info->pkt_size */ - if (fs && ls) { + if (fs && ls && + offset + desc_info->pkt_size <= RTW89_PCI_RX_BUF_SIZE) { copy_len = desc_info->pkt_size; } else { rtw89_info(rtwdev, "drop rx data due to invalid length\n"); -- 2.34.1