Article View: linux.kernel.netdev
Article #8919[PATCH net v2 2/2] net: gro: invalidate frag0 after a pull
From: Eric Dumazet
Date: Fri, 30 Oct 2026 12:59
Date: Fri, 30 Oct 2026 12:59
129 lines
12556 bytes
12556 bytes
Since commit bd56a29c7a4e ("net: gro: change skb_gro_network_header()"),
skb_gro_header_slow() no longer invalidates NAPI_GRO_CB(skb)->frag0
after pskb_may_pull(). skb_gro_may_pull() keeps comparing against the
frag0_len value set in skb_gro_reset_offset(), assuming that after a
slow pull, all later accesses are beyond frag0_len.
This is not true:
- udp4_gro_receive() and udp6_gro_receive() read the network header
with skb_gro_network_header() after udp_gro_udphdr() pulled the
UDP header.
- vxlan_gro_receive() calls skb_gro_remcsum_cleanup() at a lower
offset after the inner handlers pulled their headers.
- skb_gro_remcsum_process() can pull beyond the inner Ethernet header
before eth_gro_receive() reads it.
- napi_frags_skb() calls __skb_pull(skb, ETH_HLEN) after a slow pull,
so frag0 still points to the Ethernet header.
If the pull consumed the first page fragment, __skb_pull_tail() released
it. If the head had to grow, pskb_expand_head() freed the old one.
These reads, and the 2-byte write in skb_gro_remcsum_cleanup(), then
access memory the skb no longer holds a reference on.
esp4_gro_receive(), esp6_gro_receive(), skb_gro_receive_list() and
udp_gro_receive_segment() also pull directly and never invalidated
frag0.
Add skb_gro_frag0_invalidate(), which only clears frag0_len, and call
it before each of these pulls. This is a single store in the slow path,
and frag0 stays non NULL, so skb_gro_network_header() does not need
a NULL test.
frag0 must be invalidated even if the pull fails: __pskb_pull_tail()
can return NULL after pskb_expand_head() freed the old head, for
instance if a frag_list member has to be cloned or pulled.
Fixes: bd56a29c7a4e ("net: gro: change skb_gro_network_header()")
Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
Cc: stable@vger.kernel.org
Reported-by: Taesoo Kim <tsgatesv@gmail.com>
Reported-by: Cen Zhang <cenzhang@linux.microsoft.com>
Tested-by: Cen Zhang <cenzhang@linux.microsoft.com>
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
include/net/gro.h | 10 ++++++++++
net/core/gro.c | 1 +
net/ipv4/esp4_offload.c | 1 +
net/ipv4/udp_offload.c | 1 +
net/ipv6/esp6_offload.c | 1 +
5 files changed, 14 insertions(+)
diff --git a/include/net/gro.h b/include/net/gro.h
index 00b49b6b9e74..6f6affc8ab91 100644
--- a/include/net/gro.h
+++ b/include/net/gro.h
@@ -160,9 +160,19 @@ static inline bool skb_gro_may_pull(const struct sk_buff *skb,
return likely(hlen <= NAPI_GRO_CB(skb)->frag0_len);
}
+/* A pull can release the page fragment frag0 points to, or reallocate
+ * skb->head, even if it fails. Call this before the pull, to make sure later
+ * skb_gro_header() and skb_gro_network_header() calls no longer use frag0.
+ */
+static inline void skb_gro_frag0_invalidate(struct sk_buff *skb)
+{
+ NAPI_GRO_CB(skb)->frag0_len = 0;
+}
+
static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
unsigned int offset)
{
+ skb_gro_frag0_invalidate(skb);
if (!pskb_may_pull(skb, hlen))
return NULL;
diff --git a/net/core/gro.c b/net/core/gro.c
index 1b033855a20d..bc88652e353a 100644
--- a/net/core/gro.c
+++ b/net/core/gro.c
@@ -238,6 +238,7 @@ int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb)
NAPI_GRO_CB(skb)->flush))
return -E2BIG;
+ skb_gro_frag0_invalidate(skb);
if (!pskb_may_pull(skb, skb_gro_offset(skb))) {
NAPI_GRO_CB(skb)->flush = 1;
return -ENOMEM;
diff --git a/net/ipv4/esp4_offload.c b/net/ipv4/esp4_offload.c
index abd77162f5e7..2309468cfc3d 100644
--- a/net/ipv4/esp4_offload.c
+++ b/net/ipv4/esp4_offload.c
@@ -37,6 +37,7 @@ static struct sk_buff *esp4_gro_receive(struct list_head *head,
__be32 seq;
__be32 spi;
+ skb_gro_frag0_invalidate(skb);
if (!pskb_pull(skb, offset))
return NULL;
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index cf07c3c6611a..cd9d7426b227 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -743,6 +743,7 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
pp = p;
} else {
if (NAPI_GRO_CB(skb)->is_flist) {
+ skb_gro_frag0_invalidate(skb);
if (!pskb_may_pull(skb, skb_gro_offset(skb))) {
NAPI_GRO_CB(skb)->flush = 1;
return NULL;
diff --git a/net/ipv6/esp6_offload.c b/net/ipv6/esp6_offload.c
index 22895521a57d..ca947cb94fb7 100644
--- a/net/ipv6/esp6_offload.c
+++ b/net/ipv6/esp6_offload.c
@@ -64,6 +64,7 @@ static struct sk_buff *esp6_gro_receive(struct list_head *head,
if (NAPI_GRO_CB(skb)->proto == IPPROTO_UDP)
encap_type = UDP_ENCAP_ESPINUDP;
+ skb_gro_frag0_invalidate(skb);
if (!pskb_pull(skb, offset))
return NULL;
--
2.53.0
Technical Details
Message-ID:
<20261030125955.3107383-3-edumazet@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353776-linux-kernel-netdev=dewy.ruReferences:
<20261030125955.3107383-1-edumazet@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353776-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2 2/2] net: gro: invalidate frag0 after a pull Date: Fri, 30 Oct 2026 13:59:55 +0100 Organization: Usenet Network Message-ID: <20261030125955.3107383-3-edumazet@kernel.org> References: <20261030125955.3107383-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2241456"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:r9+8UBJpnlzVFiiCt0/9NI+g3+M= sha256:F2/Bu0pS5QcG9a10mB5N5R791piQYjnRvG2C7sJjRtM= sha1:T04UupNJYpt3+cPQUtFfSW9q+FY= sha256:5SG8WWBPCjzfvLoQd6hBZCYN+N+xrTqjvAQvc/yrDdA= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 188C0125C94; Fri, 30 Oct 2026 16:14:53 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m6sUjfb7km1s; Fri, 30 Oct 2026 16:14:51 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-353776-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id C3DDE125C93; Fri, 30 Oct 2026 16:14:42 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id CC4DE2B73B; Fri, 30 Oct 2026 13:00:15 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793365209; b=Bx25+sKKjdze2noxemdbXiNbduIlZZawfBFB8EtXBsy3HvsuGfEYb5slnAQsenUId6eI b58t/PtQ3VUD8mfiDRuYA/V5wATXRj+dSuh/JuppoR2iu0fE1KNxb66g0buEYWC2yrs3b sCXlL6ZA1+zxVQyxdUqnP5MtaR4PYz+mpM5svohRDGKzRv3wOUnaTParowsYddo6NlqBm 65Lg9bEwcfOxEb42ZTwiOclqHjnj7gocs5UyxLvkok4fAbsWJ3/TIxA7HTvmX92nY32nK Jf06WcdUnceTXD+yMX1t12fsd2Nl7IOsoTfWx0GGulEfcZscD4tgehWhClKdbnrO3vA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793365209; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding; bh=nH54Ozn9lZF+FVBrx7lei5cOZ6E8IORtKLKEiQ1jZr4=; b=49kTwP0nTZ8wMQIBR4gZw2XGseV8bhbUCC4xKLteqzVlWu3cEzmPO0SRAMw0RsJjnfpY 0SYBHd4Q1HNRTI54AhZUuuEvfCqf7CWyxlGWEqk2SchssTeG6Jo32PJ3bAFYrZ8FYK9JA 9VD4yvW62gtygP8M7w7QGNwg3A3WLUG0BK1agVTHxSYE8l94QS1YyRL9keiBcJqgdGxDs DCrHnQojwFHcqJnP4X41Mpm+NcUa/FBhoSau59v8V+8r+1RriKaVyC2xJUlqaKMYHmvoB 0gcbTRaBfSGSq886/GTZ1W+tlg+kV+7DCmynqlm1u01fZqSA2/p/97bWfm6OKetCv0Q== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FYNgY22r; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2FE3606A31C; Fri, 30 Oct 2026 13:00:09 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FYNgY22r X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793365208; b=NjEfEf50stXjboVx+wIEjejasSQkqB2ZnC7RFLOSsKn0jFs9vsWqvXXTUEgBSHWvoWFU TpFZwpJ75wjsmn+DgbclSlU+tcPk5QEPQjDqoBq1rm61aWrc5f/EP6PuPxKBdqJ/MWrTn WM12wNnB3lVuOU1uB/nXseQBxdme9maH80ag07wTuhGTse4KiHrpAdOuo/sA1oHbIjEEq h47RzAB7+ssy1kj1lG20XAZkulS57jkLmVO3FBj8zwSSZa2n+3tL+h4czBuv27b9cs+GN DD+ebqigVzABXhYp0CifBTatzFztOCn2tPd9Ui1rtxc3v+7k5Vo9Hcn66iikjGbyIpw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793365208; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=nH54Ozn9lZF+FVBrx7lei5cOZ6E8IORtKLKEiQ1jZr4=; b=gz+KO86R6UBUZS5tevXaOuYTckJEHFEugdpHXBe1ObqK8kHCVHh6LjPRCLwYhXNZY27g 5PKBvCjct7Ou2nCBb0X2aSUD2Xn5387rt+12azWh0lc5UxEPpsNQ9TPUV9//cEyNyQX8S vZOgwHKHQsIxgaDyZawCBnoxC/WjVcXgDBpZSLdyJEFiKmo4m1nI8KHQ1N01gicKxdGWM WYqrhZoWu5XUjxFkvX1PZIDetjgvsM5iUH0omT5CEYJTPtMBXvRPl/oSEixmFczVhvXey 5bvpKVY2TCtdyFyoumoPuD+/qZSTdq0Q1E+XCICwuYy5Cw5X5c/6ND+f9lp4LuKgOlg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FYNgY22r; arc=none smtp.remote-ip=100.103.45.18 X-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 8280F606A31A; Fri, 30 Oct 2026 13:00:08 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 418DE1F0093A; Fri, 30 Oct 2026 13:00:05 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793365208; bh=nH54Ozn9lZF+FVBrx7lei5cOZ6E8IORtKLKEiQ1jZr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FYNgY22re7rYvE39NgS16wGpTSJosu69m+/0r06rmL1AWbhBKTG40sHuB/xPVYUq3 0xv2m101YAbdNXa2uU5UyYMGBYBe/Vg0y7LXLL8iWpdP3UaSnsUyxj4JC+OSSKL3gz Hwut5cv/G+0rX2HfQruhQpkUHNwa34DmJBhMXVxNAPu3aKBtd0GrNbIveb49uH1v7W nxh31qJQkABaZ7uh14aQq2D/4NWaISfTTzm7wrN9txyyngxZWVeOBOeMGELrxssiOn MKxpgUYcl6/Y4e8IAcG1n/XYsjGCbZQyPvGvaOI/Qbia2gPYchunlSWinBAG7WhIrQ RjOKdBG+tEj2g== X-Cc: Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, edumazet@kernel.org, Willem de Bruijn <willemb@google.com>, Steffen Klassert <steffen.klassert@secunet.com>, Tom Herbert <tom@herbertland.com>, Cen Zhang <cenzhang@linux.microsoft.com>, AutonomousCodeSecurity@microsoft.com, stable@vger.kernel.org, Taesoo Kim <tsgatesv@gmail.com> X-Mailer: git-send-email 2.53.0 X-In-Reply-To: <20261030125955.3107383-1-edumazet@kernel.org> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list