Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 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). - [Medium] The compare-and-exchange protocol in rt6_lower_mtu() only protects against other PMTU handlers. -- ipv6: don't insert a PMTU exception whose MTU could not be stored This patch makes rt6_do_update_pmtu() allocate writable metrics up front and return an error if that fails. When it fails, a new exception is not inserted and an existing one does not get its stamp refreshed. It also adds rt6_lower_mtu(), which lowers RTAX_MTU with try_cmpxchg() so that a smaller value stored at the same time by another PMTU handler is kept.
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c > index 31ebcf6652166..06afb9d5dc2b1 100644 > --- a/net/ipv6/route.c > +++ b/net/ipv6/route.c > @@ -1546,6 +1546,34 @@ static struct net *rt6_exception_net(const struct rt6_info *rt) > return container_of(rt->dst.ops, struct net, ipv6.ip6_dst_ops); > } > > +/* Lower the MTU in the metrics of @rt to @mtu. > + * > + * A dst shares the read-only metrics of its route until it needs its own. > + * Allocating them can fail, and dst_metric_set() does not say: the PMTU would > + * be lost. > + * > + * Only ever lower it, and with a compare and exchange: PMTU handlers update a > + * dst in place without a lock, and each decides to lower the MTU from a value > + * it read earlier, so storing unconditionally could overwrite a smaller value > + * that another handler stored in between. > + */ > +static int rt6_lower_mtu(struct rt6_info *rt, u32 mtu) > +{ > + u32 *metrics = dst_metrics_write_ptr(&rt->dst); > + u32 old; > + > + if (!metrics) > + return -ENOMEM; > + > + old = READ_ONCE(metrics[RTAX_MTU - 1]); > + do { > + if (old && old <= mtu) > + break; > + } while (!try_cmpxchg(&metrics[RTAX_MTU - 1], &old, mtu));
[Severity: Medium] Does this fully deliver the "only ever goes down and a smaller value stored meanwhile is kept" guarantee from the commit message? Another writer of the same RTAX_MTU word on exception dsts was left unchanged. On NETDEV_CHANGEMTU, fib6_nh_mtu_change() takes only rt6_exception_lock and calls rt6_exceptions_update_pmtu(). That function first reads the current MTU, then does a plain store: net/ipv6/route.c:rt6_mtu_change_route_allowed() { u32 dmtu = dst6_mtu(&rt->dst); ... } net/ipv6/route.c:rt6_exceptions_update_pmtu() { ... if (dst_metric_raw(&entry->dst, RTAX_MTU) && rt6_mtu_change_route_allowed(idev, entry, mtu)) dst_metric_set(&entry->dst, RTAX_MTU, mtu); ... } dst_metric_set() ends up doing an unconditional "p[metric-1] = val;". The in-place path __ip6_rt_update_pmtu()->rt6_do_update_pmtu()-> rt6_lower_mtu() never takes rt6_exception_lock. So the two writers do not share a lock. Here is one example. An exception has PMTU 1500 and the device MTU is lowered to 1450: CPU1 (NETDEV_CHANGEMTU) rt6_exceptions_update_pmtu() rt6_mtu_change_route_allowed() dmtu = 1500, decides to store 1450 CPU0 (ICMPv6 Packet Too Big, 1280, same RTF_CACHE dst) __ip6_rt_update_pmtu() rt6_do_update_pmtu() rt6_lower_mtu() try_cmpxchg() 1500 -> 1280 rt6_update_exception_stamp_rt() CPU1 dst_metric_set(&entry->dst, RTAX_MTU, 1450) The 1280 just learned is replaced by 1450. Packets then exceed the path MTU until another Packet Too Big arrives. The same can happen when the device MTU is raised and dmtu == idev->cnf.mtu6. That looks like the overwrite the commit message describes, where "a handler that decided on 1400 overwrite a 1280 that another one stored in between". It also means a plain store races with READ_ONCE() and try_cmpxchg() on the same u32, which KCSAN may report. This still holds at the end of the series. The later commit "ipv6: validate dsts against the netns route generation" says the device MTU change path "is not covered by that". Its rt6_exception_merge() comment repeats the "neither overwrites what the other stored" guarantee, which this path does not honour. Could rt6_exceptions_update_pmtu() store conditionally instead? For example, it could try_cmpxchg() from the raw value it read, so the store only lands if nothing changed. Another option is to have both writers take the same lock.
> + > + return 0; > +} > +
[ ... ]
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40kernel.org