The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ralf Lici <ralf@mandelbit.com>
To: netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Florian Westphal <fw@strlen.de>,
	Xia Yan <yanxia@cmss.chinamobile.com>,
	Sabrina Dubroca <sd@queasysnail.net>,
	Antonio Quartulli <antonio@mandelbit.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next v4 0/5] ipv6: tie the dst cookie to the lookup that returned the dst
Date: Fri, 20 Nov 2026 10:36:15 +0100	[thread overview]
Message-ID: <cover.1795166508.git.ralf@mandelbit.com> (raw)

Hi,

This series implements a first part of the model proposed in [1] to
address the late cookie sampling race: a dst can be stored together with
a cookie read after a FIB change that its lookup did not see, and then
passes dst_check until the next change.

The case that made me post it as a series is xfrm. Adding a policy
restamps every fib6 node, so a socket whose lookup ran just before the
insertion keeps its plain dst and leaks plaintext although the policy
matches. I reproduced it for TCP connect and connected UDP, and the same
window lets a more specific blackhole route be bypassed for routes using
nexthop objects. The ovpn patch [2] hit the same pattern in
dst_cache_set_ip6.

Patches 1-3 are the prerequisites: writers that publish a routing
change before advancing the IPv6 generation, and an ip6_dst_check that
compares the cookie of nexthop-object dsts. Patch 4 adds the
lookup-cookie API and patch 5 converts tcp_v6_connect,
ip6_datagram_dst_update and ip6_sk_dst_lookup_flow to it.

Compared to [1], the fallback cookie is 0 instead of the pre-lookup
generation, so fib6_flush_trees is left alone, and nexthop-object dsts
are checked in ip6_dst_check instead of passing the generation down to
ip6_rt_pcpu_alloc.

I am targeting net-next to get feedback on the lookup-cookie API and its
incremental adoption before extending the conversion across the
remaining cache users. I am not requesting stable backports at this
stage.

Known limitations and pre-existing issues, not addressed here:

- The conversion is partial. The remaining ip6_dst_store users
  (inet6_csk_route_socket, inet6_sk_rebuild_header and
  tcp_v6_syn_recv_sock) and the other cache users (dst_cache, sctp,
  ipvs, flowtable, sk_rx_dst) still sample the cookie late.
- xfrm bundles ignore the returned cookie. Their route and path cookies
  are still sampled late in xfrm_bundle_create. I plan to apply the same
  generation bracketing inside xfrm as a follow-up.
- xfrm_policy_insert unlinks a replaced policy after rt_genid_bump_ipv6,
  so a lookup after the bump can still match the old policy. I will send
  a separate fix.
- Route deletion does not advance the generation, and ip6_dst_check does
  not look at rt->from for nexthop-object dsts, so these are not
  invalidated by deletion. This predates the series and the kdoc of the
  new helper does not claim otherwise.
- A newly linked fib6 node holds fn_sernum 0 until fib6_add stamps it,
  so a dst stored with the fallback cookie 0 can pass a check in that
  window. It fails as soon as the node is stamped.

I tested it in a VM with lockdep, PROVE_RCU and DEBUG_ATOMIC_SLEEP,
using a debug-only delay after the lookup to hit the window: no
warnings, and the plaintext and blackhole bypass are gone in these test
cases.

[1] https://lore.kernel.org/netdev/20260901122501.482920-1-ralf@mandelbit.com/
[2] https://lore.kernel.org/netdev/cover.1789639346.git.ralf@mandelbit.com/

Thanks,

Ralf Lici
Mandelbit Srl

---
Changes since v3 https://lore.kernel.org/netdev/cover.1794906743.git.ralf@mandelbit.com/
- Rebase onto current net-next.
- Split v3 2/3 into the writer ordering (2/5), the ip6_dst_check change
  (3/5) and the new API (4/5), each with its own explanation. (David)
- Reword the kdoc of ip6_dst_lookup_flow_cookie to say that it performs
  the xfrm policy lookup (David) and narrow it to changes that advance
  the IPv6 generation. (Sashiko)
- Document the ordering of fib6_new_sernum that the helper relies on and
  name it in the barrier comments. (Xia)
- Note the per-call generation advance in 1/5 and widen the
  rt6_exception_net comment. (Sashiko)
- Drop the Fixes tag from the conversion patch. (Sashiko)
- List the known limitations and pre-existing issues above.

Changes since v2 https://lore.kernel.org/all/cover.1794384146.git.ralf@mandelbit.com/
- Rebase onto current net-next, preserving the connected-only cache
  lookup introduced by f778e80b3daf ("ipv6: fix cached route reuse for
  control messages"). (Jakub)
- Move the serial update after rt6_multipath_rebalance in fib6_ifup and
  fib6_ifdown. (Sashiko)
- Add Fixes tags and improve wording. (Sashiko)
- Clarify that this is the groundwork for fixing the race and a partial
  conversion to the new API: other users will be covered in a follow-up
  series.

Changes since v1 https://lore.kernel.org/netdev/cover.1793806941.git.ralf@mandelbit.com/
- Fix kdoc return statements in patch 2/3. (NIPA)

Ralf Lici (5):
  ipv6: stamp the default route node with a fresh serial on link failure
  ipv6: advance the serial after rebalancing in fib6_ifup and
    fib6_ifdown
  ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check
  ipv6: add ip6_dst_lookup_flow_cookie
  ipv6: use lookup cookies in selected socket dst cache paths

 include/net/ip6_route.h | 18 ++++++++----
 include/net/ipv6.h      | 13 +++++++++
 net/ipv6/datagram.c     |  6 ++--
 net/ipv6/ip6_fib.c      |  4 +++
 net/ipv6/ip6_output.c   | 63 ++++++++++++++++++++++++++++++++++++++---
 net/ipv6/route.c        | 38 +++++++++++++------------
 net/ipv6/tcp_ipv6.c     |  5 ++--
 7 files changed, 116 insertions(+), 31 deletions(-)


base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
-- 
2.56.0


             reply	other threads:[~2026-11-20  9:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:36 Ralf Lici [this message]
2026-11-20  9:36 ` [PATCH net-next v4 1/5] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
2026-11-20  9:36 ` [PATCH net-next v4 2/5] ipv6: advance the serial after rebalancing in fib6_ifup and fib6_ifdown Ralf Lici
2026-11-20  9:36 ` [PATCH net-next v4 3/5] ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check Ralf Lici
2026-11-20  9:36 ` [PATCH net-next v4 4/5] ipv6: add ip6_dst_lookup_flow_cookie Ralf Lici
2026-11-20  9:36 ` [PATCH net-next v4 5/5] ipv6: use lookup cookies in selected socket dst cache paths Ralf Lici

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=cover.1795166508.git.ralf@mandelbit.com \
    --to=ralf@mandelbit.com \
    --cc=antonio@mandelbit.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    --cc=yanxia@cmss.chinamobile.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