🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27483

Re: [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation sampled before the FIB lookup

#27483
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 19:21
228 lines
16506 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix relies on a premise that some writers break.
- [Medium] The patch only partly closes the cached-dst race it describes
  (a cached dst built or refreshed by a later lookup after a FIB change,…
- [Low] The commit fixes a user-visible bug (a dst built from the old FIB
  passes ip6_dst_check() "indefinitely") and has a Reported-by: Ralf…
- [Low] The comment in rt6_get_cookie() (include/net/ip6_fib.h) still
  says "sernum is the netns route generation the dst was created under".

--

ipv6: stamp dsts with the generation sampled before the FIB lookup

This patch samples the netns IPv6 route generation before the FIB walk,
carries it in struct fib6_result, and stamps dsts built from that result
with the sample instead of the generation at allocation time. Cached pcpu
and exception dsts whose stamp differs from the sample are marked stale.
Dsts returned by fib6_rule_lookup() whose stamp moved during a multi-table
lookup are marked stale too, so that ip6_dst_check() fails for them.

> Reported-by: Ralf Lici <ralf@mandelbit.com>
> Signed-off-by: David Ahern <dahern@nvidia.com>

[Severity: Low]
Should this carry a Fixes: tag, and a Closes: link for the report?

For nexthop-object pcpu routes, folding a post-lookup generation into the
stamp seems to predate this series. At the baseline,
rt6_make_pcpu_route() runs this after the FIB has been read:

    pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev));

That came in with commit 8f34e53b60b3 ("ipv6: Use global sernum for dst
validation with nexthop objects"). The fn_sernum cookie captured after
the lookup had the same window.

Other patches in this series name 8f34e53b60b3 in a Fixes: tag, for
example "ipv6: keep a superseded pcpu dst working until its holders
notice". Without a tag here, stable tooling may pick those up without
this one. checkpatch also warns when Reported-by: is not followed by
Closes:.

> diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
> index f39baf51bcc5d..31ffac7baf73e 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);
> +}

[Severity: High]
Do all writers bump the generation after the change is visible?

In net/ipv6/route.c, fib6_ifup() and fib6_ifdown() bump first. Only then
do they call rt6_multipath_rebalance(), which rewrites the
fib_nh_upper_bound values that multipath path selection reads:

net/ipv6/route.c:fib6_ifup() {
    ...
	rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags;
	fib6_update_sernum_upto_root(net, rt);
	rt6_multipath_rebalance(rt);
    ...
}

net/ipv6/route.c:fib6_ifdown() {
    ...
	case NETDEV_CHANGE:
		...
		rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
		fib6_update_sernum(net, rt);
		rt6_multipath_rebalance(rt);
		break;
    ...
}

The NETDEV_DOWN multipath case in fib6_ifdown() follows the same order
after rt6_multipath_nh_flags_set(). It then returns -2, so the siblings
are skipped and nothing bumps again after the rebalance.

fib6_select_path() reads the upper bounds with atomic_read() under RCU
only. rt6_score_route() does not reject RTNH_F_DEAD or RTNH_F_LINKDOWN
nexthops.

A lookup that runs between the bump and the rebalance could look like
this:

CPU1 (carrier loss)
addrconf_notify()
  rt6_sync_down_dev(dev, NETDEV_CHANGE)
    fib6_ifdown()
      fib_nh_flags |= RTNH_F_LINKDOWN
      fib6_update_sernum()           /* N -> N+1 */

CPU2
ip6_pol_route()
  fib6_table_lookup()
    rt_genid_ipv6_sample()           /* samples N+1 */
  fib6_select_path()                 /* reads old upper bounds */
  rt6_make_pcpu_route()              /* dst stamped N+1 */

CPU1
      rt6_multipath_rebalance()

With ignore_routes_with_linkdown set, could CPU2 pick the nexthop that
just went linkdown and still get a dst stamped N+1?

The new check at the out: label in ip6_pol_route() would not catch this,
and neither would fib6_rule_lookup_done(), because the stamp equals the
sample. For carrier changes, no later bump follows. Sockets and
dst_caches that captured the dst in that window would keep using the
linkdown nexthop until some unrelated FIB change in the netns.

Could the bump move after rt6_multipath_rebalance() at these sites? If
not, should the commit message and this comment stop claiming the
ordering holds for all writers?

[ ... ]

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 959157896f980..8df141363e128 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1214,6 +1214,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;
> +

[Severity: Low]
This isn't a bug, but the comment in rt6_get_cookie() in
include/net/ip6_fib.h still describes the old meaning:

static inline u32 rt6_get_cookie(const struct rt6_info *rt)
{
	/* sernum is the netns route generation the dst was created under;
	 * ip6_dst_check() compares it to the current one.
	 */
	return READ_ONCE(rt->sernum);
}

With this override, sernum is the generation sampled before the FIB
walk. For exceptions built in __ip6_rt_update_pmtu() and
rt6_do_redirect(), it is the parent dst's generation, which can be older
than the one current at creation.

The RT6_SERNUM_STALE comment in the same header already says "the
generation it was built under". Should the rt6_get_cookie() comment be
updated to match?

> @@ -1299,6 +1305,7 @@ INDIRECT_CALLABLE_SCOPE struct rt6_info *ip6_pol_route_lookup(struct net *net,
>  	bool retry = false;
>  
>  	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);

[Severity: Medium]
Is the cached-dst race covered here when CONFIG_IPV6_MULTIPLE_TABLES is
not set?

ip6_pol_route() gets its own stamp-versus-sample check at its out:
label. ip6_pol_route_lookup() returns a cached exception without one:

	rt = rt6_find_cached_rt_refresh(&res, &fl6->daddr, &fl6->saddr,
					&retry);
	if (rt) {
		if (ip6_hold_safe(net, &rt))
			dst_use_noref(&rt->dst, jiffies);

This path depends on fib6_rule_lookup_done() in net/ipv6/fib6_rules.c.
That file is only built with CONFIG_IPV6_MULTIPLE_TABLES:

    ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o

Without that option, fib6_rule_lookup() is the unchanged version in
net/ipv6/ip6_fib.c. It calls pol_lookup_func() on the main table and
returns &rt->dst with no sample and no check.

In that configuration, another CPU can refresh an exception after a FIB
change. __rt6_find_cached_rt() accepts it through rt6_is_valid(), and it
is returned with the newer stamp even though this lookup's decision
predates the change.

__ip6_route_redirect() appears to have the same gap. An exception found
through ip6_redirect_nh_match() is returned unchecked via
ip6_hold_safe(net, &ret). rt6_do_redirect() then copies its stamp into
the new redirect exception with res.sernum = rt6_dst_sernum(rt).

Would the check from ip6_pol_route() close this if it were added to
ip6_pol_route_lookup() and __ip6_route_redirect(), or to the ip6_fib.c
version of fib6_rule_lookup()?

	if (rt && rt6_dst_sernum(rt) != res.sernum)
		rt6_dst_invalidate(rt);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org
Technical Details
Message-ID: <179649846017.3148.16446573204933233638@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378107-linux-kernel-netdev=dewy.ru
References: <20261201174021.7211-11-dsahern@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378107-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation
 sampled before the FIB lookup
Date: Sat, 05 Dec 2026 19:21:00 +0000
Organization: Usenet Network
Message-ID: <179649846017.3148.16446573204933233638@kernel.org>
References: <20261201174021.7211-11-dsahern@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3103541"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:MAzqjUjc/eRAw6PKC6ybQgqo0/I= sha256:3cb1ukkxSRjSwWZvU2R2yCZZwi5mwXkiSSTucVJAZA4=
	sha1:/DzET1nIGz0T2CWnKvA9vUL3aUY= sha256:T4QycVSSFarszm//tBcu37hSL3i2MKZ+eEQtCpUyWGo=
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 247A8117E97; Sat,  5 Dec 2026 22:21:31 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.539
X-Spam-Status: No, score=-3.539 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, 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, URIBL_BLOCKED=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 yfAYjoLNr8_K;
	Sat,  5 Dec 2026 22:21:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-378107-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 C61B9117E98; Sat,  5 Dec 2026 22:21:19 +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 7A0CB32482; Sat,  5 Dec 2026 19:21:02 +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=1796498462;
	b=YbU0ghbc5aaeqFNYvc+ANjIiqlZ8hODAi8TP633Y3XQiBvfsvy25DkKxgBmJc7Yxxjcs
	 f2IN5NdyWrTbGzQ64jI8iTACe8hLas2fyt66EcjN1fM1Vh7BuVAX9VV/USVgTDUlLeXYS
	 JFs8fknYakIhACgkpsNuq//CqTe7wNGoQ+yUUnvvS4mr4+7YIJh/pDHi8f3NwD5VIFkKh
	 dalDug0uubklUnELOMVg475ynqmYmk+wHNbdLZFg2xxKVC4xgctxundJixptUzp7XDZfX
	 ANV+O6rv3Xar6VDbOfxV7m2wS9+wHd3/ssDGJtORj9JERqtKJKr1yR6RzuSQA6U6kuA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796498462;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=kpz8q2ZjFGu6aVZDPzGhsxRUyFxgxTfVmldbUK3C728=;
	b=X1J+hmWnXnJTXQyWIoMbbhTlb/Sx4Qr2FI0p6KWGPf0wEm8i0qfMmD658MGBlgvczmQV
	 QMyYOrayDMi9NKJyAYP2TlAQULM5M9JRyMG0vebD5qe8oyTmoWMLit6XtN31l3mue4AB2
	 aLNJhkj1WBxtM9nodgJT7kLt/GIwMy6L/AzK3yVQRKOywn4XydnfnG/Ka3IvW/cw2rxeA
	 dYcrUK0/tbZFsgIrVNCqu6Amz68FH5YXtUvZAbeAZ282/XCHBA5zaP4ck9mxdXFt3GYcd
	 lQq6fTQmkAPXHWWPn+ktZk7xiHuOFmnBn35ntUllXyRF0FSdI1RuWIL8EAibXKaKloQ==
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=hhuJAHUX;
	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 51FA1606A330;
	Sat,  5 Dec 2026 19:21:02 +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=hhuJAHUX
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=1796498461;
	b=414GQLldm3bOceotmKeainjgsO25iE+Nwjfmlp3aZy8gqMCH3ggXJ5M1GmSdmugg3RB0
	 VQ+zVpLnwESDPmHxx6ARU0yTgWwb6nWd4RC/wwW5hVmDBdShjNOfisAD8R4RhpfOW/ZN9
	 bojOXCtJKjje7gpF3fQTS2qbz5N76J518jZDmuBJKU4n/BO2dbs7ew/0IHwEyjIxVgNuM
	 SdcS/5sUtQm9SeitPVXEHGJt385cugv+0p76UuyIyYBvDLXepsna/9NxCg+q7IcieKVWF
	 GkzDdCfZsVajQ6LRj3GD6ioI4MwzM1OjejMrByC3+0fp4u13eOMxuts77g3fZ5bC4aA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796498461;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=kpz8q2ZjFGu6aVZDPzGhsxRUyFxgxTfVmldbUK3C728=;
	b=BlezUbifwPkWTGRrMq+oybj2i4MUO/TLFyQ0/xg/3t+qY5R/LVmmYWpAtXn6xnWz5yK7
	 8lWvvs7GSiuYMMmAMMKTHddqEyTfhGwJdmmlhX6LgVvaHqFQJuCjWB4HBhDYiaJj+t7w5
	 MJGW3GGRK3tOr+xnMuORxk7hj2+3WTMghRIiOTN4TIuKfZjCeGr7caHDVicJCFi25FvMt
	 JIVplvKKr5LFfGJq2aVDz9lGzahyLBKqcvqvAuF4TisYYSOKDM8UOYYWg7orjHZWeoPjO
	 5Y6xP10gRQDoWbce7YonxEzjLg+oUspWX/Vls8AaY4n7iY1+3Qrw6VONEjv4vicmkWg==
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=hhuJAHUX;
	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 744D0606A332
	for <netdev@vger.kernel.org>; Sat,  5 Dec 2026 19:21:01 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 972BF1F00A14;
	Sat,  5 Dec 2026 19:21:00 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796498461;
	bh=kpz8q2ZjFGu6aVZDPzGhsxRUyFxgxTfVmldbUK3C728=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=hhuJAHUX43PPGa/2c16V04RT8g5Ve5204u1LbZHFrUiJcUSJUEW/rTz7x9GWWt1NQ
	 O34RrsRxve1pdE5Hl5YU2KMZ6rccu364AYA3mFR9aRRMsbKnO2aFkawG7q3/CJ3U1N
	 bFStrj5gUUlk+bpLUI+ocHeT8scQ8djR6RkiIVUp9lk3QwfeGCg+BV82M22cSeJIrG
	 xOKVPdH0JX83U1kNFI0fQFPV/uObW2Nl4L8A7/ZIgDQtUDDRy1Gq1rtO4MIHFBlF68
	 OCH37xz6hxi2dl5fCGzwipeHXY9DL6haQVrdcsObupw/6uKP/oQqSDAFG/5BIzyB5X
	 7IkSazspVYbpQ==
X-Cc: netdev@vger.kernel.org, idosch@nvidia.com, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
 ralf@mandelbit.com, ja@ssi.bg, dahern@nvidia.com, noreply@anthropic.com
X-In-Reply-To: <20261201174021.7211-11-dsahern@kernel.org>
X-sashiko-severity: High
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