Skip to content

Commit c088d5d

Browse files
committed
usb: gadget: f_phonet: fix skb frags[] overflow in pn_rx_complete()
A broken/bored/mean USB host can overflow the skb_shared_info->frags[] array on a Linux gadget exposing a Phonet function by sending an unbounded sequence of full-page OUT transfers. pn_rx_complete() finalizes the skb only when req->actual < req->length, where req->length is set to PAGE_SIZE by the gadget. If the host always sends exactly PAGE_SIZE bytes per transfer, fp->rx.skb will never be reset and each completion will add another fragment via skb_add_rx_frag(). Once nr_frags exceeds MAX_SKB_FRAGS (default 17), subsequent frag stores overwrite memory adjacent to the shinfo on the heap. Drop the skb and account a length error when the frag limit is reached, matching the fix applied in t7xx by commit f0813bc ("net: wwan: t7xx: fix potential skb->frags overflow in RX path"). Cc: stable <stable@kernel.org> Assisted-by: gregkh_clanker_t1000 Link: https://patch.msgid.link/2026040705-fruit-unloved-0701@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2c863db commit c088d5d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

drivers/usb/gadget/function/f_phonet.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
333333
if (unlikely(!skb))
334334
break;
335335

336+
if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) {
337+
/* Frame count from host exceeds frags[] capacity */
338+
dev_kfree_skb_any(skb);
339+
if (fp->rx.skb == skb)
340+
fp->rx.skb = NULL;
341+
dev->stats.rx_length_errors++;
342+
break;
343+
}
344+
336345
if (skb->len == 0) { /* First fragment */
337346
skb->protocol = htons(ETH_P_PHONET);
338347
skb_reset_mac_header(skb);

0 commit comments

Comments
 (0)