Article View: linux.kernel.netdev
Article #26845Re: [PATCH v4 1/2] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 09:43
Date: Fri, 04 Dec 2026 09:43
211 lines
16451 bytes
16451 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch fixes one caller, nf_nat's __udp_manip_pkt()
(net/netfilter/nf_nat_proto.c:75-88).
- [Low] The new comment in __udp_manip_pkt()
(net/netfilter/nf_nat_proto.c:57-74) presents the offload-target test…
- [Low] netfilter: nf_nat: Fixes trailer cites refactoring commit
faec18dbb0405
--
netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets
This patch changes __udp_manip_pkt() to detect when the outer UDP check
field is not the CHECKSUM_PARTIAL offload target. That is the state
udp_set_csum() leaves behind on its LCO branch. In that case ip_summed
is set to CHECKSUM_NONE for the duration of the address and port
checksum updates, so that the complete checksum is adjusted with
csum_replace*().
> diff --git a/net/netfilter/nf_nat_proto.c b/net/netfilter/nf_nat_proto.c
> index 64b9bac228eae..6779e9f2812d9 100644
> --- a/net/netfilter/nf_nat_proto.c
> +++ b/net/netfilter/nf_nat_proto.c
> @@ -54,9 +54,39 @@ __udp_manip_pkt(struct sk_buff *skb,
> portptr = &hdr->dest;
> }
> if (do_csum) {
> + /* When udp_set_csum() takes the LCO branch (encapsulated
> + * CHECKSUM_PARTIAL, non-GSO), uh->check holds a complete
> + * (folded and complemented) checksum while csum_start
> + * points at the inner transport header, not at this outer
> + * udphdr. In that state:
> + * - nf_csum_update() -> inet_proto_csum_replace4(pseudohdr=true)
> + * takes the pseudo-header branch and applies the address
> + * delta with the wrong sign (to an uncomplemented seed).
> + * - inet_proto_csum_replace2(pseudohdr=false) is a no-op:
> + * neither branch is taken for CHECKSUM_PARTIAL when
> + * pseudohdr is false.
> + * Temporarily flip ip_summed so both use the csum_replace*()
> + * path that correctly updates the complete checksum.
> + *
> + * The seed/offload branch of udp_set_csum() sets csum_start
> + * to the outer UDP header, so the offload-target test
> + * below distinguishes the two states.
> + */
> + bool lco = skb->ip_summed == CHECKSUM_PARTIAL &&
> + !skb_is_gso(skb) &&
> + (skb->head + skb->csum_start + skb->csum_offset) !=
> + (unsigned char *)&hdr->check;
[Severity: Low]
The Fixes tag points at faec18dbb0405 ("netfilter: nat: remove
l4proto->manip_pkt"). As far as I can tell, that commit only moved
__udp_manip_pkt() from net/netfilter/nf_nat_proto_udp.c into
nf_nat_proto.c. The checksum handling came across unchanged: the l3
csum_update followed by inet_proto_csum_replace2(..., false). So it
didn't introduce the problem described here.
The state this patch has to handle is a complete outer UDP checksum in
uh->check, while ip_summed stays CHECKSUM_PARTIAL with csum_start on
the inner transport header. That state is created by the LCO branch of
udp_set_csum() and udp6_set_csum(). That branch, and lco_csum(), came
in with 179bc67f69b6 ("net: local checksum offload for
encapsulation").
As far as I can see, before that commit both helpers hit a BUG_ON() for
non-GSO CHECKSUM_PARTIAL skbs. So __udp_manip_pkt() could never see an
outer UDP header in this state.
Should the tag be the following instead?
Fixes: 179bc67f69b6 ("net: local checksum offload for encapsulation")
Or did you have a specific reason to blame the refactoring commit?
This doesn't affect the code. However, stable tooling and backporters
use the Fixes tag to decide where the patch applies. Pointing at a file
rename suggests the bug started there, and hides that older trees would
need the fix adapted to nf_nat_proto_udp.c.
While at it, the hash is 13 characters. The usual form is the first 12.
[Severity: Low]
This isn't a bug, but the comment says the offload-target test tells
apart udp_set_csum()'s LCO branch and its seed/offload branch. The
condition is broader than that. It matches any UDP header whose check
field is not the CHECKSUM_PARTIAL target, including skbs that
udp_set_csum() never touched.
For example, nf_nat_icmp_reply_translation() reaches __udp_manip_pkt()
for the UDP header inside an ICMP error:
if (!nf_nat_ipv4_manip_pkt(skb, hdrlen + sizeof(inside->icmp),
&ct->tuplehash[!dir].tuple, !manip))
Suppose that skb is CHECKSUM_PARTIAL with the target on the ICMP
checksum, for example one injected through virtio_net_hdr with
NEEDS_CSUM. Then lco is now true, and the embedded UDP checksum is
updated as a complete checksum.
That new behavior is correct, but neither the comment nor the commit
message mentions it.
Could the comment, and perhaps the lco name, describe the general rule
instead? Something like "if this check field is not the
CHECKSUM_PARTIAL offload target, it holds a complete checksum".
> +
> + if (lco)
> + skb->ip_summed = CHECKSUM_NONE;
> +
> nf_csum_update(skb, iphdroff, &hdr->check, tuple, maniptype);
> inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport,
> false);
> +
> + if (lco)
> + skb->ip_summed = CHECKSUM_PARTIAL;
[Severity: High]
Is the root cause in the shared helpers rather than in this caller?
Under CHECKSUM_PARTIAL, inet_proto_csum_replace4() and
inet_proto_csum_replace16() in net/core/utils.c assume *sum is the
uncomplemented pseudo-header seed at the offload target:
net/core/utils.c:inet_proto_csum_replace4() {
...
} else if (pseudohdr)
*sum = ~csum_fold(csum_add(csum_sub(csum_unfold(*sum),
(__force __wsum)from),
(__force __wsum)to));
}
With pseudohdr=false they do nothing at all.
That assumption doesn't hold for the state that udp_set_csum() and
udp6_set_csum() leave behind on the LCO path:
uh->check = udp_v4_check(len, saddr, daddr, lco_csum(skb));
The follow-up patch "netfilter: nf_flow_table: Fix stale outer UDP
checksum in the fastpath" covers the flowtable. It copies the same
lco / ip_summed toggle into nf_flow_nat_ip_udp(),
nf_flow_nat_ipv6_udp() and nf_flow_nat_port_udp().
Even with both patches applied, other code that rewrites outer UDP
addresses or ports on the same skbs still uses the seed-only semantics:
tcf_nat_act() in net/sched/act_nat.c, UDP case:
if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {
inet_proto_csum_replace4(&udph->check, skb, addr,
new_addr, true);
In net/openvswitch/actions.c, update_ip_l4_checksum() and
update_ipv6_checksum() take the seed path. set_tp_port() calls
inet_proto_csum_replace2(check, skb, *port, new_port, false), which
does nothing.
udp_snat_handler() and udp_dnat_handler() in
net/netfilter/ipvs/ip_vs_proto_udp.c call udp_partial_csum_update()
whenever ip_summed == CHECKSUM_PARTIAL.
nft_payload_l4csum_update() in net/netfilter/nft_payload.c applies the
seed formula under CHECKSUM_PARTIAL. nft_payload_set_eval() skips the
transport header checksum update entirely under CHECKSUM_PARTIAL.
nf_nat_ipv4_csum_recalc() and nf_nat_ipv6_csum_recalc() in this file
use inet_proto_csum_replace2(..., true).
As one example path, a local inner TCP SYN on a vxlan device takes the
LCO branch here:
vxlan_xmit()
udp_tunnel_xmit_skb()
udp_set_csum()
The packet can then reach act_nat, an OVS set action, IPVS, or an nft
payload set with checksum flags. All of these run before
skb_csum_hwoffload_help() in validate_xmit_skb(), so ip_summed is still
CHECKSUM_PARTIAL at that point.
Wouldn't these paths still produce the bad outer UDP checksums and
UdpInCsumErrors described in the commit message?
Could the helpers take the CHECKSUM_PARTIAL seed branch only when
skb_is_gso() is true, or when sum equals skb->head + csum_start +
csum_offset, and use csum_replace*() otherwise? That would cover every
caller, and this function would no longer need to change skb->ip_summed
temporarily.
The patch is also tagged Cc: stable, but the commit message doesn't
mention these other callers. Backporters may assume this class of bug
is fully fixed.
> if (!hdr->check)
> hdr->check = CSUM_MANGLED_0;
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203090554.158077-1-lvjunyu%40cmss.chinamobile.com
Technical Details
Message-ID:
<179637739377.3146.14147716671486576035@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377220-linux-kernel-netdev=dewy.ruReferences:
<20261203090554.158077-2-lvjunyu@cmss.chinamobile.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!peer05.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377220-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH v4 1/2] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets Date: Fri, 04 Dec 2026 09:43:13 +0000 Organization: Usenet Network Message-ID: <179637739377.3146.14147716671486576035@kernel.org> References: <20261203090554.158077-2-lvjunyu@cmss.chinamobile.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2729003"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:tjGfi0buLdLYk7lIk5nSiSMItdw= sha256:fSSiIVf6QpcwISIq1sRmxAe47sMWrgyXs2Qywd4uvx0= sha1:K2g15KxVyJlxjNOPJ/q/yrpmSdk= sha256:IHuBpk6vqiGi7qNtFRGKQubxcEW7sFVQqu3ZB7EQeuU= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 1773B117B84; Fri, 4 Dec 2026 12:43:42 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.639 X-Spam-Status: No, score=-3.639 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XqxYtjbrjNxC; Fri, 4 Dec 2026 12:43:38 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377220-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 074BE117B75; Fri, 4 Dec 2026 12:43:29 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id DFD2B2AB50; Fri, 4 Dec 2026 09:43:21 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796377401; b=RILc9+tT8lKb8v1RcZoHriNtj5DZaRgtyP53OWTRfeju7zHm0fEqpHEZ3+4lzKYqUIEY SmHKE1DU425xMewFcgAgFKNRT9aqgr3nxAzBu4rwGMUn8er+CBh0Qr4Gq7qoprMVFtit8 X9Ht5pEs9T8BlLzHdjR7cfvxNRffrctUgFnHPGf7uNFhdNDTYX7EHLK7bgwurJ/P85CCP 7sKvWiVUomm5iMi1uwozE1OhlmwFj0R4APjjZprAw1/GDoX0COGVAhG06aIp84UUp3O0f Eogl66bOpKoZlghLYA2JlDIYjaTxW5Lbcqf7ZtiTB4JKmhVvcoCe3T1FyvATF6ZmHWQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377401; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=2Kjbk1KSic6Q531FoG4Hze52rraGzf3OdZaNMSdWsME=; b=LmK5EFnBRCwb7sUEcD3boSua8nmhCqkSRi34hVii4QDbuLHK2/tlU0FaLKRkHJ0t6kho kHD6wCxg8iQxamkE7sAkTuF07DlrhGadl6hCGlsWRLf34IuwLY9nxqmFO0i/ZhQDZLTSi nHYemdqWFlNRFqnfr61z0tDN95wlA7QFv5bQZTba79ZiEWbYBE7zO4I2RRXYg4ifqaTKy UwGN+oxReP9jAZKmVlqsjQK7oYlVMESbwEt5CpmSC2/p+xJdSVI/vvsgzKR5yVG0evkA1 0W2c8C4GJbA7l6E+Y0LZDt1ZSt+l5gMm6ruj5RY0PWGiB/fim4oS8r4szyXgCI8GDDw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Xo1t+Q/+"; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22AE0606A332; Fri, 4 Dec 2026 09:43:21 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Xo1t+Q/+ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377395; b=wXdgooZUDoDjtF+E/0D18+zUH76Blgys7N5zqidSjV4m61OOB3FZiLc4L8x+CDFGh0ex YkgCGI0ta4T5Tg0wfxgZbX09rHEKXITsAvBU+bjGaS296R0rG4KRINGZ03DiwMzpfqRZJ api6TWr3KxTzSRdI1u3GsE4a0UGDY9b+n6gH02hWAljDQDenks+FTIjdwxc2QrXwiA4lZ Be0LtuxoFe37dVfhBGWXUCd6k0UAhU/CvVt0zxaZXqk20rDcXhRVufsMkvmQ2cOPZm+bV MWgYRcU1gp8sw2ASml30GfNl+G2FNoSGf3GQO/zEGKpgbqdh/sVRLFKQkPHTvXx+wcw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377395; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=2Kjbk1KSic6Q531FoG4Hze52rraGzf3OdZaNMSdWsME=; b=koCKV1+ARilC+deVO2mHLgBHoiXtGwijo867SfBQieC3LzWm6M2anYn/V+Zy3cYLH/Mv spmMqHZqlAjoGVR6Xq9RpjL0G4DwlxXAkDZloXvpVZZo5IdDKm3Jsv55ZxL2HQVAIRLox nNRaFY/UF2O5960udOf1SkvEEcqOM7cYeLtYIJVxn5p3MZpe5h1aMeCtyPxTtB4HoH/aW hrmQ7H4ngUq75VmJpf1EbJD4ytx3RthNABvTQC0+aStE5ey9ccVj4BHWmIV3BLcyiXV5W E9a2YSSTbwgnLC/ne9RwAsQfJzgOb75XIGLJcV8WNNTNWAJL0qZe69kx5zBGEVCi8iA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Xo1t+Q/+"; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42067606A322; Fri, 4 Dec 2026 09:43:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47E021F000C2; Fri, 4 Dec 2026 09:43:14 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796377394; bh=2Kjbk1KSic6Q531FoG4Hze52rraGzf3OdZaNMSdWsME=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Xo1t+Q/+ARKETMbgInUIlu0xiWlJBd0hmA7PikQnK8dzAyKAV6ONLF7FBU3Jx59eY 1p3g/KYUzZW3Dy5/hTyaQ1g3nYvwcfKM9KrVI6hkZLGTncNxqhCfoPA6Y2V5YVt+el w1tgsyNZ3nkg+22uNC7Vi+OrqoyKT0KRpKasGHzdGjwvhNVsr0gjtVOyNBLvcwiAOc eGFSnE1f/IOhDn6DknGp/CeNE9RocwdGWajZBlWMSALy5jutru8AzqKQauX5I2+qOY Ns0T75FwQcx/QleU2ScvGvcBkajYGzU7V8sao7Hl9la+nb960rugpeyjp0OyBBdQ2k KPW2gXCVzXCsA== X-Cc: pablo@netfilter.org, fw@strlen.de, phil@nwl.cc, netfilter-devel@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, kuba@kernel.org X-In-Reply-To: <20261203090554.158077-2-lvjunyu@cmss.chinamobile.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Received-Bytes: 16254