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

From
Ralf Lici <ralf@mandelbit.com>
Date
2026-11-20 09:36:51
Also in
lkml
Reply to
Ralf Lici, 2026-11-20
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 <redacted>
---
New in v4
- Split out of v3 2/3 (David):
  https://lore.kernel.org/netdev/7af19082325ce83699c5fd82de4925e52ed7dff2.1794906743.git.ralf@mandelbit.com/ (local)
- 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
Thread (6 messages) 6 messages, 1 author, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help