🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21324

[RFC net-next v2 7/7] ipv6: stamp dsts with the generation sampled before the FIB lookup

#21324
From: David Ahern
Date: Mon, 23 Nov 2026 21:26
131 lines
12446 bytes
From: David Ahern <dahern@nvidia.com>

A dst is stamped with the netns route generation in ip6_dst_alloc(),
which runs after the FIB has been read. A route change that lands
between the lookup and the allocation is folded into the stamp: the
dst was built from the old tree but carries the new generation, so
ip6_dst_check() accepts it and it can keep bypassing the new route
indefinitely.

Sample the generation before the FIB is walked, carry it in
struct fib6_result and stamp every dst built from that result with it.
Writers bump the generation after the route change is visible, so a
lookup that read the old tree cannot have sampled the new generation;
the resulting dst fails ip6_dst_check() as soon as the change is
published. Use an acquire read for the sample so the FIB reads are not
reordered before it.

The sample is taken in fib6_table_lookup(), ip6_pol_route_lookup() and
__ip6_route_redirect(). Exceptions created from an existing dst in
__ip6_rt_update_pmtu() and rt6_do_redirect() inherit that dst's stamp
instead of the current generation. Dsts allocated without a lookup
result keep the stamp taken in ip6_dst_alloc().

Signed-off-by: David Ahern <dahern@nvidia.com>
---
Changes since v1:
- New patch.

 include/net/ip6_fib.h       |  5 +++++
 include/net/net_namespace.h | 10 ++++++++++
 net/ipv6/route.c            | 12 ++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 92fed30a7418..a11c4a556b5d 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -225,6 +225,11 @@ struct fib6_result {
 	u32			fib6_flags;
 	u8			fib6_type;
 	struct rt6_info		*rt6;
+	/* Route generation sampled before the FIB was read. Dsts built
+	 * from this result are stamped with it, not with the generation
+	 * at allocation time. 0 means not sampled.
+	 */
+	int			sernum;
 };
 
 #define for_each_fib6_node_rt_rcu(fn)					\
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index f39baf51bcc5..31ffac7baf73 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -557,6 +557,16 @@ static inline int rt_genid_ipv6(const struct net *net)
 	return atomic_read(&net->ipv6.fib6_sernum);
 }
 
+/* Sample the generation before walking the FIB. Writers bump it after the
+ * route change is visible, so a lookup that sees the old tree cannot sample
+ * the new generation: whatever dst it builds carries a generation that
+ * fails ip6_dst_check() once the change lands.
+ */
+static inline int rt_genid_ipv6_sample(const struct net *net)
+{
+	return atomic_read_acquire(&net->ipv6.fib6_sernum);
+}
+
 /* Invalidate every cached IPv6 dst in @net. Returns the new generation,
  * which is never 0.
  */
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 38d5f3bc85bb..deedb5fb62ca 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1210,6 +1210,12 @@ static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res)
 	rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
 	ip6_rt_init_dst(rt, res);
 
+	/* Pair the dst with the generation the FIB was read under, so a
+	 * change between the lookup and this allocation is not folded in.
+	 */
+	if (res->sernum)
+		rt->sernum = res->sernum;
+
 	rt->rt6i_dst = f6i->fib6_dst;
 	rt->rt6i_flags = res->fib6_flags;
 	if (nh->fib_nh_gw_family) {
@@ -1294,6 +1300,7 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *ip6_pol_route_lookup(struct net *net,
 	struct rt6_info *rt;
 
 	rcu_read_lock();
+	res.sernum = rt_genid_ipv6_sample(net);
 	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
 restart:
 	res.f6i = rcu_dereference(fn->leaf);
@@ -2277,6 +2284,7 @@ int fib6_table_lookup(struct net *net, struct fib6_table *table, int oif,
 {
 	struct fib6_node *fn, *saved_fn;
 
+	res->sernum = rt_genid_ipv6_sample(net);
 	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
 	saved_fn = fn;
 
@@ -2987,6 +2995,8 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,
 
 		res.fib6_flags = res.f6i->fib6_flags;
 		res.fib6_type = res.f6i->fib6_type;
+		/* derived from @rt6: it is only as current as that dst */
+		res.sernum = READ_ONCE(rt6->sernum);
 
 		if (res.f6i->nh) {
 			struct fib6_nh_match_arg arg = {
@@ -3166,6 +3176,7 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *__ip6_route_redirect(struct net *net,
 	 */
 
 	rcu_read_lock();
+	res.sernum = rt_genid_ipv6_sample(net);
 	fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
 restart:
 	for_each_fib6_node_rt_rcu(fn) {
@@ -4383,6 +4394,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
 
 	res.fib6_flags = res.f6i->fib6_flags;
 	res.fib6_type = res.f6i->fib6_type;
+	res.sernum = READ_ONCE(rt->sernum);
 	nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL);
 	if (!nrt)
 		goto out;
-- 
2.43.0
Technical Details
Message-ID: <20261123212623.106153-8-dsahern@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.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-369784-linux-kernel-netdev=dewy.ru
References: <20261123212623.106153-1-dsahern@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.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-369784-linux-kernel-netdev=dewy.ru
From: dsahern@kernel.org (David Ahern)
Newsgroups: linux.kernel.netdev
Subject: [RFC net-next v2 7/7] ipv6: stamp dsts with the generation sampled before the FIB lookup
Date: Mon, 23 Nov 2026 14:26:09 -0700
Organization: Usenet Network
Message-ID: <20261123212623.106153-8-dsahern@kernel.org>
References: <20261123212623.106153-1-dsahern@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3988838"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:coyeF5bwQTXLOBWvqKv21UX87WQ= sha256:jnzrcYdty0qSejQaCuwpW5oWC/hfsMTJs7UQoRgdoZU=
	sha1:ITlOAumpewfJLfzpFw9Z/imOFxw= sha256:n5bQc2CrD06vvZ9upB7BtZYtU7SYkgRlYcBByDPb81M=
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 C75FC125DB9; Tue, 24 Nov 2026 00:27:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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 (2048-bit key)
	header.d=kernel.org
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 Q59hMTfpLJqX;
	Tue, 24 Nov 2026 00:27:11 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369784-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id A8010125DC1; Tue, 24 Nov 2026 00:27:02 +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 E5CE73A435; Mon, 23 Nov 2026 21:26:41 +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=1795469194;
	b=jOA0f5u4EBj8QGgzOi7KAMRVxX15dJzEeTUoRKdaKELhBbnzp1x4hkppgw6ITtg2+EOH
	 /itWZm9JOAwltOA1FhZA4WTZEGaBX3CF+8D9z0DQtfisvOC/oabrE9wPGCPTqiGMmA5UH
	 xLN3eXUfenrsh9qs0sAjvJECJ/tOCLoM5PyTfYD0J+ClOAFUy0i8yE6ZLRxybkmwccXeJ
	 GsMrG/u5R2dPQC5fLjrbg8W/tgYyfoAfSDJVmtID/aJngxARY/OHoPy+4g5ba0ntrsQFT
	 E44elVKWnTNNbYPz6usMafypyzlzta2EhsN3wvDhxIo8OZM/F98t39ouWy2HxAlP55A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795469194;
	h=X-Original-To:Received:Received:DKIM-Signature: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=eH6UgdbRC4ievYK3CDGA8FvcsT7J3AAFgSAyupKWwdQ=;
	b=QRSqg+0YAzkUEUsCKRMbULwmNowoG4y/pT1Dn7gx43dihRAZaQgrCwWw9ozz6Aj3QIiA
	 yIQBGsq9no/vv1q0olCj3ymMBRAE1ByibjtieyvbpZ8pJRq6JbCAAdBACGQ7VsMl4f8pX
	 p4V7E/8jU0rN2b66pJPglWJjCYgYh7v1If2ZZ0sXscGs3/nb+Mgkrl97XglI34nhaVgRV
	 5q/vNNUTvpKpShjTYxXbMjSrAzYh6EM6z2zqWhVspd4zHEJaTx0ypuuVP4Q+61+E4GY0j
	 kG83uOvSgo/oYlvIvllO+iDcGEHsDuncy+1YGf8KkxECEI5UJVeOZjVkEAR45hdeaDw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RYFLPbJu;
	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 800DD606A6B8;
	Mon, 23 Nov 2026 21:26:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RYFLPbJu
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795469193;
	b=afidhNJAyE1hooi+9pagXqVUBBDf2K1n+Qz985feTqFEw1c+ahYIGU1UK/D6UvLiLfoP
	 F2DktCbi1rQEihhJ1GRBqrNWC+pZFHw2/rgKz/mLjVjiA4XhdmVUKiGf2iLS+Hnc12YBt
	 uaZAThUTsua1ky0PULEYzW05P3qc/AKPydpe1wKxi9SUybzqczzxox6cWHTHWY0NTl3dY
	 bkIbSfbJVP2vIrnHWpJJkDdXKvtDFb/KTxXLwZ4/Y2qAGoNmgx/ViPjcfNIgna5ClGXON
	 6B9RPLKBJsuXNvitj0MkgtmeVh95MylQfd4VjXSSfq3XHl09DfgUpLpcFJsv8bWkNAQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795469193;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Transfer-Encoding;
	bh=eH6UgdbRC4ievYK3CDGA8FvcsT7J3AAFgSAyupKWwdQ=;
	b=K+3Ycz04hqylsm6DHi5fQWeB0d5VEShLdfgFDLaIyDGwESxLfi2sNH0903/yVNHHp3aS
	 f1gyBJ1KkoPpZoBcMJi8g1N/DRPHvJXLASPrqDSwWtLC+Ou4GWF8c/6lW7caH13ZeWZIu
	 uSEKNWvLqWInb6Se5l6I7G23TdI6aK+4YBvi9qXRbZw+e/Vhjfucnj94qF/oZs7JNZSlm
	 hSwp7M904oo5i4ZKFopUqz68Fwhyrym/axqVB/kisSc6J3tbb6zyBuy40W1SDcvLDR6OS
	 hAsRRuCWUNfZ9ercb3Re7a9yhIWUJPSHEaGJUYpAO6PulxGJnPydFyfvBZ4eTILppyA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RYFLPbJu;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A052D606A689
	for <netdev@vger.kernel.org>; Mon, 23 Nov 2026 21:26:33 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47D581F01566;
	Mon, 23 Nov 2026 21:26:33 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795469193;
	bh=eH6UgdbRC4ievYK3CDGA8FvcsT7J3AAFgSAyupKWwdQ=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=RYFLPbJuH9uS96aZVrzDMj5eU4/etaryCBfA7I5nln6CTJhjtgNu626AEDkA/Wnv3
	 EJdA7dWFAWki2JNGl1Fp/lEWArYNb7UYd8pZ/6ELLh4CLQlodI78Js8925IAMxMFqz
	 pDEEK36JMR7X4G4NrF6+qMMOCV/LWkRPtdmcZTkxQ/HvfULU4evbKy0VaHvsaC9n+s
	 4vz36kp0hsAVEOXsAaFfaIF60hh7rKoR3VfcXU9s4YjlDLiwo8wlauVXISr0YswiXE
	 ob4OxGoAYTG8JPNQal686l+4AS+7e8N5hbogyPob2g657AKOWPBVy1yIofP0J8FSbJ
	 IBDk0S7JQ9IZQ==
X-Cc: ralf@mandelbit.com,
	David Ahern <dahern@nvidia.com>
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261123212623.106153-1-dsahern@kernel.org>
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