Netdev List
 help / color / mirror / Atom feed
From: Ralf Lici <ralf@mandelbit.com>
To: David Ahern <dsahern@kernel.org>
Cc: netdev@vger.kernel.org, David Ahern <dahern@nvidia.com>,
	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>
Subject: Re: [RFC net-next 0/6] ipv6: validate dsts against the netns route generation
Date: Mon, 23 Nov 2026 13:34:34 +0100	[thread overview]
Message-ID: <20261123123435.402751-1-ralf@mandelbit.com> (raw)
In-Reply-To: <20261122222717.126333-2-dsahern@kernel.org>

Hi David,

I had a look at the series and tested it. I see two problems with the
approach.

On Sun, 22 Nov 2026 15:26:58 -0700, David Ahern <dsahern@kernel.org> wrote:
> copy of it. So this series moves dst validation onto that counter, the
> way IPv4 uses rt_genid, instead of adding another one:
>
>  1. Stamp every dst with the counter in ip6_dst_alloc() and validate by
>     comparison in ip6_dst_check(). Long-lived dsts (pcpu dsts of routes
>     with an embedded fib6_nh, and exception dsts) are re-stamped when a
>     lookup finds them again, otherwise they would stay invalid.
>

pcpu and exception dsts are shared by every socket and dst_cache that
holds them, and with this series validity lives in the shared dst
instead of in each holder's cookie. When one lookup re-stamps the dst,
the stale dst becomes valid again for every holder. IPv4 does not
re-stamp: a stale cached route fails rt_cache_valid and __mkroute_output
allocates a new one, so routes already held by sockets keep their old
genid.

The script below shows this. A connected UDP socket on CPU0 caches its
route to fd01::2 through fd01::/64, then a blackhole for fd01::2/128 is
added. If an unrelated socket on CPU0 then connects to fd01::3 through
the same /64, the first socket keeps using the old route: all 10
datagrams it sends after the blackhole reach the wire, in 3 out of 3
runs. Without the unrelated socket they are dropped, and current
net-next and my series [1] drop them in both cases. With an xfrm policy
for the socket's port instead of the blackhole, the same sequence makes
the socket keep sending its 10 datagrams in plaintext, where net-next
and [1] encrypt them. This is not a narrow race but the deterministic
outcome with this series.

The stamp is also read after route selection, in ip6_dst_alloc and in
rt6_refresh_sernum. A FIB change that lands in between, e.g. the same
blackhole added while a lookup for fd01::2 has already selected the /64,
yields a dst selected from the old state that carries the new
generation. That is the window ip6_dst_lookup_flow_cookie in [1] closes
by reading the generation before the lookup.

For generation-based validation to hold, the value has to live with the
holder rather than in the shared dst, and it has to be read before route
selection. dst_check already takes a per-holder cookie for this: with
the generation read before the lookup as the cookie, compared with the
current one, dsts need no stamp or re-stamping and pcpu dsts stay
reusable across changes. That is what ip6_dst_lookup_flow_cookie
returns, with fn_sernum in place of the netns generation, so the two
approaches differ in invalidation granularity (per node vs netns-wide)
rather than in where the snapshot lives. I'd rather keep the per-node
granularity, but either one needs the holders converted to a cookie read
before the lookup.

[1] https://lore.kernel.org/netdev/cover.1795166508.git.ralf@mandelbit.com/

Reproducer, run as root in a VM, "restamp.sh route|xfrm ctrl|other":

#!/bin/bash
# usage: restamp.sh route|xfrm ctrl|other
#
# A connected UDP socket on CPU0 caches its route to fd01::2, then that
# destination gets a blackhole (route) or an xfrm policy (xfrm). With
# "other", an unrelated socket on CPU0 then connects through the same /64.
# Counts what the first socket sends to fd01::2 after the change.
case=$1 mode=$2
log=/tmp/restamp-$case-$mode.txt
on_cpu0() { taskset -c 0 ip netns exec cl "$@"; }

ip netns del cl 2>/dev/null
ip netns add cl
ip -n cl link add c0 type veth peer name p0
for dev in c0 p0; do
	# no link-local address: its DAD would add a route and bump the generation
	ip -n cl link set $dev addrgenmode none
	ip -n cl link set $dev up
done
ip -n cl addr add fd00::1/64 dev c0 nodad
ip -n cl neigh add fd00::2 lladdr 02:00:00:00:00:02 dev c0 nud permanent
ip -n cl route add fd01::/64 via fd00::2 dev c0
ip -n cl xfrm state add src fd00::1 dst fd01::2 proto esp spi 0x1001 reqid 1 \
	mode transport aead 'rfc4106(gcm(aes))' \
	0x0102030405060708090a0b0c0d0e0f1011121314 128

on_cpu0 bash -c 'exec 3>/dev/udp/fd01::2/5002; echo before >&3; sleep 3
	for i in {1..10}; do echo after >&3; sleep 0.1; done' 2>/dev/null &
sock=$!
sleep 0.5

if [ $case = route ]; then
	ip -n cl route add blackhole fd01::2/128
else
	ip -n cl xfrm policy add src fd00::1 dst fd01::2 proto udp dport 5002 \
		dir out tmpl src fd00::1 dst fd01::2 proto esp reqid 1 mode transport
fi
ip netns exec cl tcpdump -nn -l -i c0 dst fd01::2 >$log 2>/dev/null &
cap=$!
if [ $mode = other ]; then
	sleep 0.2
	on_cpu0 bash -c 'echo x >/dev/udp/fd01::3/9'
fi

wait $sock
sleep 0.5; kill $cap; wait $cap
if [ $case = route ]; then
	echo "route $mode: $(grep -c UDP $log) datagrams sent past the blackhole"
else
	echo "xfrm $mode: $(grep -c UDP $log) plaintext, $(grep -c ESP $log) ESP"
fi
ip netns del cl

-- 
Ralf Lici
Mandelbit Srl

  parent reply	other threads:[~2026-11-23 12:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 22:26 David Ahern
2026-11-22 22:26 ` [RFC net-next 0/6] ipv6: validate dsts against the netns route generation David Ahern
2026-11-22 22:30   ` David Ahern
2026-11-23 12:38     ` Ralf Lici
2026-11-23 12:34   ` Ralf Lici [this message]
2026-11-22 22:26 ` [RFC net-next 1/6] " David Ahern
2026-11-22 22:27 ` [RFC net-next 2/6] ipv6: invalidate the failing dst in ip6_link_failure() David Ahern
2026-11-22 22:27 ` [RFC net-next 3/6] nexthop: factor out nh_has_f6i() David Ahern
2026-11-22 22:27 ` [RFC net-next 4/6] nexthop: bump the IPv6 route generation on group changes David Ahern
2026-11-22 22:27 ` [RFC net-next 5/6] ipv6: scope exception invalidation to the affected nexthop David Ahern
2026-11-22 22:27 ` [RFC net-next 6/6] ipv6: make rt_genid_bump_ipv6() a plain counter increment 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=20261123123435.402751-1-ralf@mandelbit.com \
    --to=ralf@mandelbit.com \
    --cc=dahern@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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