From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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/+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47E021F000C2; Fri, 4 Dec 2026 09:43:14 +0000 (UTC) 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== Subject: Re: [PATCH v4 1/2] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets 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 Date: Fri, 04 Dec 2026 09:43:13 +0000 Message-ID: <179637739377.3146.14147716671486576035@kernel.org> In-Reply-To: <20261203090554.158077-2-lvjunyu@cmss.chinamobile.com> References: <20261203090554.158077-2-lvjunyu@cmss.chinamobile.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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