Article View: linux.kernel.netdev
Article #26229[PATCH v4 1/2] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets
From: lvjunyu
Date: Thu, 03 Dec 2026 09:05
Date: Thu, 03 Dec 2026 09:05
81 lines
12120 bytes
12120 bytes
When MASQUERADE --random-fully rewrites the outer UDP source port and
address of a VXLAN-encapsulated packet whose inner header has
CHECKSUM_PARTIAL, the outer UDP checksum is not updated correctly.
udp_set_csum() takes the LCO (Local Checksum Offload) branch for
encapsulated CHECKSUM_PARTIAL non-GSO packets, writing a complete
(folded and complemented) checksum into uh->check while leaving
csum_start pointing at the inner transport header. In this state:
- inet_proto_csum_replace2() is a no-op (pseudohdr=false,
CHECKSUM_PARTIAL)
- nf_csum_update() -> inet_proto_csum_replace4(pseudohdr=true)
takes the pseudo-header branch which treats uh->check as an
uncomplemented seed, applying the address delta with the wrong
sign
Fix this by using the offload target (csum_start + csum_offset) to
distinguish the LCO state from the seed/offload state, and temporarily
flipping ip_summed to CHECKSUM_NONE so both the address and port updates
use csum_replace*() (the complete-checksum path).
Test results (10 connections, single netns vxlan + veth environment):
Before fix: ~1080ms avg first-connection latency, 10 SYN retransmits,
UdpInCsumErrors incremented per connection
After fix: ~29ms avg first-connection latency, 0 SYN retransmits,
UdpInCsumErrors unchanged
Fixes: faec18dbb0405 ("netfilter: nat: remove l4proto->manip_pkt")
Cc: stable@vger.kernel.org
Signed-off-by: lvjunyu <lvjunyu@cmss.chinamobile.com>
---
net/netfilter/nf_nat_proto.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/net/netfilter/nf_nat_proto.c b/net/netfilter/nf_nat_proto.c
index 64b9bac228ea..6779e9f2812d 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;
+
+ 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;
+
if (!hdr->check)
hdr->check = CSUM_MANGLED_0;
}
--
2.43.0
Technical Details
Message-ID:
<20261203090554.158077-2-lvjunyu@cmss.chinamobile.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376426-linux-kernel-netdev=dewy.ruReferences:
<20261008054228.752274-1-lvjunyu@cmss.chinamobile.com> <20261203090554.158077-1-lvjunyu@cmss.chinamobile.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376426-linux-kernel-netdev=dewy.ru From: lvjunyu@cmss.chinamobile.com (lvjunyu) Newsgroups: linux.kernel.netdev Subject: [PATCH v4 1/2] netfilter: nf_nat: Fix stale outer UDP checksum on VXLAN encapsulated packets Date: Thu, 3 Dec 2026 17:05:52 +0800 Organization: Usenet Network Message-ID: <20261203090554.158077-2-lvjunyu@cmss.chinamobile.com> References: <20261008054228.752274-1-lvjunyu@cmss.chinamobile.com> <20261203090554.158077-1-lvjunyu@cmss.chinamobile.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2443875"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:MubHAOJVd473BjSoRDeFsaYdO/o= sha256:j66KXPxr4ktM4pWiwRmA0NQ1gc/8g4R9elNnoX+v9NE= sha1:gdy5B/dtY/WZVeg+Kcot0t0OPDU= sha256:D1oB+eso1OLwEfNtNgh6texLRWoM/4xW+pbHtk/dS0A= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 4A6C3117892; Thu, 3 Dec 2026 12:07:24 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.751 X-Spam-Status: No, score=-2.751 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key) reason="fail (body has been altered)" header.d=cmss.chinamobile.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZE-eCDiPtmyw; Thu, 3 Dec 2026 12:07:21 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376426-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 36C5A117873; Thu, 3 Dec 2026 12:07:13 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 9FF362777B; Thu, 3 Dec 2026 09:07:11 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796288831; b=L4wm5nsyd2YX/gWWqWt33wASiIv9gEceNI4AP3fB2imH01OfQDVfJZTRvXEXS1PjmOV0 bVkGk4uabxFLSgJ5Ddr4QfK8GJFuraN8GuvzVtHxOjupPrGmjDUKzY83Fyvy2fZOLCbGB w+ZenpZYXqVCf3kj9aeh4lxvAaklz3/3amSBamEiSor5WhYzkZAlxJ8Rf4kmZDNfF1ty3 nqrS0u0KZqsoh4/su+8kqZMsLnVab7ZFVUQ4OM1VuZOBCah/0HECoXx/u+wVwvtAU5n4c sKTkIuMR5h+G90jf7GZq5ecwp+4hW7nXBHpkS7gbG6pdC2BTsQUpKLC/5Jp3emQK+hQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288831; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo: X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG: Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=/45TdZ6SmCWE5U050F5VlVyLLz/V8R4cE0qr3NaMQbQ=; b=D1hq3TwamIw9wtFUMvKtw5n7+9V0qAFK9I727ZSSXqskRQir7+h7464KP046mv2F593B QLWuiOhu4fAciIYIDPavATzMtQuWrW8xe4Q2QC1JSL9BrjQr1bvD5dB/0QgkxVCz6qKoh wAkEDrIroTJEJViBsiAqeTE8SaNF11BWQDUUSzvVAMSCtanKM5WLCoaMxbyQtmKume4A2 U2lGyoZYCkUSUIjjLRubPl12mzicNEYkOuJsZII5yHSXeZyigt0cmeZR69rzNks2lw013 AAfKg94Yv8WtuvStTFM3IchroPlt81Iej591v45QiY9wHVOfRUzSmom58lDnb7jRDzg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b="ZA+Nf/LQ"; dmarc=pass header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03A6E606A33C; Thu, 3 Dec 2026 09:07:11 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=ZA+Nf/LQ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.135 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288830; b=Khm4vIsygr81sHVGBod16fzxJSzu1KBo3SVF5verwl580U1LMH5nPxIzc2QS3D0RRhKo ojCwBTMyaxlbXtljsH+OrGsf5S3yGWz3FyUBozYuSW9WGMDd+o7U1rN7zwx57o9o5tLql inR8OWwK7pDNV36B+FvfvlNrj7HIT27MylAu7Qs3Ac3O4MfXOdMMx4IdrqsfOyn6dsWgw AmhidVE3/mOm08Ayr/1MqTcArKHWQm5y8IqQ8SzPZOtCAnrGJXY+OM1kf1DoUzZsN+EzG V2lOiaGME5uzxRISjPZx8x9Le+OxDDumiQ4RY57gk9HwtzHd2GlWnqC5NXbrHoJSwIA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288830; h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received: X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From: To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=/45TdZ6SmCWE5U050F5VlVyLLz/V8R4cE0qr3NaMQbQ=; b=ahHdQ+3R0T+MNYGEFSjAyb+0x3Hk+n0K/XSkQhItinZr1hfNIq3J5cidfOyp5zBSLxio jNhsFCeornTmywELthoMCglHPP9iMD4mCOBVr4b9jwGGxzi/1wPcOJ7umcAEfQqwEV/9B fCqZazjKkqKUUlWA3wnocCRdMD8/6ZxFay0Wc4sTab3UUJmW+Xbap2tggzmjQ5CMAF4JQ 1frnA4mbG0mR6pWBOnKzg+VED4yuBJs5mc5Mb471PJaJ98uUc5hnJ+D6UnyrCdxRHdunv FBftkdzUMmsrVvOSJjvW02OjsT6AuG9sAcuCb+UcGHKjJ9IzXKJNz6T4jmsQxbZLHaw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b="ZA+Nf/LQ"; arc=none smtp.remote-ip=111.22.67.135 X-Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [111.22.67.135]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B400606A32F; Thu, 3 Dec 2026 09:07:08 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B400606A32F X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmss.chinamobile.com; s=default; l=0; h=from:subject:message-id:to:cc:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=ZA+Nf/LQ+iyBAkIBKt8tePV5rMvJjVFBZgZcIqQxU+fgGw/GrGSj01Nauj4rF03OGsIzd7BunzyYV UipxjT2FN94s3nYSG0z7oOc+p7Y8CR1lVYR35KJt1C6JQRdAZbucFSNfifxae7Gs8eXNDqznCVdUlU 7OrPW0OuluD2RFSo= X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app03-12003 (RichMail) with SMTP id 2ee36b1131342b7-65b71; Thu, 03 Dec 2026 17:07:00 +0800 (CST) X-RM-TRANSID: 2ee36b1131342b7-65b71 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-Received: from (unknown[223.108.79.102]) by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee16b11310a2f6-6530e; Thu, 03 Dec 2026 17:07:00 +0800 (CST) X-RM-TRANSID: 2ee16b11310a2f6-6530e X-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> X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261203090554.158077-1-lvjunyu@cmss.chinamobile.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list