ath10k_usb_rx_complete() uses the endpoint id from the first byte of each received frame as an index into ar->htc.endpoint[] without checking it, then reads ep->service_id and calls ep->ep_ops.ep_rx_complete() through that entry. The header length is not checked against the received length either. A USB device can make the driver read out of bounds and call through a function pointer read from outside the array. This is reachable even after a failed probe, as the driver stays bound and ath10k_usb_pm_resume() posts the RX URBs on every resume. Drop frames shorter than the HTC header, with an endpoint id >= ATH10K_HTC_EP_COUNT, or with a payload longer than the received data, as ath10k_htc_rx_completion_handler() does for the other buses. The bug was found, and the reproducer and this fix were written, by AI agents (Claude Mythos and Claude Opus models). The analysis and the patch were reviewed by a human. Fixes: 4db66499df91 ("ath10k: add initial USB support") Cc: stable@vger.kernel.org Signed-off-by: Alexandre Becholey --- An emulated 13b1:0042 device sending HTC frames with endpoint ids 9..255 after one runtime suspend/resume triggers it (UBSAN array-index-out-of-bounds at usb.c:304, KASAN or a bad indirect call, depending on the id) on v7.3.1 and master 9d66f26fefac. No reports with the fix. The two length checks were reviewed but not exercised at runtime (no endpoint is connected in that state). Not tested on real hardware. Reproducer available on request. Applies to master 4405c18c95d2 (usb.c unchanged since the tests). drivers/net/wireless/ath/ath10k/usb.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/wireless/ath/ath10k/usb.c b/drivers/net/wireless/ath/ath10k/usb.c index 987d57a01ddf..0c900351ba8c 100644 --- a/drivers/net/wireless/ath/ath10k/usb.c +++ b/drivers/net/wireless/ath/ath10k/usb.c @@ -299,8 +299,18 @@ static void ath10k_usb_rx_complete(struct ath10k *ar, struct sk_buff *skb) u8 *trailer; int ret; + if (skb->len < sizeof(*htc_hdr)) { + ath10k_warn(ar, "short frame received: %u\n", skb->len); + goto out_free_skb; + } + htc_hdr = (struct ath10k_htc_hdr *)skb->data; eid = eid_from_htc_hdr(htc_hdr); + if (eid >= ATH10K_HTC_EP_COUNT) { + ath10k_warn(ar, "invalid eid %d\n", eid); + goto out_free_skb; + } + ep = &ar->htc.endpoint[eid]; if (ep->service_id == 0) { @@ -314,6 +324,12 @@ static void ath10k_usb_rx_complete(struct ath10k *ar, struct sk_buff *skb) goto out_free_skb; } + if (payload_len > skb->len - sizeof(*htc_hdr)) { + ath10k_warn(ar, "truncated frame received: payload %u len %u\n", + payload_len, skb->len); + goto out_free_skb; + } + if (payload_len < htc_hdr->trailer_len) { ath10k_warn(ar, "malformed frame received, firmware crashed?\n"); goto out_free_skb; -- 2.53.0