1: ebe2515fa345 ! 1: 1f450fe10170 wifi: rtw89: pci: reject oversized RX packets @@ Commit message wifi: rtw89: pci: reject oversized RX packets  rtw89_skb_put_rx_data() and rtw89_pci_release_tx_skbs() take the data - length of an RX buffer from 14-bit fields that the chip writes. Nothing - checks it against RTW89_PCI_RX_BUF_SIZE. A larger length makes them - read up to about 5 KB past the buffer. + 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.  - Drop such a packet. + 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. @@ Commit message Signed-off-by: Maoyi Xie   ## drivers/net/wireless/realtek/rtw89/pci.c ## +@@ drivers/net/wireless/realtek/rtw89/pci.c: 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)  @@ drivers/net/wireless/realtek/rtw89/pci.c: rtw89_skb_put_rx_data(struct rtw89_dev *rtwdev, bool fs, bool ls, } } @@ drivers/net/wireless/realtek/rtw89/pci.c: rtw89_skb_put_rx_data(struct rtw89_dev skb_put_data(new, skb->data + offset, copy_len);  return true; -@@ drivers/net/wireless/realtek/rtw89/pci.c: static u32 rtw89_pci_release_tx_skbs(struct rtw89_dev *rtwdev, - return cnt; - } -  -+ if (unlikely(rx_info->len > RTW89_PCI_RX_BUF_SIZE)) { -+ rtw89_debug(rtwdev, RTW89_DBG_TXRX, -+ "oversized RP frame: %u\n", rx_info->len); -+ goto err_sync_device; -+ } -+ - rtw89_chip_query_rxdesc(rtwdev, &desc_info, skb->data, rxinfo_size); -  - /* first segment has RX desc */ 2: 4cd968053dcc ! 2: 4feeb9918ee5 wifi: rtw89: pci: validate hardware index of BD ring @@ Commit message Fixes: e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie  + Acked-by: Ping-Ke Shih   ## drivers/net/wireless/realtek/rtw89/pci.c ##  @@ drivers/net/wireless/realtek/rtw89/pci.c: static u32 rtw89_pci_dma_recalc(struct rtw89_dev *rtwdev, 3: 2cc8c5e81b10 ! 3: 2263d5a54b52 wifi: rtw89: phy: check LPS report C2H event length @@ Metadata Author: Maoyi Xie   ## Commit message ## - wifi: rtw89: phy: check LPS report C2H event length + wifi: rtw89: fw: check C2H event length  - The LPS report handler checks the length from the C2H header and the - counts in the report against each other, but not against the skb. If - the header claims more data than arrived, the debug prints read up to - 16 KB past the skb data, even with the debug mask off. + 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.  - Check the skb length before processing the report. + 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   + ## drivers/net/wireless/realtek/rtw89/fw.c ## +@@ drivers/net/wireless/realtek/rtw89/fw.c: 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; + ## drivers/net/wireless/realtek/rtw89/phy.c ##  @@ drivers/net/wireless/realtek/rtw89/phy.c: 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) || len > c2h->len) ++ if (c2h->len < sizeof(*c2h_rpt))  + return;  + /* elements size of BBCR/BBMCUCR/RFCR are 6/6/10 bytes respectively */ 4: 797a591613c3 ! 4: ca5fc90d0b5c wifi: rtw89: phy: check cur_idx of TAS power report @@ Commit message userspace harness under AddressSanitizer. Not tested on hardware.  Signed-off-by: Maoyi Xie  + Acked-by: Ping-Ke Shih   ## drivers/net/wireless/realtek/rtw89/phy.c ##  @@ drivers/net/wireless/realtek/rtw89/phy.c: void rtw89_phy_c2h_rfk_tas_pwr(struct rtw89_dev *rtwdev,