🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18260

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

#18260
From: Qiliang Yuan
Date: Wed, 18 Nov 2026 02:28
91 lines
12228 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, and have rt6_is_valid() reject 1, the
value every netns starts with: fib6_add() publishes a route before it
bumps fib6_sernum, so a route looked up in between can record 1. 0 still
means there is no sernum to check. Any other value a route records was
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   change
  trials sending after move (count)       2       0    -100%
  datagrams sent after move (count)    4399       0    -100%

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 net/ipv6/ip6_fib.c | 16 +++++++++++++---
 net/ipv6/route.c   |  6 +++++-
 2 files changed, 18 insertions(+), 4 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;
 }
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 4a4c5ace63c54..6731665fbb16d 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1466,7 +1466,11 @@ static struct rt6_info *ip6_rt_pcpu_alloc(const struct fib6_result *res)
 
 static bool rt6_is_valid(const struct rt6_info *rt6)
 {
-	return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev));
+	/* Reject the initial sernum, which every netns shares and which a
+	 * route can record before its insertion bumps the sernum.
+	 */
+	return rt6->sernum != 1 &&
+	       rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev));
 }
 
 /* It should be called with rcu_read_lock() acquired */

-- 
2.43.0
Technical Details
Message-ID: <20261117-bug-net-netns-move-rcu-barrier-v4-2-43e1ca0aac7f@linux.dev>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365816-linux-kernel-netdev=dewy.ru
References: <20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365816-linux-kernel-netdev=dewy.ru
From: qiliang.yuan@linux.dev (Qiliang Yuan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v4 2/4] ipv6: take fib6_sernum from a sequence shared by all netns
Date: Tue, 17 Nov 2026 21:28:31 -0500
Organization: Usenet Network
Message-ID: <20261117-bug-net-netns-move-rcu-barrier-v4-2-43e1ca0aac7f@linux.dev>
References: <20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network; logging-data="2483728"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:LPgvVklagwbiqbVZO9/gCpaIew0= sha256:XifibJ/Ub4r+NCJPRnIkZ33YhOOc9ffGR4uFtBuAw04= sha1:DAE/YCn/ajuhTZno6ttBDAUKJmA= sha256:IP+ooKw52aU2UB27cm/uxm1M14InQ0HyUl2hN5G3EUk=
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 113FA115159; Wed, 18 Nov 2026 05:29:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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, URIBL_BLOCKED=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 JYpBq7kW_20c; Wed, 18 Nov 2026 05:29:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-365816-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id DB00E115154; Wed, 18 Nov 2026 05:29:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 649543E6C4; Wed, 18 Nov 2026 02:29:06 +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=1794968946; b=DmRzIRTaFw4l2o9+gS8VAvC+eiWm6VLd2rJNeITN91pyNaiNsj6iiamDjTyL6y/5tpDs kO+BqVz0kzMSTJxrDNZwcCMBcbnjMh6kJnbD3XZTVh7fvdqIxpFZ9NvZgYm/xyAhc54li dfIOAjtTXY1yQNGg2MPn2I2/DLMrHedlzSTUI8Qg4p+kIUMvWeTLZBvrSv5ewh+ecyP3b JCjndFp/+vEx8VXfPr8kkBRaywihsPVIF3j/+0NA0z/5mn3jOHSQMOetCHjzhdSMLZg1V h+OWuZhhmu9gZaSCiutzxFlqMgU6pr/iDrFDLCD8vbgXDZ2Q1rpmvUM9vrY1eys271Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794968946; 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=xNNsaqZWbltLe29vh8c9m5LEUiW5nYXhMDb/b7gjjVM=; b=vl+Ik0EKfl8QWzdG4TCX5VaK/PClAbCdsorqaQV2+1IUJwCOXPrxkGY827cOeSVRLM3x mD94IJ540B0pivcIoZqQxGbE6piLwqUi5QiOfpj5CSjYuAfwgvfw5QzNruJo+hKgFv5L4 VMZbWsAxj+V+KkD3OhmjNeOC73GvNwKEk9XoqGwJYEaOu/LVoGV9d8VYAa+ttE2Lif3DN eM6JXHqpnzSDTvEH8VZ1T7ewIeGXenx6jf4mNSMVNojiDWSV+hMScbGh4ICHu/9mJ7V14 8mgtyKIHMsIo/EZ3YR1tQZCmxNk/zS33/udIBLEP9Ba/3NPTwdSSYC6VNlf/6TTtmbQ==
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=YolnICRs; 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 25279606A333; Wed, 18 Nov 2026 02:29:06 +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=YolnICRs
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.132
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794968945; b=Jhh6hQ6b5FT6SiJb3ebmVvQ9WYYKOg6y7EHrEuxTIxSt+YimGeBqyUm91yyqR98OKRAW x5vKR2ZahAArR0kOw1/T4RD9wS0qTnHHMfKxsBlEe6aKELKIZcJz8x4D5ymUwj5CdkImT 0F8NGLxkejQuiL3PVApFzK/rQ0+3XV6XBOsc7IQjQBqulHz8hsp754sLRpmtwG1CZ+MwW gI3oQrMgy5RdIRJoAyijPu0ZxEGmtFyudyMOttjxfbEaod8n20qZLfLobqe6+cMScW2BR Skce/1gvfzEy6AVUFK9DQJcqhldC4/4WOMTTKo2BwxRU44SIwdyt7+RhznrCbSX2W3w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794968945; 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=xNNsaqZWbltLe29vh8c9m5LEUiW5nYXhMDb/b7gjjVM=; b=oT8O7/7/gwIIxwMU2l+V35C+qRVEaXgZLhTT2G17g4YVmATBTQg26zMl7uEe4F6DQU9g B5jdQahdqwOnTaxUNsby4bp9SZ4Eqlgtn3ZLcBkGH30enV2y1gcqSZ/ABpFoPniXtkoxP ubjZjZPYMMMziWpaBJHv/j4WekhHpYSBT90udFSJbWrleJ5rxJ5++a2l6/vQlUUSXdDLV rcVKTZ3/TQFe58HUteN9n4nwCGSKOJnhCVT26Tq6oJgWjf3BbTTDFg8B8sOMQUiMDCsWA pM6v0zGEnLbdmsKXYTX5BxRMz7VrrX72lvHFkX6NCgF0o/1Ry2QAD/VMJ5JMiKMz0gA==
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=YolnICRs; arc=none smtp.remote-ip=95.215.58.132
X-Received: from mta1.migadu.com (out-132.mta1.migadu.com [95.215.58.132]) (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 A80DA606A32C for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 02:29:04 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A80DA606A32C
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=cpNaD7ZH3vjTO9Ho6qnhSNnvPor2Oyo++l4ViMHdDtg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794968942; v=1; x=1795573742; b=YolnICRsqNq/Q1E18JzTG5dK264mWoJjH1UfMjLHv+O5cY+5gcCvTc8559G/tyjcbeUtIsU5 mC4FnzZ3558DVhAJmqPm4SiJ9p1GxuwGQmO8wHWby0QuZF7j1azm5bg8jvo8EhZWUkIDchX6/02 d3r4kUGkD+8+6TxgOfSdNMrk=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 3bc377a770cd0a92; Wed, 18 Nov 2026 02:29:02 +0000
X-Mizu-Trace-ID: 3bc377a770cd0a92
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: <20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f@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
X-Received-Bytes: 11942