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 2/2] netfilter: nf_flow_table: Fix stale outer UDP checksum in the fastpath
Date: Fri, 04 Dec 2026 09:43:14 +0000	[thread overview]
Message-ID: <179637739496.3146.18443289292305772379@kernel.org> (raw)
In-Reply-To: <20261203090554.158077-3-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 fix is incomplete: tunnels with the outer UDP checksum
  turned off are still corrupted after flow offload.
- [Low] The new comment in nf_flow_nat_ip_udp()
  (net/netfilter/nf_flow_table_ip.c, lines 62-63) calls the reference…
- [Low] netfilter: nf_flow_table: duplicated LCO toggle open-codes csum
  helper

--

netfilter: nf_flow_table: Fix stale outer UDP checksum in the fastpath

This patch changes the flowtable UDP NAT helpers nf_flow_nat_ip_udp(),
nf_flow_nat_ipv6_udp() and nf_flow_nat_port_udp() to detect the LCO state.
In that state the skb is CHECKSUM_PARTIAL and not GSO, and the offload
target is not this udphdr->check.  When it is detected, ip_summed is
temporarily switched to CHECKSUM_NONE so the outer UDP checksum is updated
on the complete-checksum path, mirroring the __udp_manip_pkt() fix.

[ ... ]

> diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
> index 19cafae748abe..4b69527942f6d 100644
> --- a/net/netfilter/nf_flow_table_ip.c
> +++ b/net/netfilter/nf_flow_table_ip.c
> @@ -59,8 +59,28 @@ static void nf_flow_nat_ip_udp(struct sk_buff *skb, unsigned int thoff,
>  
>  	udph = (void *)(skb_network_header(skb) + thoff);
>  	if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {
> +		/* Same LCO state as __udp_manip_pkt() in the NAT
> +		 * OUTPUT path: for encapsulated CHECKSUM_PARTIAL,

[Severity: Low]
This isn't a bug, but is "in the NAT OUTPUT path" accurate here?

__udp_manip_pkt() takes no hook argument.  udp_manip_pkt() calls it for
both SNAT and DNAT at every NAT hook, and the LCO case with MASQUERADE
would run in POSTROUTING rather than OUTPUT.

> +		 * non-GSO packets, udp_set_csum() writes a complete
> +		 * checksum into uh->check while csum_start points at
> +		 * the inner transport header.  inet_proto_csum_replace4()
> +		 * would take the pseudohdr seed branch and apply the
> +		 * address delta with the wrong sign.  Temporarily flip
> +		 * ip_summed so the complete-checksum path is used.
> +		 */
> +		bool lco = skb->ip_summed == CHECKSUM_PARTIAL &&
> +			   !skb_is_gso(skb) &&
> +			   (skb->head + skb->csum_start + skb->csum_offset) !=
> +			   (unsigned char *)&udph->check;
> +
> +		if (lco)
> +			skb->ip_summed = CHECKSUM_NONE;
> +
>  		inet_proto_csum_replace4(&udph->check, skb, addr,
>  					 new_addr, true);
> +
> +		if (lco)
> +			skb->ip_summed = CHECKSUM_PARTIAL;
>  		if (!udph->check)
>  			udph->check = CSUM_MANGLED_0;
>  	}

[Severity: Low]
This isn't a bug, but this patch open-codes the same lco predicate
three times, along with the ip_summed save/restore around
inet_proto_csum_replace*():

  - nf_flow_nat_port_udp()
  - nf_flow_nat_ip_udp()
  - nf_flow_nat_ipv6_udp()

Patch 1/2 adds a fourth copy in __udp_manip_pkt().  That is fairly
subtle checksum state logic, and every copy has to be kept in sync.
Any later fix to it would have to be applied in four places.

All four copies also open-code skb->head + skb->csum_start.
skb_checksum_start() in include/linux/skbuff.h already provides that.

Could the detection and the temporary ip_summed flip be factored into
a single shared helper built on skb_checksum_start()?

More broadly, inet_proto_csum_replace4(),
inet_proto_csum_replace16() and inet_proto_csum_replace_by_diff() in
net/core/utils.c already receive both sum and skb.  They could tell
whether sum is the offload target themselves.

Other in-tree users rewrite outer addresses or ports through these
helpers:

  - net/sched/act_nat.c
  - net/openvswitch/actions.c
  - the BPF l4 csum helpers in net/core/filter.c

They look like they would hit the same LCO state on UDP tunnel
traffic, and would still produce a stale outer checksum after this
series.

Was handling this in the core helpers considered?  Or is there a
reason to keep the workaround local to the netfilter callers?

[Severity: High]
Does the lco predicate also match tunnels that have the outer UDP checksum
disabled?

In that case udp_set_csum() takes the nocheck branch:

net/ipv4/udp.c:udp_set_csum() {
	if (nocheck) {
		uh->check = 0;
	...
}

ip_summed stays CHECKSUM_PARTIAL, csum_start still points at the inner
transport header, and uh->check is 0.

This gate still admits that skb:

	if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {

lco then evaluates true, and csum_replace4() runs on *sum == 0.  The result
is ~fold(~from + to), which is nonzero whenever the address actually
changes.  The CSUM_MANGLED_0 fallback therefore never fires, and the packet
goes out with a nonzero but wrong outer checksum.  Won't the receiving
VTEP drop it?

The same seems to apply in two other places:

  - nf_flow_nat_ipv6_udp() via inet_proto_csum_replace16().
    udp6_set_csum() has the same nocheck branch.
  - nf_flow_nat_port_udp() in nf_flow_table_core.c, where the port
    delta is now written into the zero checksum.

The classic path this is meant to mirror never rewrites a zero checksum:

net/netfilter/nf_nat_proto.c:udp_manip_pkt() {
	...
	__udp_manip_pkt(skb, iphdroff, hdr, tuple, maniptype, !!hdr->check);
	...
}

So these packets would pass before offload and still be dropped after
offload.

Several common setups are in this state:

  - Geneve over IPv4, by default.  geneve_nl2info() only sets
    IP_TUNNEL_CSUM_BIT when IFLA_GENEVE_UDP_CSUM=1.
  - VXLAN created with noudpcsum.
  - IPv6 tunnels using udp6zerocsumtx.

This state was already broken before the patch, so it isn't a new
regression.  Address updates went through the CHECKSUM_PARTIAL seed
branch, and the port update was a no-op followed by CSUM_MANGLED_0.

The commit message says this mirrors the __udp_manip_pkt() fix.  Should
these helpers skip the update when lco is set and udph->check is 0, to
match the !!hdr->check gate in udp_manip_pkt()?

[ ... ]

-- 
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
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 [this message]

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=179637739496.3146.18443289292305772379@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