From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: ralf@mandelbit.com, David Ahern <dahern@nvidia.com>
Subject: [RFC net-next v2 0/7] ipv6: validate dsts against the netns route generation at lookup
Date: Mon, 23 Nov 2026 14:26:02 -0700 [thread overview]
Message-ID: <20261123212623.106153-1-dsahern@kernel.org> (raw)
From: David Ahern <dahern@nvidia.com>
IPv6 dsts are validated in ip6_dst_check() against a cookie that the holder
(socket, dst_cache, xfrm bundle, ...) samples from rt->from's fib6_node
(fn_sernum) when it stores the dst. That is later than the lookup that
produced the dst, which allows this sequence:
CPU0 CPU1
---- ----
lookup returns Dold
add a more-specific route (e.g. a
blackhole /128), bump fn_sernum
rt6_get_cookie(Dold) reads the new
fn_sernum
publish (Dold, new cookie)
The next dst_check() compares the cookie with the same node's current
fn_sernum and accepts Dold, which keeps bypassing the more-specific route
indefinitely. The same late sampling exists in every persistent cache
(socket TX/RX, xfrm, dst_cache users, SCTP, flowtable, IPVS, RXE), so
fixing each user would leave future users exposed. This is the problem
described in the thread where ovpn hit it.
This series moves the validity into the dst, as IPv4 does with rt_genid:
1. every dst carries the netns route generation it was built under and
ip6_dst_check() compares it with the current one; holders no longer
contribute a token.
2-5. keep invalidation targeted where it was before: ip6_link_failure()
clears the failing dst's sernum, nexthop group changes bump the
generation, and PMTU/redirect exceptions invalidate only the pcpu
dsts of the affected nexthop, as IPv4 does for fnhe.
6. rt_genid_bump_ipv6() becomes a counter increment like its IPv4
counterpart instead of walking every tree to rewrite fn_sernum.
7. the generation is sampled before the FIB is read and carried in
struct fib6_result, so a dst and the FIB lookup that produced it
refer to the same point in time. Without this a change landing between
the lookup and the allocation is folded into the stamp.
Long-lived dsts are never re-stamped: pcpu and exception dsts are shared
by all holders, so re-stamping one would make it valid again for every
socket and dst_cache that already saw it as stale. A stale pcpu dst is
dropped and rebuilt; a stale exception is treated as a miss. This is the
same behaviour as IPv4, where a stale cached route fails rt_cache_valid()
and a new one is allocated.
Known trade-off: any FIB change in a netns now invalidates every cached
IPv6 dst in it, not just those under the affected node; stale dsts are
rebuilt lazily on their next use.
Changes since v1:
- Do not re-stamp pcpu and exception dsts when a lookup finds them again
(patch 1); that made stale dsts valid again for other holders.
- New patch 7: sample the generation before the FIB lookup.
- Updated the patch 1 commit message to match.
AI assistance: Claude (Sonnet 5.5) helped develop these patches. I have
reviewed them and take responsibility for them.
Ralf: Patch 7 is alternative to your patch that adds the cookie to the
APIs. Instead the result struct contains the genid before the lookup is
done. Adding it to the fib6_result seems simpler and accomplishes the
end goal everywhere.
David Ahern (7):
ipv6: validate dsts against the netns route generation
ipv6: invalidate the failing dst in ip6_link_failure()
nexthop: factor out nh_has_f6i()
nexthop: bump the IPv6 route generation on group changes
ipv6: scope exception invalidation to the affected nexthop
ipv6: make rt_genid_bump_ipv6() a plain counter increment
ipv6: stamp dsts with the generation sampled before the FIB lookup
include/net/ip6_fib.h | 50 +++++------------
include/net/net_namespace.h | 36 ++++++++++---
net/ipv4/nexthop.c | 42 ++++++++++++---
net/ipv6/addrconf_core.c | 7 ---
net/ipv6/ip6_fib.c | 76 +++++++++++---------------
net/ipv6/route.c | 105 ++++++++++++++++++++++++------------
6 files changed, 178 insertions(+), 138 deletions(-)
--
2.43.0
next reply other threads:[~2026-11-23 21:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 21:26 David Ahern [this message]
2026-11-23 21:26 ` [RFC net-next v2 1/7] ipv6: validate dsts against the netns route generation David Ahern
2026-11-23 21:26 ` [RFC net-next v2 2/7] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-11-23 21:26 ` [RFC net-next v2 3/7] nexthop: factor out nh_has_f6i() David Ahern
2026-11-23 21:26 ` [RFC net-next v2 4/7] nexthop: bump the IPv6 route generation on group changes David Ahern
2026-11-23 21:26 ` [RFC net-next v2 5/7] ipv6: scope exception invalidation to the affected nexthop David Ahern
2026-11-23 21:26 ` [RFC net-next v2 6/7] ipv6: make rt_genid_bump_ipv6() a plain counter increment David Ahern
2026-11-23 21:26 ` [RFC net-next v2 7/7] ipv6: stamp dsts with the generation sampled before the FIB lookup David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123212623.106153-1-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=dahern@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=ralf@mandelbit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox