Skip to contentSkip to conversation

wifi: rtw88: usb: reject oversized RX packets

PATCH In review Maoyi Xie 3 participants 4 messages Nov 28 – Dec 1 Realtek wireless driver (rtw88)

lore
Share & tools
lore

Maoyi Xie

author
#0 lore raw

PATCH 1/1 wifi: rtw88: usb: reject oversized RX packets

rtw_usb_rx_handler() checks pkt_len + pkt_offset of each aggregated RX packet only against max_skb_len. If a corrupted descriptor claims more than the bytes left in the URB, skb_put_data() reads up to about 11 KB past the received data.

Stop the walk when a packet does not fit in the rest of the URB.

Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware.

Fixes e9048e2935f7 ("wifi: rtw88: usb: Copy instead of cloning the RX skb")

---
I used an LLM to help write the harness and this patch.

Commit 83ca360e8528 ("wifi: rtw88: sdio: reject oversized RX packets") added the same check. The rtw89 USB RX handler also drops such a packet.

 drivers/net/wireless/realtek/rtw88/usb.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/wireless/realtek/rtw88/usb.c +7 -0
index 7b1fc7ef10a0..ef2a0686b7cf 100644
@@ -718,6 +718,13 @@ static void rtw_usb_rx_handler(struct work_struct *work)
 				goto skip_packet;
 			}
 
+			if (unlikely(rx_desc + skb_len > rx_skb->data + rx_skb->len)) {
+				rtw_dbg(rtwdev, RTW_DBG_USB,
+					"oversized RX packet: %u, %td bytes left\n",
+					skb_len, rx_skb->data + rx_skb->len - rx_desc);
+				break;
+			}
+
 			skb = alloc_skb(skb_len, GFP_ATOMIC);
 			if (!skb) {
 				rtw_dbg(rtwdev, RTW_DBG_USB,
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Maoyi Xie

rtw_usb_rx_handler() checks pkt_len + pkt_offset of each aggregated RX packet only against max_skb_len. If a corrupted descriptor claims more than the bytes left in the URB, skb_put_data() reads up to about 11 KB past the received data.

Stop the walk when a packet does not fit in the rest of the URB.

Quoted 8 lines

Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware.

Fixes e9048e2935f7 ("wifi: rtw88: usb: Copy instead of cloning the RX skb")

---

Looks good to me,

Best regards,
Luka Gejak

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Maoyi Xie
Quoted 7 lines · Maoyi Xie

rtw_usb_rx_handler() checks pkt_len + pkt_offset of each aggregated RX packet only against max_skb_len. If a corrupted descriptor claims more than the bytes left in the URB, skb_put_data() reads up to about 11 KB past the received data.

Stop the walk when a packet does not fit in the rest of the URB.

Quoted 7 lines

Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware.

Fixes e9048e2935f7 ("wifi: rtw88: usb: Copy instead of cloning the RX skb")
maintainer
#3 lore raw
In reply to Maoyi Xie
Quoted 11 lines · Maoyi Xie

rtw_usb_rx_handler() checks pkt_len + pkt_offset of each aggregated RX packet only against max_skb_len. If a corrupted descriptor claims more than the bytes left in the URB, skb_put_data() reads up to about 11 KB past the received data.

Stop the walk when a packet does not fit in the rest of the URB.

Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware.

Quoted 5 lines
Fixes e9048e2935f7 ("wifi: rtw88: usb: Copy instead of cloning the RX skb")

1 patch(es) applied to rtw-next branch of rtw.git, thanks.

6b94f519cbc9 wifi: rtw88: usb: reject oversized RX packets

---
https://github.com/pkshih/rtw.git