]> git.itanic.dy.fi Git - linux-stable/commitdiff
seg6: fix skb checksum evaluation in SRH encapsulation/insertion
authorAndrea Mayer <andrea.mayer@uniroma2.it>
Tue, 12 Jul 2022 17:58:35 +0000 (19:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 22 Jul 2022 08:21:42 +0000 (10:21 +0200)
[ Upstream commit df8386d13ea280d55beee1b95f61a59234a3798b ]

Support for SRH encapsulation and insertion was introduced with
commit 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and
injection with lwtunnels"), through the seg6_do_srh_encap() and
seg6_do_srh_inline() functions, respectively.
The former encapsulates the packet in an outer IPv6 header along with
the SRH, while the latter inserts the SRH between the IPv6 header and
the payload. Then, the headers are initialized/updated according to the
operating mode (i.e., encap/inline).
Finally, the skb checksum is calculated to reflect the changes applied
to the headers.

The IPv6 payload length ('payload_len') is not initialized
within seg6_do_srh_{inline,encap}() but is deferred in seg6_do_srh(), i.e.
the caller of seg6_do_srh_{inline,encap}().
However, this operation invalidates the skb checksum, since the
'payload_len' is updated only after the checksum is evaluated.

To solve this issue, the initialization of the IPv6 payload length is
moved from seg6_do_srh() directly into the seg6_do_srh_{inline,encap}()
functions and before the skb checksum update takes place.

Fixes: 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and injection with lwtunnels")
Reported-by: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/all/20220705190727.69d532417be7438b15404ee1@uniroma2.it
Signed-off-by: Andrea Mayer <andrea.mayer@uniroma2.it>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv6/seg6_iptunnel.c

index d64855010948db23eb5ebe5ce0bc4dfff2634afb..e756ba705fd9b4e40bf8a0257b1533a8c51320bc 100644 (file)
@@ -189,6 +189,8 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto)
        }
 #endif
 
+       hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
+
        skb_postpush_rcsum(skb, hdr, tot_len);
 
        return 0;
@@ -241,6 +243,8 @@ int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh)
        }
 #endif
 
+       hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
+
        skb_postpush_rcsum(skb, hdr, sizeof(struct ipv6hdr) + hdrlen);
 
        return 0;
@@ -302,7 +306,6 @@ static int seg6_do_srh(struct sk_buff *skb)
                break;
        }
 
-       ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
        skb_set_transport_header(skb, sizeof(struct ipv6hdr));
        nf_reset_ct(skb);