From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 361EA3358B0; Mon, 20 Apr 2026 16:03:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700985; cv=none; b=okWCWxwCfTt8g7LSJk5cmav3tuatTu75m5pfnOovJrs/c2ZdqSegzsQxfK25QGUYK95+vsPbAy2+UfbYnieSKElyZ9sYZpUbOFm+VhA8/YxKsT5Dg+VilfHX/cqoSByXC0lQ3lp3drXNULiLzzKHJWmzEf4/QfYZMCPhuxoYTkk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700985; c=relaxed/simple; bh=SAqpIsiRi2LCDB3XX+ahzdsxXK7Yefb0T944neXfPrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nQIWHSwDAJf4Jf5z/7U1lI45JaFI7bBKKM4tkofd+BKkDZYMDZv1YpbD4xOfMaLmUuBBK3YrlAAM5r+8ZFpr8KJGk7K5UeyyYMjythWKqmuYmduJxepk5JYvQouVH02HbT0whxsTL25E10KNNjwl8YXGFNp/zbM0ICJBlWAEZc4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rpTWh2S4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="rpTWh2S4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1758C19425; Mon, 20 Apr 2026 16:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776700985; bh=SAqpIsiRi2LCDB3XX+ahzdsxXK7Yefb0T944neXfPrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rpTWh2S4GgeaN5d+l6ETxemO+yjMDujgAH0ifUM4VIC1EI+32l6Bndb3GbJN8FLqr dlRktJGTWztJIkXS1sq2XvHDCikb6oDLNj+oXDZmBozaM84F9qX0hR4h2Fr1FJaWyi loPEFH4k42uHJgcrFIWu7o6UfUvi/b7B0J4izt5s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable Subject: [PATCH 6.18 135/198] usb: gadget: f_phonet: fix skb frags[] overflow in pn_rx_complete() Date: Mon, 20 Apr 2026 17:41:54 +0200 Message-ID: <20260420153940.468549747@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260420153935.605963767@linuxfoundation.org> References: <20260420153935.605963767@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Greg Kroah-Hartman commit c088d5dd2fffb4de1fb8e7f57751c8b82942180a upstream. 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 f0813bcd2d9d ("net: wwan: t7xx: fix potential skb->frags overflow in RX path"). Cc: stable Assisted-by: gregkh_clanker_t1000 Link: https://patch.msgid.link/2026040705-fruit-unloved-0701@gregkh Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_phonet.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/usb/gadget/function/f_phonet.c +++ b/drivers/usb/gadget/function/f_phonet.c @@ -333,6 +333,15 @@ static void pn_rx_complete(struct usb_ep if (unlikely(!skb)) break; + if (unlikely(skb_shinfo(skb)->nr_frags >= MAX_SKB_FRAGS)) { + /* Frame count from host exceeds frags[] capacity */ + dev_kfree_skb_any(skb); + if (fp->rx.skb == skb) + fp->rx.skb = NULL; + dev->stats.rx_length_errors++; + break; + } + if (skb->len == 0) { /* First fragment */ skb->protocol = htons(ETH_P_PHONET); skb_reset_mac_header(skb);