Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Ralf Lici
Fri, 20 Nov 2026 09:36
[PATCH net-next v4 3/5] ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check
Author: Ralf Lici
Date: Fri, 20 Nov 2026 09:36
Date: Fri, 20 Nov 2026 09:36
44 lines
11004 bytes
11004 bytes
Dsts of routes using nexthop objects record the IPv6 generation at allocation in rt->sernum. ip6_dst_check validates them with rt6_is_valid, which compares rt->sernum with the current generation, and ignores the cookie supplied by the caller. If the generation advances between route selection and dst allocation, the dst records the new generation and passes rt6_is_valid although it was selected from the old state. A caller that sampled the generation before its lookup can detect this only if ip6_dst_check compares the cookie as well. Require the cookie to match rt->sernum. Existing callers obtain the cookie with rt6_get_cookie, which returns rt->sernum for these dsts, so their validation is unchanged. ip6_dst_lookup_flow_cookie, added in the next patch, returns the generation read before the lookup as the cookie for these dsts. Signed-off-by: Ralf Lici <ralf@mandelbit.com> Reviewed-by: Xia Yan <yanxia@cmss.chinamobile.com> --- New in v4 - Split out of v3 2/3 (David): https://lore.kernel.org/netdev/7af19082325ce83699c5fd82de4925e52ed7dff2.1794906743.git.ralf@mandelbit.com/ - Carry Xia's Reviewed-by from v3 2/3, the code is unchanged. net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 98e3ca0644ab..4c02c5168163 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; rcu_read_lock(); -- 2.56.0
Re: [PATCH net-next v4 3/5] ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check
Author: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 10:26
Date: Tue, 24 Nov 2026 10:26
91 lines
11379 bytes
11379 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads