Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/3] net: gso: segment length of encapsulated GSO packets
@ 2026-11-28 16:47 Julius Bairaktaris
  2026-11-28 16:47 ` [PATCH net 1/3] net: gro: set the inner transport header of encapsulated fraglist packets Julius Bairaktaris
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:47 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, horms, willemb,
	willemdebruijn.kernel, ncardwell, kuniyu, alice.kernel, wang.zhan,
	marcelo.leitner, lucien.xin, linux-sctp, dsahern,
	steffen.klassert, nbd

skb_gso_transport_seglen() returns the length of one segment of a GSO
packet, which the MTU checks of IPv4 and IPv6 forwarding and output
compare with the MTU. For an encapsulated packet it counts from the
inner transport header and adds the inner L4 header: fraglist GRO
leaves the inner transport header unset for the inner flow of a tunnel,
and the inner UDP and SCTP headers are not counted.

Patch 1 sets the inner transport header in the fraglist completion of
TCP and UDP GRO, IPv4 and IPv6.
Patch 2 counts the inner UDP header of encapsulated UDP GSO packets.
Patch 3 counts the SCTP header of encapsulated SCTP GSO packets.

Per issue:
- Trigger: patch 1, tunnel traffic from the network (VXLAN, FOU/GUE,
  GRE, IPIP, SIT) forwarded by a host whose ingress has rx-gro-list on;
  patch 2, UDP GSO packets in a UDP tunnel (UDP GRO behind a tunnel
  socket, UDP_SEGMENT over VXLAN) forwarded or sent over a smaller MTU;
  patch 3, SCTP over UDP (net.sctp.udp_port and encap_port set)
  forwarded over a smaller MTU.
- Impact: patch 1, the forwarded aggregates are dropped or their
  segments checked against the MTU with a wrong length; patches 2 and
  3, segments of up to 8 or 12 bytes over the MTU leave whole and are
  lost further on. No memory safety issue. CVSS 3.1: 3.7
  (AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L).
- Until the fix lands: patch 1, ethtool -K <ingress> rx-gro-list off;
  patches 2 and 3, nothing short of the fix.
- Found: by Sashiko reviews of earlier versions of "ipmr: forward GSO
  multicast packets".

Tested in QEMU (KVM) with network namespaces, on net (28a371228d4e):
- VXLAN with an inner UDP or TCP flow over IPv4 or IPv6, outer UDP
  checksum zero or set, rx-gro-list on the router, forwarded unicast
  over a 1400-byte route, 1000 packets per case: net delivers 35 to 195
  per case (2 runs of 12 cases); with this series all 1000 arrive with
  valid outer and inner checksums, also with checksum offload on the
  egress (5 runs, one with KASAN).
- An SCTP association over UDP with a 1500-byte path MTU through a
  router whose egress MTU is 1496 bytes: on net the router hands the
  egress 20 (IPv4) and 28 (IPv6) GSO packets with segments of up to 1500
  bytes (2 runs); with this series none (5 runs, one with KASAN).

Changes since "ipmr: forward GSO multicast packets" v6, whose patches 1
and 3 are patches 1 and 2 here:
- Split out of the ipmr series (Willem de Bruijn).
- Patch 3 (new): count the SCTP header in the encapsulated branch of
  skb_gso_transport_seglen() (Sashiko on v6 patch 3).
- Patches 1 and 2: name the IPv6 users of the segment length in the
  commit message.
- Rebase onto net.
- ipmr v6: https://lore.kernel.org/netdev/cover.1795295554.git.julius@bairaktaris.de/

I used Claude (Anthropic) to help write these patches.

Julius Bairaktaris (3):
  net: gro: set the inner transport header of encapsulated fraglist
    packets
  net: gso: count the inner UDP header of encapsulated UDP GSO packets
  net: gso: count the SCTP header of encapsulated SCTP GSO packets

 net/core/gso.c           | 4 ++++
 net/ipv4/tcp_offload.c   | 3 +++
 net/ipv4/udp_offload.c   | 3 +++
 net/ipv6/tcpv6_offload.c | 3 +++
 net/ipv6/udp_offload.c   | 3 +++
 5 files changed, 16 insertions(+)


base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net 1/3] net: gro: set the inner transport header of encapsulated fraglist packets
  2026-11-28 16:47 [PATCH net 0/3] net: gso: segment length of encapsulated GSO packets Julius Bairaktaris
@ 2026-11-28 16:47 ` Julius Bairaktaris
  2026-11-28 16:47 ` [PATCH net 2/3] net: gso: count the inner UDP header of encapsulated UDP GSO packets Julius Bairaktaris
  2026-11-28 16:47 ` [PATCH net 3/3] net: gso: count the SCTP header of encapsulated SCTP " Julius Bairaktaris
  2 siblings, 0 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:47 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, horms, willemb,
	willemdebruijn.kernel, ncardwell, kuniyu, alice.kernel, wang.zhan,
	marcelo.leitner, lucien.xin, linux-sctp, dsahern,
	steffen.klassert, nbd

The fraglist branches of tcp4_gro_complete() and tcp6_gro_complete()
return before tcp_gro_complete(), and those of udp4_gro_complete() and
udp6_gro_complete() before udp_gro_complete_segment(). Only the latter
two set skb->inner_transport_header when skb->encapsulation is set:
commit d51c5907e980 ("net, gro: Set inner transport header offset in
tcp/udp GRO hook") added it to the regular branches only.

The TCP fraglist branch completes the inner flow of every tunnel that
GRO handles (UDP tunnel sockets, FOU/GUE, GRE, IPIP, SIT, ip6ip6,
ip4ip6): tcp4_check_fraglist_gro() and tcp6_check_fraglist_gro() do not
look at the encapsulation. The UDP one completes the inner flow of a
UDP tunnel socket, whose udp_gro_complete() clears encap_mark, and of
FOU/GUE, which clear it on receive; behind GRE, IPIP and SIT encap_mark
stays set and the aggregate completes through
udp_gro_complete_segment().

Such an aggregate keeps an inner transport header from earlier
processing. skb_gso_transport_seglen() computes the segment length from
it, so the MTU checks of ip_forward(), ip6_forward(),
ip_finish_output_gso() and ip6_finish_output_gso() compare a wrong
length with the MTU; qdisc_pkt_len_segs_init() drops the aggregate with
SKB_DROP_REASON_SKB_BAD_GSO when the offset lies in front of skb->data;
and __skb_udp_tunnel_segment() sets the inner transport header of the
packet it segments from it.

Set the inner transport header in the fraglist branches as well. The
transport header points at the inner TCP or UDP header there, as in
the regular branches.

With rx-gro-list on a virtio-net port of a router with VXLAN sockets,
1000 VXLAN packets per case (outer IPv4, 1400 bytes; inner UDP or TCP
over IPv4 or IPv6; outer UDP checksum zero or set) forwarded unicast
over a 1400-byte route reached the receiver 35 to 195 times per case on
net (2 runs of 12 cases), and 1000 times with this change (5 runs, one
with KASAN).

Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
Fixes: 8d95dc474f85 ("net: add code for TCP fraglist GRO")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
Changes since ipmr v6 1/5:
- Name the IPv6 users of the segment length in the commit message.
- Rebase onto net.
- v6: https://lore.kernel.org/netdev/7b97180d58a027672614af854d79e5639f17d180.1795295554.git.julius@bairaktaris.de/

 net/ipv4/tcp_offload.c   | 3 +++
 net/ipv4/udp_offload.c   | 3 +++
 net/ipv6/tcpv6_offload.c | 3 +++
 net/ipv6/udp_offload.c   | 3 +++
 4 files changed, 12 insertions(+)

diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c
index 7691be01da4d..527313547091 100644
--- a/net/ipv4/tcp_offload.c
+++ b/net/ipv4/tcp_offload.c
@@ -469,6 +469,9 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk_buff *skb, int thoff)
 		skb_shinfo(skb)->gso_type |= SKB_GSO_FRAGLIST | SKB_GSO_TCPV4;
 		skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
 
+		if (skb->encapsulation)
+			skb->inner_transport_header = skb->transport_header;
+
 		__skb_incr_checksum_unnecessary(skb);
 
 		return 0;
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 243bd75302d8..8c77f6f95fb1 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -972,6 +972,9 @@ INDIRECT_CALLABLE_SCOPE int udp4_gro_complete(struct sk_buff *skb, int nhoff)
 		skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4);
 		skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
 
+		if (skb->encapsulation)
+			skb->inner_transport_header = skb->transport_header;
+
 		__skb_incr_checksum_unnecessary(skb);
 
 		return 0;
diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c
index 71feb92aeac2..d1c0b1889d8b 100644
--- a/net/ipv6/tcpv6_offload.c
+++ b/net/ipv6/tcpv6_offload.c
@@ -89,6 +89,9 @@ static __always_inline int tcp6_gro_complete(struct sk_buff *skb, int thoff)
 		skb_shinfo(skb)->gso_type |= SKB_GSO_FRAGLIST | SKB_GSO_TCPV6;
 		skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
 
+		if (skb->encapsulation)
+			skb->inner_transport_header = skb->transport_header;
+
 		__skb_incr_checksum_unnecessary(skb);
 
 		return 0;
diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c
index 7370bcb80332..79346fc17df5 100644
--- a/net/ipv6/udp_offload.c
+++ b/net/ipv6/udp_offload.c
@@ -176,6 +176,9 @@ int udp6_gro_complete(struct sk_buff *skb, int nhoff)
 		skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4);
 		skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
 
+		if (skb->encapsulation)
+			skb->inner_transport_header = skb->transport_header;
+
 		__skb_incr_checksum_unnecessary(skb);
 
 		return 0;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net 2/3] net: gso: count the inner UDP header of encapsulated UDP GSO packets
  2026-11-28 16:47 [PATCH net 0/3] net: gso: segment length of encapsulated GSO packets Julius Bairaktaris
  2026-11-28 16:47 ` [PATCH net 1/3] net: gro: set the inner transport header of encapsulated fraglist packets Julius Bairaktaris
@ 2026-11-28 16:47 ` Julius Bairaktaris
  2026-11-28 16:47 ` [PATCH net 3/3] net: gso: count the SCTP header of encapsulated SCTP " Julius Bairaktaris
  2 siblings, 0 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:47 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, horms, willemb,
	willemdebruijn.kernel, ncardwell, kuniyu, alice.kernel, wang.zhan,
	marcelo.leitner, lucien.xin, linux-sctp, dsahern,
	steffen.klassert, nbd

skb_gso_transport_seglen() adds the inner TCP header length for an
encapsulated GSO packet, but not the inner UDP header for
SKB_GSO_UDP_L4, whose gso_size covers the payload only. Every segment
of a UDP GSO packet in a UDP tunnel, built by UDP GRO behind a tunnel
socket or sent with UDP_SEGMENT over VXLAN, is counted 8 bytes short.
The MTU checks of ip_forward(), ip6_forward(), ip_finish_output_gso() and
ip6_finish_output_gso() then let segments that exceed the MTU by up to
8 bytes leave whole.

Add the inner UDP header as the unencapsulated branch does.

Fixes: ee80d1ebe5ba ("udp: add udp gso")
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
Changes since ipmr v6 3/5:
- Name the IPv6 users of the segment length in the commit message.
- Rebase onto net.
- v6: https://lore.kernel.org/netdev/25682585bdc914eaba2f9c5ee7473722bb2ddc10.1795295554.git.julius@bairaktaris.de/

 net/core/gso.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/gso.c b/net/core/gso.c
index b5bd269e56e4..eb95c9d2819b 100644
--- a/net/core/gso.c
+++ b/net/core/gso.c
@@ -156,6 +156,8 @@ static unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
 
 		if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
 			thlen += inner_tcp_hdrlen(skb);
+		else if (shinfo->gso_type & SKB_GSO_UDP_L4)
+			thlen += sizeof(struct udphdr);
 	} else if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) {
 		thlen = tcp_hdrlen(skb);
 	} else if (unlikely(skb_is_gso_sctp(skb))) {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net 3/3] net: gso: count the SCTP header of encapsulated SCTP GSO packets
  2026-11-28 16:47 [PATCH net 0/3] net: gso: segment length of encapsulated GSO packets Julius Bairaktaris
  2026-11-28 16:47 ` [PATCH net 1/3] net: gro: set the inner transport header of encapsulated fraglist packets Julius Bairaktaris
  2026-11-28 16:47 ` [PATCH net 2/3] net: gso: count the inner UDP header of encapsulated UDP GSO packets Julius Bairaktaris
@ 2026-11-28 16:47 ` Julius Bairaktaris
  2 siblings, 0 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-28 16:47 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, horms, willemb,
	willemdebruijn.kernel, ncardwell, kuniyu, alice.kernel, wang.zhan,
	marcelo.leitner, lucien.xin, linux-sctp, dsahern,
	steffen.klassert, nbd

skb_gso_transport_seglen() adds the SCTP common header for an SCTP GSO
packet only in its unencapsulated branch. SCTP over UDP (RFC 6951)
sends its GSO packets encapsulated: sctp_v4_xmit() and sctp_v6_xmit()
add SKB_GSO_UDP_TUNNEL_CSUM and set skb->encapsulation and the inner
transport header at the SCTP header. The encapsulated branch then
counts only the outer UDP header, and skb_gso_size_check() adds the
length of each frag_list member, which holds the chunks of one segment:
every segment is counted 12 bytes short. The MTU checks of ip_forward(),
ip6_forward(), ip_finish_output_gso() and ip6_finish_output_gso() then
let segments that exceed the MTU by up to 12 bytes leave whole.

Add the SCTP header in the encapsulated branch as well.

An SCTP association over UDP with a 1500-byte path MTU, forwarded by a
router whose egress has a 1496-byte MTU (QEMU, network namespaces): on
net the router hands the egress 20 (IPv4) and 28 (IPv6) GSO packets
with segments of up to 1500 bytes, in each of 2 runs; with this change
none, and it counts the packets it refuses in FragFails and
Ip6InTooBigErrors (5 runs, one with KASAN).

The missing case was pointed out by the Sashiko review of the inner
UDP header fix.

Fixes: 600af7fd809a ("sctp: support for sending packet over udp4 sock")
Fixes: 259db53ba593 ("sctp: support for sending packet over udp6 sock")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
New: Sashiko on ipmr v6 3/5.

 net/core/gso.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/gso.c b/net/core/gso.c
index eb95c9d2819b..d62ced6f74f2 100644
--- a/net/core/gso.c
+++ b/net/core/gso.c
@@ -158,6 +158,8 @@ static unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
 			thlen += inner_tcp_hdrlen(skb);
 		else if (shinfo->gso_type & SKB_GSO_UDP_L4)
 			thlen += sizeof(struct udphdr);
+		else if (unlikely(skb_is_gso_sctp(skb)))
+			thlen += sizeof(struct sctphdr);
 	} else if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) {
 		thlen = tcp_hdrlen(skb);
 	} else if (unlikely(skb_is_gso_sctp(skb))) {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-28 16:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 16:47 [PATCH net 0/3] net: gso: segment length of encapsulated GSO packets Julius Bairaktaris
2026-11-28 16:47 ` [PATCH net 1/3] net: gro: set the inner transport header of encapsulated fraglist packets Julius Bairaktaris
2026-11-28 16:47 ` [PATCH net 2/3] net: gso: count the inner UDP header of encapsulated UDP GSO packets Julius Bairaktaris
2026-11-28 16:47 ` [PATCH net 3/3] net: gso: count the SCTP header of encapsulated SCTP " Julius Bairaktaris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox