🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13076

[PATCH net-next v3 2/4] ipv6: take fib6_sernum from a sequence shared by all netns

#13076
From: Qiliang Yuan
Date: Mon, 09 Nov 2026 08:18
73 lines
11468 bytes
A per-cpu IPv6 route of a nexthop object records fib6_sernum of the
netns it was created in, and rt6_is_valid() compares it with fib6_sernum
of the netns its device belongs to when the route is checked. Every netns
starts its fib6_sernum at 1 and increments it on each tree change, so
different netns often hold the same value.

When a device moves to another netns, such a route remains usable until
nexthop_free_rcu() releases it, and fib6_info_destroy_rcu() queues that
callback from inside an RCU callback, after the device has moved. If the
fib6_sernum of the new netns matches the cached one in that window,
ip6_dst_check() accepts the route and a socket in the old netns keeps
sending through a device that now belongs to another netns.

Take every fib6_sernum bump from one sequence shared by all netns, which
only hands out values from 2 up: every netns still starts at 1, and 0
means there is no sernum to check. Inserting a route bumps fib6_sernum,
so the routes a netns caches carry values drawn from the sequence, which
no other netns holds until it wraps after 2^31 bumps. fib6_new_sernum()
callers only hold their own table's tb6_lock, so two tables of one netns
can store their values in either order, and fib6_sernum is no longer
monotonic per netns. It is only compared for equality, so this costs at
most an extra invalidation. A connected UDP socket in netns A caches a
route through an IPv6 nexthop object on a veth. The veth is moved to
netns B and brought up with one RTM_NEWLINK, then the socket sends
200000 datagrams. A route is added to and removed from B 0 to 20 times
before the move, 63 trials:

                                before     after
  trials sending after move          1         0
  datagrams sent after move       3429         0

Fixes: 8f34e53b60b3 ("ipv6: Use global sernum for dst validation with nexthop objects")
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
---
 net/ipv6/ip6_fib.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index e1d49897d6ab0..827051cbf7482 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -123,13 +123,23 @@ static void fib6_walkers_skip_rt(struct net *net, struct fib6_info *rt)
 	fib6_walkers_replace_leaf(net, rt, next);
 }
 
+/*
+ * Draw fib6_sernum bumps from one sequence shared by all netns, so that a
+ * route cached against one netns does not match the sernum of another one,
+ * e.g. after its device moved, until the sequence wraps. Every netns starts
+ * at 1 and the sequence only hands out values from 2 up: 0 means no sernum
+ * to check.
+ */
+static atomic_t fib6_sernum_seq = ATOMIC_INIT(1);
+
 static int fib6_new_sernum(struct net *net)
 {
-	int new, old = atomic_read(&net->ipv6.fib6_sernum);
+	int new, old = atomic_read(&fib6_sernum_seq);
 
 	do {
-		new = old < INT_MAX ? old + 1 : 1;
-	} while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new));
+		new = old < INT_MAX ? old + 1 : 2;
+	} while (!atomic_try_cmpxchg(&fib6_sernum_seq, &old, new));
+	atomic_set(&net->ipv6.fib6_sernum, new);
 
 	return new;
 }

-- 
2.43.0
Technical Details
Message-ID: <20261109-bug-net-netns-move-rcu-barrier-v3-2-6084b02610b3@linux.dev>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359122-linux-kernel-netdev=dewy.ru
References: <20261109-bug-net-netns-move-rcu-barrier-v3-0-6084b02610b3@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359122-linux-kernel-netdev=dewy.ru
From: qiliang.yuan@linux.dev (Qiliang Yuan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v3 2/4] ipv6: take fib6_sernum from a sequence
 shared by all netns
Date: Mon, 09 Nov 2026 03:18:13 -0500
Organization: Usenet Network
Message-ID: <20261109-bug-net-netns-move-rcu-barrier-v3-2-6084b02610b3@linux.dev>
References: <20261109-bug-net-netns-move-rcu-barrier-v3-0-6084b02610b3@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="307048"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:lP9ZMJvC2rZ8sW9I4yajmDWv6S4= sha256:UrbCqLh96zN3TNGHD04xOJoCbZB/o960FluntG1Fe9U=
	sha1:5F90QIcExp64GlVIl6v95h9SZ2w= sha256:rO0bXYDu1qnfEdPPfYfAXwcWiZcNEVPwrcnoIGPDC9w=
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 E356D113740; Mon,  9 Nov 2026 11:21:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-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=pass (1024-bit key)
	header.d=linux.dev
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 0PlUos0Otr4s;
	Mon,  9 Nov 2026 11:21:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359122-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9D6B4113730; Mon,  9 Nov 2026 11:21:30 +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 C0A4EE7537; Mon,  9 Nov 2026 08:18:47 +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=1794212327;
	b=FU/TN3AI62PoQUfloIeEp6vrkcIFUJGim39QDUoX+hxMMGZF8EyfCOZy5TI8dXahJ1rT
	 iOXVCs+aYxzwUgREY29Pu9XGc4lfUQdFh+bY4y3LFaON7mVAkJClah7Zz0EkJohO9RNGH
	 2VKIvYV2ZgDZ9yw0NuXg45pGMzmlIigPYKSAh67WnjlP6PIkxAhDnUnZlr8Z/Kuki8riI
	 6QmVUhQpUXf0Jylt0tSh4VI6BLZEc1LpPKH1Q0wtdqu2fg5I5ifemWU4pGw9ZEuSy2PAd
	 a6+ehyL2i2bDcdlpS9RAl+jil6LtrhEOdpkK/ObIn9Wd83xjNEw4sbwBm689GPA9xxA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794212327;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:
	 Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer;
	bh=x9XVD/0ohs7oMGMaz9ZkzBw5Vyvf8w/OSrxiwXVJ68Y=;
	b=ztvLFKwd/FmH7I2lyfDlatbkgFb8dQjqLDEPMjRVmep+WdswkG9yv6KxXrh1G1C0yxZu
	 zLhmd5DDwNCuil/NmwYlhr32lhv0uTszzsSzYnEO4xwogTOphJCmdgsmzsFf+o3mIMpjY
	 hX5TI/1Am2sVGT9TjGXknRumEPI6Fi5CKzZa+vJwIxgv1wuhYF5W1J3DagMwKjIgUpCvi
	 Vu2tQQ2O9TGuIIWmhCyRTlf3wWRucD90FIcBXGcRprc2lVYfYxCF8I1VQ+D2VUAdaGzxX
	 FV00n+FCZgfH0/P7J98LwvA5do4frbg6sOyvbzwvOlMpl/r6MPnZMUggbj7R0kCyAlg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=XpROUVdL;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 058B9606D806;
	Mon,  9 Nov 2026 08:18:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=XpROUVdL
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.155
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794212321;
	b=tIbnUQW1KnYHJGbgX4Rmr3zc1W2ypDhFqCDbuN0o1nB/av7S6q+NzroOw3VE4+gESWGL
	 Vr8yGZQ9VCHzgbU9D+CQfas5a3hwLfUggctURfiD2ah+d+YldXZFNlJA979AA9mcUYEvk
	 ipPXHVf/pH3RRO3WolbRkMa5W4Yy23xxOLlIcI7hrzMQO7bDnwjqtFhMe5An4d+RrCHz8
	 AwHnkq8lkN+Bv03PsbiVI/3hlBEob80WIjc13NJaWiwdmOTdw2sRISF9fXxjoC5VZfnOQ
	 Rh2zydfGBkX8JiDmqgl/mZwr5fQqqWe6XrhnVZ8c79iu0M/byrPgesZCXl0GH+RJBcA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794212321;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version:
	 Content-Type:Content-Transfer-Encoding:Message-Id:References:
	 In-Reply-To:To:Cc:X-Mailer;
	bh=x9XVD/0ohs7oMGMaz9ZkzBw5Vyvf8w/OSrxiwXVJ68Y=;
	b=gQY+PjLMoXXQhJ9xOTU8kehbKsUPmtEvsRaE3OKmqwTLErjW2XqOtO+D7mD3WLmvkXqQ
	 N34Pecm/UE8J0COuouEulLgkYjICNbRo5hDfTzklOz1fYzoa1mzYhOKg6hLirXMj4+ac9
	 1TdlcPeHoGOroS14ZBb04p6G6ejrI8QkOXCXNAYHeRRwXVQPF+xFeySevo/GQJjsZI1sE
	 dx6ZVwXAiV44H2JENxSfwqBM9z77X6SYhEWqmiFUep4NYbdzn2gChAyoteNUZPl5oYsfH
	 opBtViV3FjtMk1TeMHKbZIJb7eMy2TeKTS+X9k2Y7KzrEADt3wgWIX6N1sYY6TEKIjQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=XpROUVdL;
	arc=none smtp.remote-ip=91.218.175.155
X-Received: from mta0.migadu.com (out-155.mta0.migadu.com [91.218.175.155])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51C4A606A326
	for <netdev@vger.kernel.org>; Mon,  9 Nov 2026 08:18:39 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51C4A606A326
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=FerX5k66pAHBzte7mokkF2Oe+4SJ4Lb5zMrSGV3QcDA=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1794212318; v=1; x=1794817118;
 b=XpROUVdL9JYmch1q4FyY8+U5SI72+G848AHyj5OJ/r3y+NROC9/DQjaSBm2zr2ECFsdsuubG
 Zb6owJnFXFIcsy90KVCE/ooDH/Aj/qn0J2yTaJrcL4FLBK+CoQgBXzm2eOHoe5nHjdZGfiAogCe
 /nEWdx6EEsOCksrXl8Wrffvw=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 2c5c3cba312d07a0;
	Mon, 09 Nov 2026 08:18:38 +0000
X-Mizu-Trace-ID: 2c5c3cba312d07a0
X-Migadu-Flow: FLOW_OUT
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
X-In-Reply-To: <20261109-bug-net-netns-move-rcu-barrier-v3-0-6084b02610b3@linux.dev>
X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, netdev@vger.kernel.org, 
 linux-kernel@vger.kernel.org, Qiliang Yuan <qiliang.yuan@linux.dev>
X-Mailer: b4 0.13.0