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=1796377396; b=4yl0BEEFgCkiRdfTBJeyo41C7K2iGE4wf0on0wIIWrWTLPAPru6Hy85wHMNDMs6iCPmm cIj9adKmFuCYXp5QjHXM9ITwgQwawIH/IKLTkxqhRWnbIPteQ8CcedDbyvcr9QtUYzHm3 iJOiad+wD/StUNYSz+P3/nSybbIdsjCsI00u99Vh8bNG4yc3y7Mim93Vtjmq4fWgeaut6 if/Itl9cmzAWmRpkYYzQ1wbnvE+6DY0rQ3VT2neUiw9ziLT0P64wjP4c4da1GngwW85MT MDpeg9axw1ogXYmGVPA+m49Fu2pfapcLwQzjqKKBA7+zHdmlnp0rQMaCXQ4MA7FCSGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377396; 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=xhh4JcSCeddZyDXA/A+tI1NU5RzHWw98Kwh/tTfkCao=; b=xCAqA1+VLQNJ0RgE7Lfc0betP5etfHW5BizHlg8D7uuJJTk07uC20P77MPcuTadOuCes q4EgLzmFLNSFflNC4HBcrTDVJGP7zzudjERj4KjEpX/Jza6MkxZwGNs6lpFvwVtrZUL2N J6tZQmwQL0Q3m6HMkUZG82/GCpQLNSEHjtIlVNqqR+eLj0d4dRT3rWAr6QYocCWAiKLYo uqj/lmp4iTKUZMFUCM9x1eCcJ9nQ13KQKiu3lIx4vOhTuExmCgOwUX4hxQ6WsBEzOt7k2 ftffoiynHRAATA/FFiPWc7imt1qN2r4Q25ZTc7reJlJQsvrc4DVNPal6xqDKZ765ygg== 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=YIjTjW+D; 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 1F5A0606A339; Fri, 4 Dec 2026 09:43:16 +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=YIjTjW+D Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A4A41F000C2; Fri, 4 Dec 2026 09:43:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796377395; bh=xhh4JcSCeddZyDXA/A+tI1NU5RzHWw98Kwh/tTfkCao=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=YIjTjW+DrB1XHjEesEoFkUGS5gHzpz0mNNqHdydfqsOc8S/n2fA/h21A+aw/JsGgA nb4luoSJA7SfcuepwZxpkYXN3SKMOzJ6sWcwsI7imtCxl9oLtIVCJ2kE5uuUUXCe8L KH696O9QR8eyobvQ75jvOH+A85aVcGNnDqtBL3d77gFdLKOwn3UUW2WRj3JFD8nCaU 4ipEVUIksA3X7zxit3eFRu1Oul0jkIRbTCGFzfeUtTQwEDAtIHB7ACOcQFjZa4pIKt jiu1wVPfu3h5zBK9krfgOmZRte+JPZcY9JQVDIcKLE5i0aX43ydhxL9xD/gGI28FNR fGtn3KgBktbhg== Subject: Re: [PATCH v4 2/2] netfilter: nf_flow_table: Fix stale outer UDP checksum in the fastpath 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:14 +0000 Message-ID: <179637739496.3146.18443289292305772379@kernel.org> In-Reply-To: <20261203090554.158077-3-lvjunyu@cmss.chinamobile.com> References: <20261203090554.158077-3-lvjunyu@cmss.chinamobile.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@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 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