From: Ralf Lici <ralf@mandelbit.com>
To: netdev@vger.kernel.org
Cc: Ralf Lici <ralf@mandelbit.com>, 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>,
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 v5 0/4] ipv6: tie dst validation to the lookup that returned the dst
Date: Tue, 24 Nov 2026 17:27:06 +0100 [thread overview]
Message-ID: <cover.1795537128.git.ralf@mandelbit.com> (raw)
Hi,
This series fixes the late cookie sampling race described in [1]: 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.
With xfrm, a socket whose lookup ran just before a policy insertion
keeps its plain dst and leaks plaintext although the policy matches,
and a more specific blackhole route can be bypassed in the same way.
v4 returned the cookie from the lookup and converted selected cache
users to it. Following David's objection to growing the API and his RFC
[2], which moves validity into the dst, this revision keeps validity in
the dst but stamps it with the fn_sernum of the route's node, sampled
during the lookup, instead of the netns generation:
- Every holder is covered without being converted, including dst_cache
users and the route and path dsts of xfrm bundles.
- Invalidation keeps its per-node scope, rather than every FIB change
invalidating every cached IPv6 dst in the netns.
- Shared pcpu dsts are never re-stamped: a lookup only reuses one that
carries its own stamp, and replaces it otherwise.
Patches 1 and 2 are writer-side fixes from v4: a fresh serial on default
router failure, and fib6_ifup and fib6_ifdown advancing the serial
after the ECMP rebalance. Patch 3 samples the stamp during the lookup
and patch 4 validates dsts against it.
I tested it in a VM with lockdep, PROVE_RCU and DEBUG_ATOMIC_SLEEP,
using reproducers for the races above, which I can share.
Not addressed here, and noted in the patches where relevant:
- PMTU and redirect exceptions keep being validated against the
holder's cookie, so they keep the late sampling. Refreshing them
needs PMTU updates serialized with the replacement, a follow-up.
- The stamp covers the lookup in one table: a fib rule inserted while
the rules are evaluated can leave a lookup on the previous table.
- Deleting one route of an ECMP group rebalances the others without a
new serial, changing the forwarding sysctl changes how gateways are
scored without one, and deleting a nexthop-object route does not
advance the generation. These predate this series.
- A replaced pcpu dst is released with dst_dev_put, so a holder that
sends through it without validating it again, such as a corked UDP
socket, loses those packets. This already happens when the route is
removed, and now also when a FIB change in the route's subtree
replaces the pcpu dst.
- xfrm_policy_insert advances the generation before unlinking the
policy it replaces. I will send the fix separately to the ipsec tree.
- pcpu dsts dropped when their route is removed, in
__fib6_drop_pcpu_from, still release the slot's reference without
waiting for a grace period, as before.
[1] https://lore.kernel.org/netdev/20260901122501.482920-1-ralf@mandelbit.com/
[2] https://lore.kernel.org/netdev/20261123212623.106153-1-dsahern@kernel.org/
Thanks,
Ralf Lici
Mandelbit Srl
---
Changes since v4 https://lore.kernel.org/netdev/cover.1795166508.git.ralf@mandelbit.com/
- Keep validity in the dst instead of returning a cookie from the
lookup, with a stamp sampled during the lookup (patches 3 and 4).
Drop ip6_dst_lookup_flow_cookie, ip6_dst_store_cookie and the
conversion of socket cache users, which are no longer needed, and the
ip6_dst_check change for nexthop-object dsts, superseded by patch 4.
(David)
- Mention the tunnel transmit error paths in patch 1. (Sashiko)
- The xfrm bundle cookies and the UDP rx dst cookie pairing reported on
v4 no longer matter, since dsts are validated against their own
stamp. (Sashiko)
- The xfrm_policy_insert ordering reported on v4 will be fixed
separately in the ipsec tree. (Sashiko)
- Reword the fib6_ifup and fib6_ifdown patch to refer to the lookup
stamps.
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 (4):
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: sample the route's serial during the lookup
ipv6: validate dsts against the state their lookup found
include/net/ip6_fib.h | 10 +++
net/ipv6/ip6_fib.c | 4 ++
net/ipv6/route.c | 151 +++++++++++++++++++++++++++++++++++-------
3 files changed, 140 insertions(+), 25 deletions(-)
base-commit: c2621b518b38ed38e280e008aa33e6c2d302f8cc
--
2.56.0
next reply other threads:[~2026-11-24 16:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 16:27 Ralf Lici [this message]
2026-11-24 16:27 ` [PATCH net-next v5 1/4] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
2026-11-24 16:27 ` [PATCH net-next v5 2/4] ipv6: advance the serial after rebalancing in fib6_ifup and fib6_ifdown Ralf Lici
2026-11-24 16:27 ` [PATCH net-next v5 3/4] ipv6: sample the route's serial during the lookup Ralf Lici
2026-11-24 16:27 ` [PATCH net-next v5 4/4] ipv6: validate dsts against the state their lookup found 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.1795537128.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=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