Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: lvjunyu@cmss.chinamobile.com
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
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	[thread overview]
Message-ID: <179637739377.3146.14147716671486576035@kernel.org> (raw)
In-Reply-To: <20261203090554.158077-2-lvjunyu@cmss.chinamobile.com>

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

  reply	other threads:[~2026-12-04  9:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08  5:42 [PATCH v3] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets lvjunyu
2026-10-12  6:13 ` netdev-bot+sashiko
2026-10-13  9:00 ` lvjunyu
2026-12-03  9:05 ` [PATCH v4 0/2] netfilter: " lvjunyu
2026-12-03  9:05   ` [PATCH v4 1/2] netfilter: nf_nat: " lvjunyu
2026-12-04  9:43     ` netdev-bot+sashiko [this message]
2026-12-03  9:05   ` [PATCH v4 2/2] netfilter: nf_flow_table: Fix stale outer UDP checksum in the fastpath lvjunyu
2026-12-04  9:43     ` netdev-bot+sashiko

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=179637739377.3146.14147716671486576035@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=fw@strlen.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvjunyu@cmss.chinamobile.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=phil@nwl.cc \
    --cc=stable@vger.kernel.org \
    /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