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 Reviewed-by: Xia Yan --- 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