[PATCH v4 2/2] netfilter: nf_flow_table: Fix stale outer UDP checksum in the fastpath

From: lvjunyu

Date: Thu Dec 03 2026 - 04:07:27 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: lvjunyu <lvjunyu@xxxxxxxxxxxxxxxxxxxx>
---
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