]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
udp: gso: Fix handling checksum in __udp_gso_segment
authorAlice Mikityanska <alice@isovalent.com>
Mon, 18 May 2026 06:22:49 +0000 (09:22 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 20 May 2026 22:02:47 +0000 (15:02 -0700)
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")
Signed-off-by: Alice Mikityanska <alice@isovalent.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
Link: https://patch.msgid.link/20260518062250.3019914-2-gal@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/udp_offload.c

index a0813d425b7162367866786f1f5d862d1efdcbf5..2578aa7f9ff9391317866e17306ac022a2ec6d55 100644 (file)
@@ -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)