From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387979; b=J1WIkt7SVAbwJALxWUnQiIx9/qC7uRDFSTH1GBT3iwGIBpc6hjAPpnQXQ7BWNMCNALgL 8dkkJudC6mhPc/2qgs59Wx2sfPFVumyEvJJHNaoL8fGDNItoUNfy1jg/HMVRUVd0e0a0L YDv07EZyMbBH8xuuqV+OIW0LsyPbFb5X1qLqKJrVdTWH2L1Ls2iQT1Z/syFPr8kDQlLUY O9fCEiZwyq2FLuuc41F+EEal0XjS/FwDueLtek4hh+oTA063U2aGI2hMa/6Dqbczaz55c AYlOsRyd6wfMdEPauFPdujMpBqlKosz32mWJmn1TCrAZLicJUW96vO4V60Ygj2yIyGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387979; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=qMG+DCm2xyj2qIRIcU5dv6BV32njgm8zUFtMx7oyYMQ=; b=WrBPmn8tiK2dpKMMAvbqkd3EA/TR6e1yRy8hVJCFrB1ic0WJMTPDtDpT45pGGz/31LBo FHsgrsw/P0C8qKk/HjGwoyGOaMwKtoZRcYY5aijYaKLPQe7GLgm5+HmTEyn0D0CTebTSm EL6HumsHni2XRuTia3Em14RvEvEVuiQ+k36pfptHBG5D3PCKeMtx7ENWuSbbvjZDzcDLy 0Mof41murHTEu7dCMQDhsm8gxS9tfuB5luFvyNgkpsYQSg7e/B1TMJXTa5EZ3IO5ITYPN 28/zaMNKN5Gh5Uiyvi62+wnlBBoAZSRWN1hW4ArXbUCLzl36LlcNkMOGJ0agyZI72eA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bZ0XM9Wp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C01EA606A33E; Fri, 4 Dec 2026 12:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bZ0XM9Wp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C5201F000CE; Fri, 4 Dec 2026 12:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387979; bh=qMG+DCm2xyj2qIRIcU5dv6BV32njgm8zUFtMx7oyYMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bZ0XM9WpJURrxfSHeLH/2pCzGcv+zR/MUGI81ICXAMgs96+MN3dYt+k4Dvm41xG0+ LSHFDn4dsPGHNFzQjtxGIztD4EtBKa24EAvSBTQfBv7u2E4ltJCYNmN+1UQNhfVv5w xq/+Dv67I8IWKs69JTmr35ErJTCn8Kmnz2f0U5S0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Willem de Bruijn , "Michael S. Tsirkin" , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 0436/1059] virtio-net: fix frag overflow in big packets receive Date: Fri, 4 Dec 2026 18:59:27 +0900 Message-ID: <20261204100655.611709582@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Willem de Bruijn [ Upstream commit b0e4ea3a0cd42eccad9cc4153afcad555480b9e6 ] In big packets mode with guest GSO, add_recvbuf_big() posts a chain of MAX_SKB_FRAGS + 1 pages. page_to_skb() copies only ETH_HLEN of the first page into the linear area and adds the rest of that page as a frag, then one frag per remaining page. A device that fills the entire buffer therefore causes MAX_SKB_FRAGS + 1 frags, writing one skb_frag_t past the end of skb_shinfo(skb)->frags[]. Post one page less. The buffer still fits a maximal GSO packet. A well behaved device does not trigger this, as GSO packets are at most 64KB. Also check the frag count in page_to_skb() before adding any frag as defense in depth. Fixes: 9ab86bbcf8be ("virtio_net: Defer skb allocation in receive path Date: Wed, 13 Jan 2010 12:53:38 -0800") Signed-off-by: Willem de Bruijn Acked-by: Michael S. Tsirkin Link: https://patch.msgid.link/20261020032108.81879-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski [ sashal: Changed the %d in the pr_debug() format string to %lu because MAX_SKB_FRAGS is unsigned long in this tree. ] Signed-off-by: Sasha Levin --- drivers/net/virtio_net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 9773a64c5dba8..09cf03613704f 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -544,6 +544,15 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi, } BUG_ON(offset >= PAGE_SIZE); + + /* The first frag starts at offset, each next frag is a full page. */ + if (unlikely(DIV_ROUND_UP(offset + len, PAGE_SIZE) > MAX_SKB_FRAGS)) { + pr_debug("%s: rx error: len %u needs more than %lu frags\n", + vi->dev->name, len, MAX_SKB_FRAGS); + kfree_skb(skb); + return NULL; + } + while (len) { unsigned int frag_size = min((unsigned)PAGE_SIZE - offset, len); skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, offset, @@ -3833,7 +3842,8 @@ static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu) */ if (mtu > ETH_DATA_LEN || guest_gso) { vi->big_packets = true; - vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS : DIV_ROUND_UP(mtu, PAGE_SIZE); + vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS - 1 : + DIV_ROUND_UP(mtu, PAGE_SIZE); } } -- 2.53.0