All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, edumazet@kernel.org,
	pabeni@redhat.com, horms@kernel.org,
	Willem de Bruijn <willemb@google.com>,
	stable@vger.kernel.org, Hassan Sultan <hassansultan@google.com>
Subject: [PATCH net v2 2/2] net: gso: fall back to skb_segment when fraglist cannot satisfy checksum
Date: Thu, 19 Nov 2026 23:46:40 -0500	[thread overview]
Message-ID: <20261120044733.222627-3-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20261120044733.222627-1-willemdebruijn.kernel@gmail.com>

From: Willem de Bruijn <willemb@google.com>

skb_segment_list() keeps the original headers and checksum state of the
frag_list members. It ignores the checksum features and does not set up
the SKB_GSO_CB() checksum state. This breaks:

1. Outer tunnel checksums. __skb_udp_tunnel_segment() and
   gre_gso_segment() compute these with gso_make_checksum(), which
   reads stale SKB_GSO_CB() state, and needs an inner payload sum that
   skb_segment_list() does not compute.

2. CHECKSUM_PARTIAL packets, e.g., from veth or tun, sent to a device
   without checksum offload. Unlike skb_segment(), skb_segment_list()
   does not resolve these.

Extend the existing fallback to skb_segment() for modified geometry and
SKB_GSO_DODGY, from
commit 17bd3bd82f9f ("net: gso: fix tcp fraglist segmentation after pull
from frag_list"), to when:

- skb_tnl_header_len() is non-zero: UDP, GRE and MPLS tunnels (case 1).
- the features cannot checksum a CHECKSUM_PARTIAL packet (case 2).
- skb->encapsulation is set: encapsulations not seen by
  skb_tnl_header_len(). For example, ESP with xfrm offload in transport
  mode, as skb_segment_list() does not copy the ESP header and IV to
  the frag_list members. IPIP and SIT are excluded too, for simplicity.

Share this test between TCP and UDP in skb_gso_fraglist_ok().

This moves some correctly handled tunnel traffic to the slower
skb_segment(). Fraglist GRO is off by default.

Discovered through analysis by an LLM. Reproduced on an unmodified
kernel and verified with LLM-generated reproducers in virtme-ng.

Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
Fixes: bee88cd5bd83 ("net: add support for segmenting TCP fraglist GSO packets")
Cc: stable@vger.kernel.org
Reported-by: Hassan Sultan <hassansultan@google.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 include/net/gso.h        | 33 +++++++++++++++++++++++++++++++++
 net/ipv4/tcp_offload.c   |  5 ++---
 net/ipv4/udp_offload.c   |  5 +++--
 net/ipv6/tcpv6_offload.c |  6 +++---
 4 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/include/net/gso.h b/include/net/gso.h
index 119fc4c170e1..6cf6a6dee234 100644
--- a/include/net/gso.h
+++ b/include/net/gso.h
@@ -3,6 +3,7 @@
 #ifndef _NET_GSO_H
 #define _NET_GSO_H
 
+#include <linux/netdevice.h>
 #include <linux/skbuff.h>
 
 /* Keeps track of mac header offset relative to skb->head.
@@ -39,6 +40,38 @@ static inline int skb_tnl_header_len(const struct sk_buff *inner_skb)
 		SKB_GSO_CB(inner_skb)->mac_offset;
 }
 
+/**
+ * skb_gso_fraglist_ok - test whether skb_segment_list() can segment an skb
+ * @skb: SKB_GSO_FRAGLIST skb to segment
+ * @features: features for the output path
+ * @hdrlen: transport header length
+ * @proto: network protocol, for checksum offload
+ *
+ * Return: false if the skb must be passed to the more general skb_segment().
+ */
+static inline bool skb_gso_fraglist_ok(const struct sk_buff *skb,
+				       netdev_features_t features,
+				       unsigned int hdrlen, __be16 proto)
+{
+	/* Geometry modified, e.g., by a pull from frag_list */
+	if (skb_pagelen(skb) - hdrlen != skb_shinfo(skb)->gso_size)
+		return false;
+
+	if (skb_shinfo(skb)->gso_type & SKB_GSO_DODGY)
+		return false;
+
+	/* Tunnel headers and outer checksums are not rebuilt */
+	if (skb->encapsulation || skb_tnl_header_len(skb))
+		return false;
+
+	/* Checksums are not resolved in software */
+	if (skb->ip_summed == CHECKSUM_PARTIAL &&
+	    !can_checksum_protocol(features, proto))
+		return false;
+
+	return true;
+}
+
 static inline int gso_pskb_expand_head(struct sk_buff *skb, int extra)
 {
 	int new_headroom, headroom;
diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c
index 520778c5ca7f..7691be01da4d 100644
--- a/net/ipv4/tcp_offload.c
+++ b/net/ipv4/tcp_offload.c
@@ -105,11 +105,10 @@ static struct sk_buff *tcp4_gso_segment(struct sk_buff *skb,
 		return ERR_PTR(-EINVAL);
 
 	if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST) {
-		struct tcphdr *th = tcp_hdr(skb);
 		int err;
 
-		if ((skb_pagelen(skb) - th->doff * 4 == skb_shinfo(skb)->gso_size) &&
-		    !(skb_shinfo(skb)->gso_type & SKB_GSO_DODGY))
+		if (skb_gso_fraglist_ok(skb, features, tcp_hdrlen(skb),
+					htons(ETH_P_IP)))
 			return __tcp4_gso_segment_list(skb, features);
 
 		err = skb_cow_head(skb, 0);
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index b77ae2f00c62..243bd75302d8 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -519,8 +519,9 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		 * the frag_list skbs still have the IP family we segment for,
 		 * as their network headers are not rebuilt.
 		 */
-		if ((skb_pagelen(gso_skb) - sizeof(*uh) == skb_shinfo(gso_skb)->gso_size) &&
-		    !(skb_shinfo(gso_skb)->gso_type & SKB_GSO_DODGY) &&
+		if (skb_gso_fraglist_ok(gso_skb, features, sizeof(*uh),
+					is_ipv6 ? htons(ETH_P_IPV6) :
+						  htons(ETH_P_IP)) &&
 		    ip_hdr(skb_shinfo(gso_skb)->frag_list)->version == (is_ipv6 ? 6 : 4))
 			return __udp_gso_segment_list(gso_skb, features, is_ipv6);
 
diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c
index 0914f95f100c..71feb92aeac2 100644
--- a/net/ipv6/tcpv6_offload.c
+++ b/net/ipv6/tcpv6_offload.c
@@ -9,6 +9,7 @@
 #include <linux/skbuff.h>
 #include <net/inet6_hashtables.h>
 #include <net/gro.h>
+#include <net/gso.h>
 #include <net/protocol.h>
 #include <net/tcp.h>
 #include <net/ip6_checksum.h>
@@ -177,11 +178,10 @@ static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
 		return ERR_PTR(-EINVAL);
 
 	if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST) {
-		struct tcphdr *th = tcp_hdr(skb);
 		int err;
 
-		if ((skb_pagelen(skb) - th->doff * 4 == skb_shinfo(skb)->gso_size) &&
-		    !(skb_shinfo(skb)->gso_type & SKB_GSO_DODGY))
+		if (skb_gso_fraglist_ok(skb, features, tcp_hdrlen(skb),
+					htons(ETH_P_IPV6)))
 			return __tcp6_gso_segment_list(skb, features);
 
 		err = skb_cow_head(skb, 0);
-- 
2.56.1.750.gf70dc682cf-goog


      parent reply	other threads:[~2026-11-20  4:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  4:46 [PATCH net v2 0/2] net: gso: fraglist segmentation fixes Willem de Bruijn
2026-11-20  4:46 ` [PATCH net v2 1/2] net: gso: cow head on tcp fraglist fallback to skb_segment Willem de Bruijn
2026-11-20  4:46 ` Willem de Bruijn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120044733.222627-3-willemdebruijn.kernel@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hassansultan@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.