Skip to contentSkip to conversation

udp: gso: Fix __udp_gso_segment() after GSO_PARTIAL UDP length change

PATCH Applied Gal Pressman 3 participants 7 messages May 18 – May 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover udp: gso: Fix __udp_gso_segment() after GSO_PARTIAL UDP length change

This series fixes two issues introduced by commit b10b446ce7ad ("udp:
gso: Use single MSS length in UDP header for GSO_PARTIAL"), which switched __udp_gso_segment() to write the single MSS length into the UDP header for GSO_PARTIAL skbs.

Patch 1 (from Alice) fixes the UDP checksum adjustment in __udp_gso_segment().
The patch adjusts the checksum by the correct delta, and since msslen and newlen become equivalent before the loop, drops one of the two variables to simplify the code.

Patch 2 handles the case where the last segment of a GSO_PARTIAL skb is itself a GSO skb. This happens when the original packet size is an exact multiple of MSS, so the post-loop segment is not a remainder skb but a full GSO chunk and must also carry the single MSS length in its UDP header.

Changelog -
v1->v2: Took patch #1 from Alice.

	https://lore.kernel.org/all/[email protected]/
	https://lore.kernel.org/all/[email protected]/

Alice Mikityanska (1):
udp: gso: Fix handling checksum in __udp_gso_segment

Gal Pressman (1):
udp: Fix UDP length on last GSO_PARTIAL segment

 net/ipv4/udp_offload.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 1/2 udp: gso: Fix handling checksum in __udp_gso_segment

From: Alice Mikityanska <[email protected]>

The cited commit started using msslen for uh->len, but still uses newlen to adjust uh->check. Although the checksum is ignored in most cases due to the hardware offload, __udp_gso_segment attempts to maintain the correct one. Fix uh->check and adjust it by the right value.

Additionally, after the fix, newlen becomes assigned and unused before the loop. The code can be simplified a bit if mss adjustment is dropped, so that newlen becomes equal to msslen before the loop, and msslen can be also dropped, saving a few lines of code.

This brings us back to one variable, drops an unneeded arithmetic for mss, and fixes the UDP checksum.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL")
---
 net/ipv4/udp_offload.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
net/ipv4/udp_offload.c +2 -11
index a0813d425b71..2578aa7f9ff9 100644
@@ -482,11 +482,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 	struct sock *sk = gso_skb->sk;
 	unsigned int sum_truesize = 0;
 	struct sk_buff *segs, *seg;
-	__be16 newlen, msslen;
 	struct udphdr *uh;
 	unsigned int mss;
 	bool copy_dtor;
 	__sum16 check;
+	__be16 newlen;
 	int ret = 0;
 
 	mss = skb_shinfo(gso_skb)->gso_size;
@@ -555,15 +555,6 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		return segs;
 	}
 
-	msslen = htons(sizeof(*uh) + mss);
-
-	/* GSO partial and frag_list segmentation only requires splitting
-	 * the frame into an MSS multiple and possibly a remainder, both
-	 * cases return a GSO skb. So update the mss now.
-	 */
-	if (skb_is_gso(segs))
-		mss *= skb_shinfo(segs)->gso_segs;
-
 	seg = segs;
 	uh = udp_hdr(seg);
 
@@ -586,7 +577,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		if (!seg->next)
 			break;
 
-		uh->len = msslen;
+		uh->len = newlen;
 		uh->check = check;
 
 		if (seg->ip_summed == CHECKSUM_PARTIAL)
Signature · 1 line
2.52.0
#2 lore raw

PATCH v2 2/2 udp: Fix UDP length on last GSO_PARTIAL segment

In reply to Gal Pressman

Following the cited commit, __udp_gso_segment() writes single MSS length in the UDP header.
The cited patch doesn't account for the fact that the last segment could be a GSO skb by itself. This could happen when the size of the packet is a multiple of MSS, hence the first segment is also the last one (there is no need for a remainder skb).

When the post-loop segment is a GSO skb, assign the single MSS length in the UDP header.

Fixes b10b446ce7ad ("udp: gso: Use single MSS length in UDP header for GSO_PARTIAL")
---
 net/ipv4/udp_offload.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/ipv4/udp_offload.c +6 -3
index 2578aa7f9ff9..815396fe97ad 100644
@@ -590,9 +590,12 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		uh = udp_hdr(seg);
 	}
 
-	/* last packet can be partial gso_size, account for that in checksum */
-	newlen = htons(skb_tail_pointer(seg) - skb_transport_header(seg) +
-		       seg->data_len);
+	if (!skb_is_gso(seg))
+		/* last packet can be partial gso_size, account for that in
+		 * checksum.
+		 */
+		newlen = htons(skb_tail_pointer(seg) -
+			       skb_transport_header(seg) + seg->data_len);
 	check = csum16_add(csum16_sub(uh->check, uh->len), newlen);
 
 	uh->len = newlen;
Signature · 1 line
2.52.0
maintainer
#3 lore raw

Re: [PATCH net v2 2/2] udp: Fix UDP length on last GSO_PARTIAL segment

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 596

Quoted 4 lines · On Mon, 18 May 2026 09:22:50 +0300 Gal Pressman wrote:
net/ipv4/udp_offload.c +4 -0
+	if (!skb_is_gso(seg))
+		/* last packet can be partial gso_size, account for that in
+		 * checksum.
+		 */

No need to repost but I think we should tweak this comment. Saying "partial gso_size" when it such segment is in fact not part of GSO_PARTIAL is a bit confusing. How about:

	/* Unless skb fits perfectly as GSO_PARTIAL, the trailing
	 * segment may not be full MSS, account for that in the checksum
	 */

?

#4 lore raw

Re: [PATCH net v2 2/2] udp: Fix UDP length on last GSO_PARTIAL segment

Quoted 10 lines · Jakub Kicinski

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 596

Quoted 4 lines · On Mon, 18 May 2026 09:22:50 +0300 Gal Pressman wrote:
net/ipv4/udp_offload.c +4 -0
+	if (!skb_is_gso(seg))
+		/* last packet can be partial gso_size, account for that in
+		 * checksum.
+		 */

No need to repost but I think we should tweak this comment. Saying "partial gso_size" when it such segment is in fact not part of GSO_PARTIAL is a bit confusing. How about:

Quoted 5 lines
	/* Unless skb fits perfectly as GSO_PARTIAL, the trailing
	 * segment may not be full MSS, account for that in the checksum
	 */

?

Sounds good, should I submit a patch?

maintainer
#5 lore raw

Re: [PATCH net v2 2/2] udp: Fix UDP length on last GSO_PARTIAL segment

Quoted 11 lines · On Wed, 20 May 2026 19:34:17 +0300 Gal Pressman wrote:
Quoted 10 lines · Jakub Kicinski

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 596

Quoted 4 lines · On Mon, 18 May 2026 09:22:50 +0300 Gal Pressman wrote:
net/ipv4/udp_offload.c +4 -0
+	if (!skb_is_gso(seg))
+		/* last packet can be partial gso_size, account for that in
+		 * checksum.
+		 */  

No need to repost but I think we should tweak this comment. Saying "partial gso_size" when it such segment is in fact not part of GSO_PARTIAL is a bit confusing. How about:

Quoted 7 lines
Quoted 5 lines
	/* Unless skb fits perfectly as GSO_PARTIAL, the trailing
	 * segment may not be full MSS, account for that in the checksum
	 */

?

Sounds good, should I submit a patch?

I'll edit, don't want it to miss the PR

#6 lore raw
In reply to Gal Pressman
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 5 lines · On Mon, 18 May 2026 09:22:48 +0300 you wrote:

This series fixes two issues introduced by commit b10b446ce7ad ("udp:
gso: Use single MSS length in UDP header for GSO_PARTIAL"), which switched __udp_gso_segment() to write the single MSS length into the UDP header for GSO_PARTIAL skbs.

Quoted 7 lines

Patch 1 (from Alice) fixes the UDP checksum adjustment in __udp_gso_segment().
The patch adjusts the checksum by the correct delta, and since msslen and newlen become equivalent before the loop, drops one of the two variables to simplify the code.

[...]

Here is the summary with links:
- [net,v2,1/2] udp: gso: Fix handling checksum in __udp_gso_segment

    https://git.kernel.org/netdev/net/c/5f17ae0f595a
  - [net,v2,2/2] udp: Fix UDP length on last GSO_PARTIAL segment
    https://git.kernel.org/netdev/net/c/78effd896eee

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html