Re: [PATCH v4 1/2] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets
From: netdev-bot+sashiko
Date: Fri Dec 04 2026 - 04:43:20 EST
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