Skip to content

RFC ipv6: validate dsts against the netns route generation at lookup

David Ahern netdev 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest7 patches 0 repliesNew
  2. v1 RFC6 patches 4 repliesSuperseded

Changes in v2 from the cover letter

- 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.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7ipv6: validate dsts against the netns route generationinclude/net/ip6_fib.h net/ipv6/ip6_fib.c net/ipv6/route.c+32 -670 replies
2/7ipv6: invalidate the failing dst in ip6_link_failure()net/ipv6/route.c+5 -60 replies
3/7nexthop: factor out nh_has_f6i()net/ipv4/nexthop.c+12 -50 replies
4/7nexthop: bump the IPv6 route generation on group changesnet/ipv4/nexthop.c+25 -20 replies
5/7ipv6: scope exception invalidation to the affected nexthopinclude/net/ip6_fib.h net/ipv6/ip6_fib.c net/ipv6/route.c+52 -30 replies
6/7ipv6: make rt_genid_bump_ipv6() a plain counter incrementinclude/net/net_namespace.h net/ipv6/addrconf_core.c net/ipv6/ip6_fib.c+27 -570 replies
7/7ipv6: stamp dsts with the generation sampled before the FIB lookupinclude/net/ip6_fib.h include/net/net_namespace.h net/ipv6/route.c+27 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [RFC net-next v2 0/7] ipv6: validate dsts against the netns route generation at lookup

From: David Ahern <[email protected]>

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(-)
Signature · 1 line
2.43.0