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=1796498457; b=2NCDF5yiwLXTaXISqTF4w6csYCGar3NeBJLMyFBT7fgcQAkDD2I6J4kXjceeuOD+CrEJ LHf7sxePAHU3m3+SOWQ3jeEbJ/VjbCcLaXdzn5GQhNEI4wfRDKj9372TCW6fVxk+w3iYo tX2Z0S7AJMP0M8t38+8z8r4AMtCmZLXTI64oHW9s/JwytR4lIjhUuVwH62d3Z/SL3Xv4z QWOl4B62h01tTDCfSz4wsOq5Pn3Qs0DPLmYdxDHE4pY6t26yZsdrznuqAUOBxYF7GXD2i nToddWgvbDWvZjqDQRZkKwwDN3KZlwRcaRtnz10kC8qbdvLyCv7ab2DyVlnpbQGrykQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796498457; 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=tz0sDuhAxLaEc6+Kpcr6Ne2UqTRRr9ci5DSpl5g/aSY=; b=pbWkUUm68E5l8dMh8MQpXKqyMM+U9A+joYFskLEADrEZNE0HlkHRI69Lkt+0NBguglDv ZkDEeQytERB4o0Ak8gU3/D4bevBaa2jYhCuCOCsfGLPz5zK4bVjlLLJrV6r/ENGrUve8L OhfkTpXo3J/fTuap37HK5RdhFBB13A+DYDkdrpCR9xTcmPdlhwxwFDRt8lfwBxQZMM7ch tI7ZQoHcwzmz+gT/pF+ZV+NKuVg3KAGznzx9hYtWjbHRXSDqMcLJdqLTlr0X9cK/FFcQA ZvaM1UVp1hfFv5x2KBfuLMVUc3AVsQSNUQMER8eJQ3NwUUyppplK08Ef9SZ7G6IcfCA== 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="WwM7I/2f"; 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 B1E65606A332 for ; Sat, 5 Dec 2026 19:20:57 +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=WwM7I/2f Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2B6C1F00936; Sat, 5 Dec 2026 19:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796498457; bh=tz0sDuhAxLaEc6+Kpcr6Ne2UqTRRr9ci5DSpl5g/aSY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=WwM7I/2foJGzz1/pMTDz/2FiJ8O12K5GaIyvdWnX//RddpkiJJOpUJc5k+/SoGDio 2qiqIiPSB6NXV3qKXuRnQYup8OapMkCQj2h+s6tlQ/W/CD0Dqvo8R+6A1Qre+9786v 8wdYX8R305isKgC8HgNVC34sl17LleaseNoOLUp5XDrMG7pzGGZsOtQKzjZCqftBx4 /LZOJI2uCqfcWYY4TVtRH27PSwBIvi3YZD/hSBOLP3lsaS/04BlxSVp/CqMkVAgjCL ACL0B3r4dl3uOqoXTRSFmMosJBPkz0mbuUrAVAcLHF7OvMLnwd4g6R/KKw2t2I04dq H/TZmsXKk6Czw== Subject: Re: [PATCH net-next v3 06/13] ipv6: validate dsts against the netns route generation 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:20:56 +0000 Message-ID: <179649845641.3148.13879014332504224921@kernel.org> In-Reply-To: <20261201174021.7211-7-dsahern@kernel.org> References: <20261201174021.7211-7-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 13 potential issue(s) to consider. Critical: 0 · High: 4 · Medium: 4 · Low: 5 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] Use-after-free (RCU NOREF lifetime): the fix is incomplete. - [High] ipv6: unguarded dst->dev access in ip6_dst_check() and rt6_is_valid() - [High] ipv6: refcount underflow via rt6_uncached_list_add() on published dsts - [High] ipv6: orphaned pcpu dst after route deletion in rt6_get_pcpu_route() - [Medium] With nexthop objects, a refresh changes which route owns an exception without putting the new owner on the GC list. - [Medium] With CONFIG_IPV6_SUBTREES, rt6_uncached_clone_superseded() cannot find PMTU exceptions for FLOWI_FLAG_KNOWN_NH clones of source-… - [Medium] The rule that a lowered PMTU is not lost to a refresh depends on the in-place updater reaching fib6_nh_update_exception(), whose… - [Medium] ipv6: lost RTF_EXPIRES on refresh race in __rt6_insert_exception() - [Low] Process: the commit fixes a reported, user-visible bug (Reported- by: Ralf Lici; a stale dst passes revalidation because the cookie was… - [Low] The comment in __rt6_find_cached_rt() says callers that hand the exception to users as their dst must pass @stale, so a stale exception… - [Low] After hlist_replace_rcu() in __rt6_insert_exception(), the comment says 'Only a change since the copy is merged, so the PMTU a… - [Low] The commit says the merge 'lowers the expiry the same way' as the lockless handler, so that 'a smaller value stored by one is kept… - [Low] Race in the pcpu-dirty handshake on PREEMPT_RT. -- ipv6: validate dsts against the netns route generation This commit stamps every IPv6 dst with the netns route generation when it is allocated, and ip6_dst_check() validates it with a plain comparison instead of the fn_sernum based cookie. On lookup, a stale exception is replaced by a current copy, and an exception insert now invalidates only the nexthop's pcpu dsts, which are tracked with a new per-nexthop cpumask. When a pcpu slot or the exception table gives up a dst, its reference is dropped after an RCU grace period. > diff --git a/net/ipv6/route.c b/net/ipv6/route.c > index 836bd7aa05cd7..959157896f980 100644 > --- a/net/ipv6/route.c > +++ b/net/ipv6/route.c [ ... ] > @@ -1523,6 +1557,13 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net, > return prev; > } > > + /* Tell fib6_nh_invalidate_pcpu() there is a dst to invalidate on this > + * CPU. The cmpxchg() above orders the install before the mark. > + */ > + cpumask_set_cpu(smp_processor_id(), res->nh->rt6i_pcpu_dirty); > + /* Order the mark before the exception re-check in ip6_pol_route() */ > + smp_mb__after_atomic(); > + [Severity: Low] On PREEMPT_RT, can another task on this CPU use the new pcpu dst between the cmpxchg() and cpumask_set_cpu()? The WARN_ON_ONCE() above already says preemption is possible here. Task A installs D and is preempted before it sets its bit. Task C on the same CPU misses the exception, which is not published yet, and gets D from rt6_get_pcpu_route() without the re-check. The writer then publishes the exception, does smp_mb() and scans rt6i_pcpu_dirty. It finds the bit clear and leaves D valid for C's holder. Also, when the cmpxchg() fails, rt6_make_pcpu_route() returns prev without setting the mark or issuing the barrier. [ ... ] > @@ -1749,18 +1790,163 @@ struct rt6_exception_bucket *fib6_nh_get_excptn_bucket(const struct fib6_nh *nh, [ ... ] > +static void rt6_exception_merge(struct rt6_info *cur, const struct rt6_info *rt) > +{ > + u32 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); [ ... ] > + /* As dst_set_expires() does, never extend an expiry */ > + if (rt->rt6i_flags & RTF_EXPIRES) { > + unsigned long expires = READ_ONCE(rt->dst.expires); > + unsigned long old = READ_ONCE(cur->dst.expires); > + > + do { > + if (old && !time_before(expires, old)) > + break; > + } while (!try_cmpxchg(&cur->dst.expires, &old, expires)); > + > + cur->rt6i_flags |= RTF_EXPIRES; > + } > + cur->rt6i_flags |= rt->rt6i_flags & RTF_MODIFIED; > +} [Severity: Low] The commit message says the merge lowers the expiry the same way the in-place handler does, so a smaller value is kept whichever order they run in. Is that accurate for the expiry? This code uses try_cmpxchg(). The lockless path, rt6_do_update_pmtu() -> rt6_update_expires() -> dst_set_expires(), checks and then does a plain store: old = READ_ONCE(dst->expires); if (!old || time_before(expires, old)) WRITE_ONCE(dst->expires, expires); A handler that read the value before this cmpxchg can overwrite the earlier expiry with a later one. When RTF_EXPIRES is not yet set, rt6_update_expires() can also store from->expires unconditionally. rt6i_flags is also changed with a plain |= in two places: here under rt6_exception_lock, and without the lock in rt6_do_update_pmtu() and rt6_update_expires(). Should those accesses be annotated or made atomic? [ ... ] > @@ -1790,27 +1981,88 @@ static int rt6_insert_exception(struct rt6_info *nrt, [ ... ] > if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) { > - err = -EINVAL; > - goto out; > - } [ ... ] > + if (old && (old->rt6i_flags & RTF_DYNAMIC)) { [ ... ] > + dst_metric_set(&nrt->dst, RTAX_MTU, res->f6i->fib6_pmtu); > + } else { > + /* A stale exception that no longer lowers anything > + * would fail every refresh from here on: drop it. > + */ > + if (old) > + rt6_remove_exception(old_bucket, rt6_ex); > + err = -EINVAL; > + goto out; > + } > } [Severity: High] Should rt6_remove_exception() also defer its release? It still does: hlist_del_rcu(&rt6_ex->hlist); dst_release(&rt6_ex->rt6i->dst); The commit message says that when a pcpu slot or the exception table gives up a dst, its reference is now dropped after a grace period. The reason given is that RT6_LOOKUP_F_DST_NOREF readers rely on RCU alone, and dst_destroy() releases an xfrm bundle's child with dst_release_immediate(). This new call on the refresh path drops a stale exception that lockless readers have just found. Every other path that unpublishes an exception goes through the same function: aging, rt6_exception_remove_oldest(), flushes, and replacement on a normal insert. Could this sequence free the exception while a reader is still using it? a NOREF reader in ip6_pol_route() finds exception E under RCU E is the child of xfrm bundle B, whose last reference is gone and whose dst_destroy_rcu() is already queued rt6_remove_exception() unlinks E and calls dst_release() on it B's grace period ends: dst_destroy(B) -> dst_release_immediate(E) the reader is still using E Would using rt6_dst_release_deferred() in rt6_remove_exception() close this? [ ... ] > + hlist_replace_rcu(&rt6_ex->hlist, &new_ex->hlist); > + > + /* An in-place PMTU update of old does not take the lock, and > + * one that saw old still in the table does not merge (see > + * fib6_nh_update_exception()). Pairs with smp_mb() there: > + * either it sees nrt and merges into it under the lock, or > + * this sees its update and merges it here. Only a change > + * since the copy is merged, so the PMTU a redirect copy > + * dropped above is not brought back. > + */ > + smp_mb(); > + if (dst_metric_raw(&old->dst, RTAX_MTU) != old_mtu || > + READ_ONCE(old->dst.expires) != old_expires) > + rt6_exception_merge(nrt, old); [Severity: Low] Does this match the comment that only a change since the copy is merged? If only old's expiry changed, rt6_exception_merge(nrt, old) still runs and merges old's whole MTU: u32 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); ... if (mtu) rt6_lower_mtu(cur, mtu); In the RTF_DYNAMIC branch above, nrt's MTU was just set to res->f6i->fib6_pmtu, which is usually 0. rt6_lower_mtu() treats 0 as no value, so old's MTU gets stored in the copy. rt6_do_update_pmtu() calls rt6_lower_mtu() and then rt6_update_expires(). Suppose a lockless update's MTU store lands before the snapshot and its expiry store lands after it. Wouldn't that bring back the PMTU the redirect branch meant to drop? > @@ -1828,10 +2080,14 @@ static int rt6_insert_exception(struct rt6_info *nrt, > out: > spin_unlock_bh(&rt6_exception_lock); > > - /* Update fn->fn_sernum to invalidate all cached dst */ > - if (!err) { > + /* new_ex is in the table on success only */ > + if (err) > + kfree(new_ex); > + > + if (!err && !old) { > + fib6_nh_invalidate_pcpu(nh); > + > spin_lock_bh(&f6i->fib6_table->tb6_lock); > - fib6_update_sernum(net, f6i); > fib6_update_excp_seq(f6i); > fib6_add_gc_list(f6i); > spin_unlock_bh(&f6i->fib6_table->tb6_lock); [Severity: Medium] With nexthop objects, can a refresh move an exception to a route that is not on the GC list? rt6_refresh_exception() builds nrt with ip6_rt_cache_alloc(res, ...), so nrt->from is res->f6i, the route this lookup selected. That can differ from old->from when two routes share a nexthop object. For example, A is a /32 that created the exception, and B is a more specific /48 added later, which bumps the generation and makes the exception stale. Because old is set, the refresh skips fib6_add_gc_list(f6i) here. If A is then deleted, fib6_nh_flush_exceptions(nh, A) removes only the entries whose from is A, so B's copy stays. A also leaves tb6_gc_hlist. Exceptions are aged only through routes on tb6_gc_hlist: fib6_gc_table() -> fib6_age() -> fib6_age_exceptions() Would the shared bucket stop being aged after that? A redirect exception would then never be removed by the lastuse timeout, or by the check in rt6_age_examine_exception() that the gateway is still a router. [ ... ] > @@ -1932,6 +2214,86 @@ static struct rt6_info *rt6_find_cached_rt(const struct fib6_result *res, [ ... ] > + err = __rt6_insert_exception(nrt, res, old); > + if (!err) > + return nrt; > + > + dst_release_immediate(&nrt->dst); > + > + /* @old was replaced or removed since we found it: use what is there > + * now, which is a miss if it was removed. > + */ > + if (err == -EEXIST) > + return __rt6_find_cached_rt(res, &old->rt6i_dst.addr, saddr, > + NULL); [Severity: Low] The comment in __rt6_find_cached_rt() says that callers which hand the exception to users as their dst pass @stale. Does this fallback follow that rule? It passes NULL, and the result goes back through rt6_find_cached_rt_refresh() to ip6_pol_route() and ip6_pol_route_lookup(), which both hand it out. The exception now in the table may itself be stale, for example a concurrent refresh's copy that was stamped before another generation bump. It would then be returned as is, with no refresh attempt and without *retry being set. [ ... ] > @@ -2035,9 +2412,31 @@ static void fib6_nh_update_exception(const struct fib6_nh *nh, int plen, > if (plen) > src_key = &rt->rt6i_src.addr; > #endif > + > + /* Order the update of @rt before the lookup, see above */ > + smp_mb(); > + [Severity: Medium] Does every in-place PMTU update reach this barrier? For nexthop-object routes, rt6_update_exception_stamp_rt() calls fib6_nh_update_exception() only when fib6_nh_find_match() matches: struct fib6_nh_match_arg arg = { .dev = rt->dst.dev, .gw = &rt->rt6i_gateway, }; nexthop_for_each_fib6_nh(from->nh, fib6_nh_find_match, &arg); if (!arg.match) goto unlock; .gw is never NULL, so fib6_nh_find_match() rejects gateway-less nexthops through (arg->gw && !nh->fib_nh_gw_family). A redirect exception whose gateway differs from the nexthop's gateway does not match either. In those cases the updater lowers old's MTU without the smp_mb(), the lookup or the merge. If that store lands after the post-swap re-read in __rt6_insert_exception(), the lower PMTU never reaches the copy. The commit message says "Either the updater finds the copy or the replacement sees the update, so the lower PMTU is not lost." How does that hold for these routes? [ ... ] > @@ -2837,16 +3258,89 @@ static struct dst_entry *rt6_check(struct rt6_info *rt, [ ... ] > +static bool rt6_uncached_clone_superseded(const struct rt6_info *rt, > + struct fib6_info *from) > +{ > + struct rt6_clone_nh_arg arg = { > + .rt = rt, > + .from = from, > + }; > + > +#ifdef CONFIG_IPV6_SUBTREES > + if (rt->rt6i_src.plen) > + arg.saddr = &rt->rt6i_src.addr; > +#endif [Severity: Medium] With CONFIG_IPV6_SUBTREES, can this find the PMTU exception for a FLOWI_FLAG_KNOWN_NH clone of a source-specific route? ip6_pol_route() makes the clone only for gateway-less nexthops, with ip6_rt_cache_alloc(&res, &fl6->daddr, NULL), so its rt6i_src stays the route's source prefix. PMTU exceptions on the same gateway-less nexthop get the flow's source address in ip6_rt_cache_alloc(), and are keyed by it: if (rt->rt6i_src.plen && saddr) { rt->rt6i_src.addr = *saddr; rt->rt6i_src.plen = 128; } Here arg.saddr is the prefix. __rt6_find_cached_rt() falls back to &f6i->fib6_src.addr, which is the same value, so both lookups miss and ip6_dst_check() keeps passing the clone. Before this patch, every exception insert called fib6_update_sernum(), which invalidated such clones through the cookie. Is this a regression for IPVS dest->dst_cache holders in that configuration? The commit message says ip6_dst_check() fails an uncached RTF_CACHE dst "when its nexthop has an exception for the dst's destination". That would not hold here. [ ... ] > @@ -3808,7 +4319,7 @@ void fib6_nh_release_dsts(struct fib6_nh *fib6_nh) > pcpu_rt = xchg(ppcpu_rt, NULL); > if (pcpu_rt) { > dst_dev_put(&pcpu_rt->dst); > - dst_release(&pcpu_rt->dst); > + rt6_dst_release_deferred(pcpu_rt); > } > } > } [Severity: Low] This looks like a separate fix for an existing use-after-free. Before this patch, fib6_nh_release_dsts() called dst_dev_put() and then dropped the reference immediately, which is open to the same NOREF reader and xfrm child problem. Could it go into its own patch with a Fixes: tag, so that stable can take it without this ~600-line redesign? Also, the commit has "Reported-by: Ralf Lici " but no Fixes: or Closes: tag, while the earlier fix patches in the series have them. Should one be added here? [ ... ] > @@ -2856,8 +3350,11 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst, > > rt = dst_rt6_info(dst); > > - if (READ_ONCE(rt->sernum)) > - return rt6_is_valid(rt) ? dst : NULL; > + /* Any FIB change bumps the netns generation, which invalidates > + * every dst created under an older one. > + */ > + if (!rt6_is_valid(rt)) > + return NULL; > > rcu_read_lock(); > [Severity: High] Can this read rt->dst.dev after the device is gone? ip6_dst_check() now calls rt6_is_valid() for every IPv6 dst, and it does so before the rcu_read_lock() below. rt6_is_valid() does dev_net(rt6->dst.dev) and then reads the netns generation, without dst_dev_rcu() or dst_dev_net_rcu(). Some callers run in preemptible process context without RCU held: sk_dst_check() in ip6_sk_dst_lookup_flow(), and __sk_dst_check() in inet6_csk_xmit() and inet6_sk_rebuild_header(). With this patch, retired pcpu dsts and replaced exceptions stay on the uncached list while sockets still hold them. On unregister, rt6_uncached_list_flush_dev() or dst_dev_put() points dst->dev at blackhole_netdev and drops the reference on the old device. A task preempted after loading rt->dst.dev could then dereference a freed net_device. The same applies to dev->nd_net when the device moves to another netns. The old code had the same unprotected read, but only for nexthop-object pcpu dsts. Now it covers every dst. Should the generation check move under the rcu_read_lock() and use dst_dev_net_rcu()? Or should rt6_is_valid() take the lock itself? [ ... ] > @@ -1790,27 +1981,88 @@ static int rt6_insert_exception(struct rt6_info *nrt, > if (f6i->fib6_src.plen) > src_key = &nrt->rt6i_src.addr; > #endif > + if (old) { > + old_bucket = bucket; > + rt6_ex = __rt6_find_exception_spinlock(&old_bucket, > + &nrt->rt6i_dst.addr, > + src_key); > + if (!rt6_ex || rt6_ex->rt6i != old) { > + err = -EEXIST; > + goto out; > + } > + /* Before the copy: an in-place update of old that lands in > + * between is then both in the copy and seen as a change after > + * the swap, which merges it again, harmlessly. > + */ > + old_mtu = dst_metric_raw(&old->dst, RTAX_MTU); > + old_expires = READ_ONCE(old->dst.expires); [Severity: Medium] Can a refresh racing with rt6_do_update_pmtu() publish a copy that has the lower PMTU but no expiry? Take an exception that does not have RTF_EXPIRES yet, such as a redirect. rt6_update_expires() writes dst.expires through dst_set_expires() first, and only afterwards sets RTF_EXPIRES in rt6i_flags. Consider this ordering: - The MTU and the expiry are already stored on old when old_mtu and old_expires are sampled here. - RTF_EXPIRES is not yet set when rt6_exception_copy_state() reads old->rt6i_flags. nrt then gets the lower MTU and RTF_MODIFIED, but no RTF_EXPIRES and an expires of 0. If the updater's lockless lookup in fib6_nh_update_exception() still sees old in the table, it only refreshes the stamp. After the swap and smp_mb(), the re-check compares only the MTU and expires against the samples. Those have not changed, so rt6_exception_merge() is skipped. The published copy then keeps the learned PMTU and never expires it after ip6_rt_mtu_expires, for as long as the exception stays in use. Should old->rt6i_flags & RTF_EXPIRES be sampled together with old_mtu and old_expires, and also be compared after the swap? > + err = rt6_exception_copy_state(nrt, old); > + if (err) > + goto out; > + } > + > /* rt6_mtu_change() might lower mtu on f6i. > * Only insert this exception route if its mtu > * is less than f6i's mtu value. > */ > if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) { > - err = -EINVAL; > - goto out; > - } > - > - /* Allocate the new entry before the one it replaces is touched, so > - * that running out of memory leaves what was learned in place. > - */ > - new_ex = kzalloc_obj(*new_ex, GFP_ATOMIC); > - if (!new_ex) { > - err = -ENOMEM; > - goto out; > + if (old && (old->rt6i_flags & RTF_DYNAMIC)) { > + /* A redirect whose PMTU was lowered in place and has > + * since stopped lowering anything, e.g. after a device > + * MTU change: the gateway is still worth keeping. Forget > + * only the PMTU and carry the route's own MTU, as a new > + * redirect exception would. The metrics are writable > + * already (rt6_exception_copy_state()), so this cannot > + * fail. > + */ > + dst_metric_set(&nrt->dst, RTAX_MTU, res->f6i->fib6_pmtu); > + } else { > + /* A stale exception that no longer lowers anything > + * would fail every refresh from here on: drop it. > + */ > + if (old) > + rt6_remove_exception(old_bucket, rt6_ex); > + err = -EINVAL; > + goto out; > + } > } > > new_ex->rt6i = nrt; > new_ex->stamp = jiffies; > > + if (old) { > + /* rt6_ex, found above, is old's entry. Swap in place: lockless > + * lookups see either the old or the new exception and never > + * a gap in which they would miss it and build a pcpu dst that > + * ignores it, nothing invalidates pcpu dsts for a refresh, and > + * the position in the chain, which route dumps count, and the > + * depth do not change. > + * > + * Holders of old find out that it is stale when they next > + * check it, so keep it working rather than dst_dev_put() it. > + * Device unregister detaches it like any other uncached dst. > + */ > + hlist_replace_rcu(&rt6_ex->hlist, &new_ex->hlist); > + > + /* An in-place PMTU update of old does not take the lock, and > + * one that saw old still in the table does not merge (see > + * fib6_nh_update_exception()). Pairs with smp_mb() there: > + * either it sees nrt and merges into it under the lock, or > + * this sees its update and merges it here. Only a change > + * since the copy is merged, so the PMTU a redirect copy > + * dropped above is not brought back. > + */ > + smp_mb(); > + if (dst_metric_raw(&old->dst, RTAX_MTU) != old_mtu || > + READ_ONCE(old->dst.expires) != old_expires) > + rt6_exception_merge(nrt, old); > + > + rt6_uncached_list_add(old); > + rt6_dst_release_deferred(old); > + kfree_rcu(rt6_ex, rcu); > + goto out; > + } > + > rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr, > src_key); > if (rt6_ex) [Severity: High] Can this make a NOREF caller think it holds a reference it never took? Before this series, the only dst ip6_pol_route() returned with rt_uncached_list set was the FLOWI_FLAG_KNOWN_NH clone. That clone always comes with a reference, even under RT6_LOOKUP_F_DST_NOREF. Callers rely on this and use rt_uncached_list to tell whether they own one: ip6_route_output_flags() skips dst_hold_safe() when it is set ip6_rt_put_flags(), used by fib6_rule_lookup() and the fib6 rule actions, calls ip6_rt_put() when it is set seg6_lookup_any_nexthop() uses skb_dst_set() instead of skb_dst_set_noref() when it is set old was in the exception table until the swap above. Lockless lookups on other CPUs may have just returned it without taking a reference: CPU0: NOREF lookup in ip6_pol_route() returns exception E CPU1: refresh swaps in the copy, rt6_uncached_list_add(E), rt6_dst_release_deferred(E) CPU0: ip6_route_output_flags() sees rt_uncached_list set, skips dst_hold_safe() and returns E as if it held a reference The caller then releases E, and the deferred release drops the table's reference. The refcount underflows and E is freed while it is still in use. ip6_rt_put_flags() and seg6_lookup_any_nexthop() have the same problem. The stale pcpu dst that rt6_get_pcpu_route() retires is put on the uncached list in the same way. Should the lookup report ownership directly, rather than callers inferring it from rt_uncached_list afterwards? Or should a dst that was published in a pcpu slot or the exception table be tracked for device unregister in some other way? [ ... ] > @@ -1476,7 +1506,11 @@ static struct rt6_info *rt6_get_pcpu_route(const struct fib6_result *res) > > pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu); > > - if (pcpu_rt && READ_ONCE(pcpu_rt->sernum) && !rt6_is_valid(pcpu_rt)) { > + /* A dst stamped with an older genid stays stale for everyone still > + * holding it, as in IPv4. Never re-stamp it; drop it and build a > + * new one. > + */ > + if (pcpu_rt && !rt6_is_valid(pcpu_rt)) { > struct rt6_info *prev, **p; > > p = this_cpu_ptr(res->nh->rt6i_pcpu); [Severity: High] With nexthop objects, can rt6_get_pcpu_route() keep returning a pcpu dst whose from has been cleared? When a route that uses a shared nexthop object is deleted, __fib6_drop_pcpu_from() clears pcpu_rt->from with xchg() on the nexthop's pcpu dsts that came from it. It leaves them in rt6i_pcpu and does not touch their sernum. rt6_make_pcpu_route() does the same when it races with fib6_destroying. As far as I can see, fib6_del_route() does not bump net->ipv6.fib6_sernum either. So rt6_is_valid() still passes. Lookups of the other route sharing the nexthop keep getting that dst from the slot. Before this patch, ip6_dst_check() returned early for such dsts on the generation alone. Now it falls through to rt6_check(rt, NULL), which fails on every call. Sockets and dst_cache users then look the route up again for every packet and get the same dst back. In addition, __ip6_rt_update_pmtu() and rt6_do_redirect() bail out on a NULL from, and RTM_GETROUTE for the destination fails with -ENETUNREACH. Should rt6_get_pcpu_route() also treat a NULL from as stale? Or should __fib6_drop_pcpu_from() mark the dsts it orphans with rt6_dst_invalidate()? Relatedly, the commit message says every FIB change bumps the netns generation. Does that hold for deletes? Two cases look like it does not: - Removing an ECMP sibling rebalances the remaining siblings in rt6_multipath_rebalance(). - Removing an RTN_THROW route changes which table a lookup ends in. In both cases the dsts of the surviving routes keep a valid stamp and a non-NULL fib6_node. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201174021.7211-1-dsahern%40kernel.org