mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: lvjunyu <lvjunyu@cmss.chinamobile.com>
To: pablo@netfilter.org
Cc: fw@strlen.de, phil@nwl.cc, netfilter-devel@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, lvjunyu <lvjunyu@cmss.chinamobile.com>
Subject: [PATCH v4 2/2] netfilter: nf_flow_table: Fix stale outer UDP checksum in the fastpath
Date: Thu,  3 Dec 2026 17:05:53 +0800	[thread overview]
Message-ID: <20261203090554.158077-3-lvjunyu@cmss.chinamobile.com> (raw)
In-Reply-To: <20261203090554.158077-1-lvjunyu@cmss.chinamobile.com>

The flowtable software fastpath has the same LCO (Local Checksum
Offload) defect that was fixed in __udp_manip_pkt() for the classic
conntrack NAT path.

Once the conntrack entry of a VXLAN/Geneve flow is offloaded,
subsequent packets of the outer flow bypass __udp_manip_pkt() and
are NATed by the flowtable helpers instead:

  nf_flow_nat_ip() -> nf_flow_nat_ip_udp()
  nf_flow_nat_ipv6() -> nf_flow_nat_ipv6_udp()
  nf_flow_snat_port()/nf_flow_dnat_port() -> nf_flow_nat_port_udp()

For locally generated encapsulated packets in the LCO state
(CHECKSUM_PARTIAL, non-GSO, a complete folded checksum in
uh->check while csum_start points at the inner transport header):

  - inet_proto_csum_replace4/16(pseudohdr=true) takes the seed
    branch and applies the address delta with the wrong sign.
  - inet_proto_csum_replace2(pseudohdr=false) is a no-op, so the
    port delta is lost.

Locally generated VXLAN packets keep CHECKSUM_PARTIAL across a veth
pair, so in a netns/container VXLAN deployment where the flowtable
hook sits at the ingress of the receiving netns these helpers are
reached with LCO packets.  Packets before the flow is offloaded are
fixed up by the __udp_manip_pkt() change, but every packet after
offload corrupts the outer UDP checksum again, the peer drops it
and the inner TCP flow stalls.

Mirror the __udp_manip_pkt() fix: detect the LCO state via the
offload target (csum_start + csum_offset does not point at this
udphdr->check) and temporarily flip ip_summed to CHECKSUM_NONE so
both the address and port updates use the csum_replace*() complete
checksum path.

Fixes: 97add9f0d66d ("netfilter: flow table support for IPv4")
Fixes: 0995210753a2 ("netfilter: flow table support for IPv6")
Fixes: ac2a66665e23 ("netfilter: add generic flow table infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: lvjunyu <lvjunyu@cmss.chinamobile.com>
---
 net/netfilter/nf_flow_table_core.c | 16 ++++++++++++++
 net/netfilter/nf_flow_table_ip.c   | 34 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 2aa2647ed9df..1971ab36134d 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -642,8 +642,24 @@ static void nf_flow_nat_port_udp(struct sk_buff *skb, unsigned int thoff,
 
 	udph = (void *)(skb_network_header(skb) + thoff);
 	if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {
+		/* With pseudohdr=false, inet_proto_csum_replace2() is
+		 * a no-op under CHECKSUM_PARTIAL, so the port delta
+		 * would be lost for the same LCO packets that
+		 * nf_flow_nat_ip_udp() fixes up.
+		 */
+		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_replace2(&udph->check, skb, port,
 					 new_port, false);
+
+		if (lco)
+			skb->ip_summed = CHECKSUM_PARTIAL;
 		if (!udph->check)
 			udph->check = CSUM_MANGLED_0;
 	}
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index 19cafae748ab..4b69527942f6 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,
+		 * 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;
 	}
@@ -951,8 +971,22 @@ static void nf_flow_nat_ipv6_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 fixup as nf_flow_nat_ip_udp(), with the
+		 * IPv6 address delta (inet_proto_csum_replace16()).
+		 */
+		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_replace16(&udph->check, skb, addr->s6_addr32,
 					  new_addr->s6_addr32, true);
+
+		if (lco)
+			skb->ip_summed = CHECKSUM_PARTIAL;
 		if (!udph->check)
 			udph->check = CSUM_MANGLED_0;
 	}
-- 
2.43.0




  parent reply	other threads:[~2026-12-03  9:07 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   ` lvjunyu [this message]
2026-12-04  9:43     ` [PATCH v4 2/2] netfilter: nf_flow_table: Fix stale outer UDP checksum in the fastpath 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=20261203090554.158077-3-lvjunyu@cmss.chinamobile.com \
    --to=lvjunyu@cmss.chinamobile.com \
    --cc=fw@strlen.de \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®