Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by Willem de Bruijn
Fri, 20 Nov 2026 04:46
[PATCH net v2 0/2] net: gso: fraglist segmentation fixes
Author: Willem de Bruijn
Date: Fri, 20 Nov 2026 04:46
Date: Fri, 20 Nov 2026 04:46
65 lines
13150 bytes
13150 bytes
From: Willem de Bruijn <willemb@google.com>
Fix two issues when segmenting SKB_GSO_FRAGLIST packets.
Patch 1 unshares the head before the TCP fallback to skb_segment()
rewrites the TCP checksum field.
Patch 2 falls back to skb_segment() in more cases where
skb_segment_list() produces incorrect checksums: tunnels with outer
checksums, and CHECKSUM_PARTIAL packets sent to a device without
checksum offload.
Testing
Tested in virtme-ng. A sender injects TCP and UDP GSO packets (20
packets of 20 segments of 1000B) over a veth with TSO disabled. The
peer veth has GRO and rx-gro-list enabled, and forwards the fraglist
skbs to a tap device without offloads, in three ways:
- routed
- routed into a vxlan device with udpcsum, over the tap
- bridged
Each for IPv4 and IPv6, and with sender checksum offload enabled
(CHECKSUM_PARTIAL) and disabled (complete checksums): 24 cases.
A reader on the tap verifies the IP, TCP and UDP checksums of every
segment, including inside vxlan. For TCP, a packet socket on the
ingress veth holds clones of the GRO packets, and checks whether their
TCP checksum field was modified in place.
- net/main: 14 of 24 cases fail.
CHECKSUM_PARTIAL to the tap has incorrect L4 checksums, routed and
bridged. Vxlan has incorrect outer UDP checksums: with IPv6 inner
packets always, with IPv4 inner packets only with CHECKSUM_PARTIAL.
- This series without the skb_cow_head() of patch 1: the bridged TCP
CHECKSUM_PARTIAL cases, IPv4 and IPv6, modify all clones. Routed
cases are not affected, as ip_forward() unshares the head.
- This series: all 24 cases pass.
Changes
v1 -> v2
- new patch 1/2
- patch 2/2: move the test into helper skb_gso_fraglist_ok()
- patch 2/2: rebase onto commit 22b7cb932c6a ("udp: check frag_list
IP family before using skb_segment_list()")
- patch 2/2: commit message: explain the skb->encapsulation test,
reference the existing skb_segment() fallback, drop the claim that
skb_segment() is always safe
v1: https://lore.kernel.org/netdev/20261111221129.829218-1-willemdebruijn.kernel@gmail.com/
Willem de Bruijn (2):
net: gso: cow head on tcp fraglist fallback to skb_segment
net: gso: fall back to skb_segment when fraglist cannot satisfy
checksum
include/net/gso.h | 33 +++++++++++++++++++++++++++++++++
net/ipv4/tcp_offload.c | 10 +++++++---
net/ipv4/udp_offload.c | 5 +++--
net/ipv6/tcpv6_offload.c | 11 ++++++++---
4 files changed, 51 insertions(+), 8 deletions(-)
--
2.56.1.750.gf70dc682cf-goog
[PATCH net v2 1/2] net: gso: cow head on tcp fraglist fallback to skb_segment
Author: Willem de Bruijn
Date: Fri, 20 Nov 2026 04:46
Date: Fri, 20 Nov 2026 04:46
70 lines
13287 bytes
13287 bytes
From: Willem de Bruijn <willemb@google.com>
When tcp4_gso_segment() or tcp6_gso_segment() cannot use
skb_segment_list(), they fall back to tcp_gso_segment(), first resetting
th->check to the pseudo-header sum. This writes to skb->head without
unsharing it. If the skb is cloned, e.g., by a packet socket on a bridge
port, the other holders see the rewritten checksum.
Call skb_cow_head(), like skb_segment_list() and the UDP fallback
already unshare the head with skb_unclone() and __skb_linearize().
skb_header_cloned() is equivalent to skb_cloned() here, as GRO does not
set nohdr on the head of fraglist skbs.
Discovered by an AI code review agent. Reproduced on an unmodified
kernel with bridged veth devices and an AF_PACKET socket, and verified
in virtme-ng.
Fixes: 17bd3bd82f9f ("net: gso: fix tcp fraglist segmentation after pull from frag_list")
Cc: stable@vger.kernel.org
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
net/ipv4/tcp_offload.c | 5 +++++
net/ipv6/tcpv6_offload.c | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c
index b84fcd07c723..520778c5ca7f 100644
--- a/net/ipv4/tcp_offload.c
+++ b/net/ipv4/tcp_offload.c
@@ -106,11 +106,16 @@ static struct sk_buff *tcp4_gso_segment(struct sk_buff *skb,
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))
return __tcp4_gso_segment_list(skb, features);
+ err = skb_cow_head(skb, 0);
+ if (err < 0)
+ return ERR_PTR(err);
+
skb->ip_summed = CHECKSUM_NONE;
}
diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c
index eec3778855eb..0914f95f100c 100644
--- a/net/ipv6/tcpv6_offload.c
+++ b/net/ipv6/tcpv6_offload.c
@@ -178,11 +178,16 @@ static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
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))
return __tcp6_gso_segment_list(skb, features);
+ err = skb_cow_head(skb, 0);
+ if (err < 0)
+ return ERR_PTR(err);
+
skb->ip_summed = CHECKSUM_NONE;
}
--
2.56.1.750.gf70dc682cf-goog
[PATCH net v2 2/2] net: gso: fall back to skb_segment when fraglist cannot satisfy checksum
Author: Willem de Bruijn
Date: Fri, 20 Nov 2026 04:46
Date: Fri, 20 Nov 2026 04:46
161 lines
17030 bytes
17030 bytes
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
Re: [PATCH net v2 2/2] net: gso: fall back to skb_segment when fraglist cannot satisfy checksum
Author: Willem de Bruijn
Date: Tue, 24 Nov 2026 00:55
Date: Tue, 24 Nov 2026 00:55
177 lines
18501 bytes
18501 bytes
Julius Bairaktaris wrote:
> Willem de Bruijn wrote:
> > 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.
>
> Patch 2/5 of my "ipmr: forward GSO multicast packets" v6 changes the
> same three conditions for this case. With this series on net, the case
> from 2/5 (TCP from a local udpcsum VXLAN device, CHECKSUM_PARTIAL
> aggregates, forwarded with rx-gro-list on) leaves no wrong outer
> checksum, 3 of 3 cases in 2 runs, so 2/5 is not needed on top of it.
> The other four patches apply unchanged on top of this series.
>
> https://lore.kernel.org/netdev/cover.1795295554.git.julius@bairaktaris.de/
Good catch.
> > + /* Tunnel headers and outer checksums are not rebuilt */
> > + if (skb->encapsulation || skb_tnl_header_len(skb))
> > + return false;
>
> 1/5 is still needed: the fraglist branches of
> tcp4/tcp6/udp4/udp6_gro_complete() leave inner_transport_header unset
> for qdisc_pkt_len_segs_init() and skb_gso_transport_seglen(). VXLAN
> forwarded with rx-gro-list on, 20 cases of 1000 packets, 2 runs: 34 to
> 241 reach the receiver with this series, and with 1/5 and 3/5-5/5 on
> top every packet the router received, with valid checksums.
>
> Is v7 without 2/5, based on net once this series is applied, how you
> want the two combined?
How about splitting into two series.
One that is not ipmr specific: patches 1 and 3. That is ready to be
merged I expect without major comments.
A few comments to Patch 4:
> @@ -1948,6 +1952,15 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt,
> if (vif->flags & VIFF_TUNNEL) {
> + /* An encapsulated packet carries the inner headers of its
> + * own tunnel. Only IPXIP4 GSO packets nest: their IP headers
> + * are segmented by protocol field, while GRE and UDP tunnel
> + * segmentation read skb->inner_protocol, which ip_encap()
> + * sets for its own header.
> + */
> + if (skb_is_gso(skb) && skb->encapsulation &&
> + !(skb_shinfo(skb)->gso_type & SKB_GSO_IPXIP4))
> + return -1;
[severity: high, confidence: high]
Checking only !(gso_type & SKB_GSO_IPXIP4) lets compound tunnels with
SKB_GSO_IPXIP4 set slip through: FOU/GUE over IPIP/SIT (both from GRO via
udp_gro_complete() -> {ipip,sit}_gro_complete() and local ipip/sit devices
with encap fou/gue) carry SKB_GSO_UDP_TUNNEL[_CSUM] | SKB_GSO_IPXIP4 (and
esp4_offload.c can combine SKB_GSO_ESP | SKB_GSO_IPXIP4). ip_encap() then
unconditionally overwrites skb->inner_protocol_type and skb->inner_ipproto
to IPPROTO_IPIP, so skb_udp_tunnel_segment() dispatches SIT-over-FOU/GUE to
ipip_gso_segment() on an IPv6 header, dropping/corrupting it after vif stats
already counted it.
The hidden assumption is that SKB_GSO_IPXIP4 is mutually exclusive with SKB_GSO_UDP_TUNNEL[_CSUM]. It isn't: FOU and GUE wrap IP-in-IP /
SIT inside UDP, so a single skb carries both SKB_GSO_UDP_TUNNEL[_CSUM] and SKB_GSO_IPXIP4 in skb_shinfo(skb)->gso_type.
The check tests the wrong sense of the bitmask: it asks "is IPXIP4 present?" rather than "are any non-IPXIP4 tunnel bits present?"
Admittedly double encap is a bit niche. But something a fuzzer will find. I'd lower the severity to medium though.
[severity: high, confidence: high]
Even for pure SKB_GSO_IPXIP4 (IPIP/SIT without FOU/GUE), pushing a third IP
header without segmenting first breaks the invariant enforced by real ipip
devices (IPIP_FEATURES omits NETIF_F_GSO_ENCAP_ALL and hw_enc_features is 0,
so validate_xmit_skb() segments any encapsulated GSO skb before ipip_tunnel_xmit()).
NICs advertising full NETIF_F_GSO_IPXIP4 offload (i40e, ice, iavf, ionic)
take the 3-header skb directly and only update skb_network_header() and
skb_inner_network_header(), leaving the middle IPv4 header with the full
aggregate tot_len and static id on every segment (and patch 5 widens this
from DF=0 to DF=1 traffic). GSO_PARTIAL NICs (mlx5, bnxt, ixgbe, igb, igc)
also replicate the middle header with a fixed id even when DF is clear.
Either drop all skb_is_gso(skb) && skb->encapsulation here (as in v5) or
segment already-encapsulated GSO skbs before ip_encap().
struct sk_buff only has two sets of header pointers: outer (network_header, transport_header) and inner (inner_network_header,
inner_transport_header). Every hardware TSO driver and NIC descriptor format is built around that 2-layer model.
Normal ipip tunnel devices enforce this automatically. ipip_tunnel_setup:403-422 advertises NETIF_F_GSO_SOFTWARE (which excludes
NETIF_F_GSO_ENCAP_ALL) and leaves dev->hw_enc_features = 0. When an already-encapsulated GSO skb (skb->encapsulation == 1) is transmitted
to tunl0, __netif_skb_features:3998-3999 masks features with dev->hw_enc_features (0), so validate_xmit_skb() segments it first before
ipip_tunnel_xmit() pushes the second IP header.
VIFF_TUNNEL bypasses dev_queue_xmit() on dvmrp%d and calls ip_encap() directly inside ipmr_prepare_xmit(), so nothing segments an incoming
IPIP/SIT GSO skb before ip_encap() wraps it in another IPv4 header.
The root tension is that v6 added && !(gso_type & SKB_GSO_IPXIP4) solely to appease a review comment on v5 about preserving pre-existing
DF=0 software-GSO IPIP/SIT behavior, but doing so violates the kernel's 2-layer GSO invariant and creates both Issue #1 and Issue #2.
There are two clean ways out:
1. Minimal net fix (revert to v5): if (skb_is_gso(skb) && skb->encapsulation) return -1; — drops all already-encapsulated GSO skbs on
VIFF_TUNNEL in one line, avoids illegal 3-IP-header GSO skbs completely, and eliminates both Issue #1 and Issue #2.
2. Full fix (matching ipip netdev semantics): Segment already-encapsulated GSO skbs (skb_gso_segment(skb, 0) / software GSO) before calling
ip_encap() in ipmr_queue_{fwd,output}_xmit() — then all encapsulated GSO traffic (IPIP, SIT, GRE, VXLAN, FOU/GUE) works over VIFF_TUNNEL on
both software and hardware TSO NICs, with zero drops and zero 3-header skbs (though slightly more invasive for net).
> @@ -1982,6 +1995,17 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt,
> + if ((vif->flags & VIFF_TUNNEL) && skb->encapsulation &&
> + !skb_is_gso(skb) && skb->ip_summed == CHECKSUM_PARTIAL &&
> + skb_checksum_help(skb)) {
> + ip_rt_put(rt);
> + return -1;
> + }
[severity: medium, confidence: high]
A unicast SCTP packet inside VXLAN/GRE/IPIP with a multicast outer
destination can reach here with skb->encapsulation && CHECKSUM_PARTIAL &&
skb->csum_not_inet (unlike unencapsulated multicast SCTP). skb_checksum_help()
writes a 16-bit 1's-complement checksum over the first 2 bytes of the 4-byte
SCTP CRC32c field. Use skb_csum_hwoffload_help(skb, 0) instead, matching
validate_xmit_skb() on an ipip device.
Re: [PATCH net v2 0/2] net: gso: fraglist segmentation fixes
Author: patchwork-bot+netdevbpf
Date: Tue, 24 Nov 2026 15:20
Date: Tue, 24 Nov 2026 15:20
26 lines
8637 bytes
8637 bytes
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Thu, 19 Nov 2026 23:46:38 -0500 you wrote:
> From: Willem de Bruijn <willemb@google.com>
>
> Fix two issues when segmenting SKB_GSO_FRAGLIST packets.
>
> Patch 1 unshares the head before the TCP fallback to skb_segment()
> rewrites the TCP checksum field.
>
> [...]
Here is the summary with links:
- [net,v2,1/2] net: gso: cow head on tcp fraglist fallback to skb_segment
https://git.kernel.org/netdev/net/c/3f137feaad8e
- [net,v2,2/2] net: gso: fall back to skb_segment when fraglist cannot satisfy checksum
https://git.kernel.org/netdev/net/c/ab5b219a7340
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads