From: Hangbin Liu <hangbin.liu@linux.dev>
To: Andrea Mayer <andrea.mayer@uniroma2.it>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>, Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org, bpf@vger.kernel.org,
David Lebrun <david.lebrun@uclouvain.be>,
Daniel Borkmann <daniel@iogearbox.net>,
Mathieu Xhonneux <m.xhonneux@gmail.com>,
David Lebrun <dlebrun@google.com>,
Stefano Salsano <stefano.salsano@uniroma2.it>,
Andrea Mayer <andrea@common-net.org>
Subject: Re: [PATCH net 1/6] seg6: fix skb checksum update helpers
Date: Tue, 3 Nov 2026 09:25:28 +0800 [thread overview]
Message-ID: <auk4COJzzhbGK-3g@fedora> (raw)
In-Reply-To: <20261031225033.64-2-andrea.mayer@uniroma2.it>
On Sat, Oct 31, 2026 at 11:50:28PM +0100, Andrea Mayer wrote:
> With CHECKSUM_COMPLETE, ipv6_srh_rcv() updates skb->csum for the new
> Segments Left and destination address through seg6_update_csum().
> Replacing "from" with "to" in the packet must change skb->csum (C) to
> C - from + to, but update_csum_diff4() and update_csum_diff16() compute:
>
> ~csum_partial({ ~from, to }, ~C) = ~(~C + ~from + to) = C + from - to
>
> This does not affect packets forwarded by ip6_forward(), which sets
> ip_summed to CHECKSUM_NONE. But when the packet is delivered on the same
> node and skb->csum was computed in software, for instance by conntrack, UDP
> can drop the packet as a checksum error. With skb->csum computed by the
> device, TCP can instead log a "hw csum failure", as if the device had
> computed a wrong skb->csum.
>
> Fix update_csum_diff4() and update_csum_diff16() to compute C - from + to.
>
> Found by manual code inspection, while checking that the skb->csum updates
> in the SRv6 receive path are consistent. A following commit adds a selftest
> that reproduces the problem with a tc ct action. The issue was confirmed in
> a VM without kernel changes or error injection: with the rest of this
> series and without this patch, that selftest fails, as UDP drops datagrams
> as checksum errors. Also tested against the srv6 selftests, and with a
> ConnectX-6 Lx NIC (mlx5) that provides CHECKSUM_COMPLETE.
>
> Fixes: 1ababeba4a21 ("ipv6: implement dataplane support for rthdr type 4 (Segment Routing Header)")
> Signed-off-by: Andrea Mayer <andrea.mayer@uniroma2.it>
> ---
> include/net/seg6.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/seg6.h b/include/net/seg6.h
> index 82b3fbbcbb93..01d8034e48fc 100644
> --- a/include/net/seg6.h
> +++ b/include/net/seg6.h
> @@ -19,7 +19,7 @@ static inline void update_csum_diff4(struct sk_buff *skb, __be32 from,
> {
> __be32 diff[] = { ~from, to };
>
> - skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
> + skb->csum = csum_partial(diff, sizeof(diff), skb->csum);
> }
>
> static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from,
> @@ -30,7 +30,7 @@ static inline void update_csum_diff16(struct sk_buff *skb, __be32 *from,
> to[0], to[1], to[2], to[3],
> };
>
> - skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);
> + skb->csum = csum_partial(diff, sizeof(diff), skb->csum);
> }
>
> struct seg6_pernet_data {
> --
> 2.43.0
>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
next prev parent reply other threads:[~2026-11-03 1:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 22:50 [PATCH net 0/6] seg6: fix skb checksum updates with CHECKSUM_COMPLETE Andrea Mayer
2026-10-31 22:50 ` [PATCH net 1/6] seg6: fix skb checksum update helpers Andrea Mayer
2026-11-03 1:25 ` Hangbin Liu [this message]
2026-10-31 22:50 ` [PATCH net 2/6] seg6: update skb checksum when ipv6_srh_rcv() decrements the Hop Limit Andrea Mayer
2026-11-03 1:27 ` Hangbin Liu
2026-10-31 22:50 ` [PATCH net 3/6] seg6: update skb checksum when SRv6 behaviors advance to the next SID Andrea Mayer
2026-11-03 2:15 ` Hangbin Liu
2026-10-31 22:50 ` [PATCH net 4/6] seg6: discard CHECKSUM_COMPLETE after the End.BPF program Andrea Mayer
2026-11-03 2:28 ` Hangbin Liu
2026-10-31 22:50 ` [PATCH net 5/6] seg6: account for the MAC header in skb checksum on L2 encapsulation Andrea Mayer
2026-11-03 2:37 ` Hangbin Liu
2026-10-31 22:50 ` [PATCH net 6/6] selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE Andrea Mayer
2026-11-03 3:26 ` Hangbin Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=auk4COJzzhbGK-3g@fedora \
--to=hangbin.liu@linux.dev \
--cc=andrea.mayer@uniroma2.it \
--cc=andrea@common-net.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=david.lebrun@uclouvain.be \
--cc=dlebrun@google.com \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=m.xhonneux@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=stefano.salsano@uniroma2.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox