Re: [PATCH net-next v4 3/5] ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check

From: netdev-bot+sashiko

Date: Tue Nov 24 2026 - 05:27:08 EST


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In net/ipv6/route.c, ip6_dst_check() (lines 2821-2822) now
returns a nexthop-object per-CPU dst (rt->sernum != 0) only if `cookie…

--

ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check

This patch makes ip6_dst_check() compare the cookie passed by the caller
with rt->sernum for dsts of nexthop-object routes. Before, it only checked
rt->sernum against the current IPv6 generation. The commit message says
existing callers are unaffected because rt6_get_cookie() returns
rt->sernum for these dsts.

> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 98e3ca0644ab9..4c02c5168163c 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -2819,7 +2819,7 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
> rt = dst_rt6_info(dst);
>
> if (rt->sernum)
> - return rt6_is_valid(rt) ? dst : NULL;
> + return (rt6_is_valid(rt) && cookie == rt->sernum) ? dst : NULL;

[Severity: Low]
Is "their validation is unchanged" true for the IPv6 UDP rx dst cache?
Until now the cookie was ignored for these dsts, so a cached dst and its
cookie could come from different lookups without any effect. With this
check they have to match.

In udp6_sk_rx_dst_set(), the dst and the cookie are written separately:

net/ipv6/udp.c:udp6_sk_rx_dst_set() {
if (udp_sk_rx_dst_set(sk, dst))
sk->sk_rx_dst_cookie = rt6_get_cookie(dst_rt6_info(dst));
}

udp_sk_rx_dst_set() updates only the pointer, using xchg(). Nothing
serializes softirq writers running on different CPUs, so this ordering
looks possible:

CPU A
xchg(sk_rx_dst, dst1) dst1->sernum == g1
IPv6 generation moves to g2
CPU B
xchg(sk_rx_dst, dst2) dst2->sernum == g2
sk_rx_dst_cookie = g2
CPU A
sk_rx_dst_cookie = g1

The socket now holds dst2 with cookie g1. After that, every call to
udp_v6_early_demux() fails:

dst = dst_check(dst, sk->sk_rx_dst_cookie);

rt6_is_valid(dst2) is true, but g1 != g2. udp_v6_early_demux() does not
clear sk_rx_dst when this check fails.

The full input lookup on CPU B then returns the same per-CPU dst2. So in
__udp6_lib_rcv() this condition is false:

if (unlikely(rcu_dereference(sk->sk_rx_dst) != dst))
udp6_sk_rx_dst_set(sk, dst);

That means the stale cookie is never corrected.

Could this leave early demux disabled for that socket on that CPU? Each
packet would pay for a full FIB lookup until the generation advances again
or a packet arrives on a CPU with a different per-CPU dst.

The window between the xchg() and the cookie store is short, but a hardirq
can stretch it. On PREEMPT_RT, softirqs run in threads, so preemption can
too. Later patches in the series do not touch this UDP rx path.

ip6_dst_store() has a similar split-store pattern. There, a failed
sk_dst_check() resets the cache, so it recovers. TCP rx dst writers are
serialized by the socket lock, so any mismatch there is only transient.

>
> rcu_read_lock();
>

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795166508.git.ralf%40mandelbit.com