From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 F0C4E1DE4EF; Sat, 30 May 2026 16:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780159055; cv=none; b=egu5v3l10d3KriHB0Vqrt0ZGR3CLnKQXwpygnBeTCjc8yaDaXsRXpUG0E5uJyXhRXNn0VN+Jtccy5PAt7Zpc7uXBxhaDJFUrQtIGqcKQnimmH/hasP5Dm1Re1fZPAGuvIXNxOWcs4sRw+XLu6F0+lz+fuqShRli0zzv8jxAFVQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780159055; c=relaxed/simple; bh=2gpCMEP/wpcDIB+rBRHqsAa2I3GNXWxYeB3f3ysoOVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LhnkzI7yl9FF+MMi9RVcCDZWlBRErylMxiCCkWt6inXFNrCzLR614H9LDiUPqTDlo1SWJds8U0iuBa8SJIeakkfPE2EyhG5yqYzxFxc955574ao14bB5L4wc6ZQovnEG+ptwZk4CwBqKRK4y9cj0mhJnN9CmR550Uo/QTxfk3E8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2eVhgxCK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2eVhgxCK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1EB11F00893; Sat, 30 May 2026 16:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780159054; bh=N/T2dQClqFO1Jfup6kv+T23k6p9HRKjNJwxOwOOMvxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2eVhgxCKil9OiQ3XKCL5oMTa10ngD7aqPKqSST3/SYSPXU7TcChHeU+flg3T/R6Z3 OBDyi5lRShafZyCY7jvDEfd7M2ntYl63mDUs+6kaPCMtOtcPvCJxckkLnvnQn1NPT5 TwLuwxeT1yar2AbM51v+1uTtWxSM9TmqSH6K3jog= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable Subject: [PATCH 6.1 068/969] usb: gadget: f_phonet: fix skb frags[] overflow in pn_rx_complete() Date: Sat, 30 May 2026 17:53:12 +0200 Message-ID: <20260530160302.251557537@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160300.485627683@linuxfoundation.org> References: <20260530160300.485627683@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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);