From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Sat, 5 Dec 2026 19:21:01 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 972BF1F00A14; Sat, 5 Dec 2026 19:21:00 +0000 (UTC) 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== Subject: Re: [PATCH net-next v3 10/13] ipv6: stamp dsts with the generation sampled before the FIB lookup 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 Date: Sat, 05 Dec 2026 19:21:00 +0000 Message-ID: <179649846017.3148.16446573204933233638@kernel.org> In-Reply-To: <20261201174021.7211-11-dsahern@kernel.org> References: <20261201174021.7211-11-dsahern@kernel.org> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 > Signed-off-by: David Ahern [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