All of lore.kernel.org
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: dsahern@kernel.org
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
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	[thread overview]
Message-ID: <179649846017.3148.16446573204933233638@kernel.org> (raw)
In-Reply-To: <20261201174021.7211-11-dsahern@kernel.org>

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

  reply	other threads:[~2026-12-05 19:21 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 17:40 [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 01/13] ipv6: allocate the exception entry before removing the one it replaces David Ahern
2026-12-02 16:02   ` Ido Schimmel
2026-12-01 17:40 ` [PATCH net-next v3 02/13] ipv6: keep a superseded pcpu dst working until its holders notice David Ahern
2026-12-02 16:19   ` Ido Schimmel
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 03/13] ipv6: don't insert a PMTU exception whose MTU could not be stored David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 04/13] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 05/13] ipv6: tell route dumps about exception inserts with a table sequence David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 07/13] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 08/13] nexthop: factor out nh_has_f6i() David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 09/13] nexthop: bump the IPv6 route generation on group changes David Ahern
2026-12-05 19:20   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation sampled before the FIB lookup David Ahern
2026-12-05 19:21   ` netdev-bot+sashiko [this message]
2026-12-01 17:40 ` [PATCH net-next v3 11/13] selftests: net: pmtu: check that a deleted cached exception stays deleted David Ahern
2026-12-01 17:40 ` [PATCH net-next v3 12/13] selftests: net: fib_tests: Add stale pcpu test David Ahern
2026-12-05 19:21   ` netdev-bot+sashiko
2026-12-01 17:40 ` [PATCH net-next v3 13/13] selftests: net: ipvs: check a PMTU learned after the DR route was cached David Ahern
2026-12-05 19:21   ` netdev-bot+sashiko
2026-12-01 17:43 ` [PATCH net-next v3 00/13] ipv6: validate cached dsts against the netns route generation netdev-bot+sinfo
2026-12-02  9:45 ` Ralf Lici
2026-12-03 15:34 ` Ido Schimmel
2026-12-03 15:44   ` David Ahern
2026-12-03 16:55   ` Ralf Lici
2026-12-03 17:16     ` Ido Schimmel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179649846017.3148.16446573204933233638@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=dahern@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=ja@ssi.bg \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=noreply@anthropic.com \
    --cc=pabeni@redhat.com \
    --cc=ralf@mandelbit.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.