mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: qiliang.yuan@linux.dev
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, dsahern@kernel.org,
	idosch@nvidia.com, razor@blackwall.org, kuniyu@google.com,
	ralf@mandelbit.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v5 1/4] ipv4: draw rt_genid from a sequence shared by all netns
Date: Mon, 23 Nov 2026 00:25:42 +0000	[thread overview]
Message-ID: <179539354213.3135.13464015676697562807@kernel.org> (raw)
In-Reply-To: <20261121-bug-net-netns-move-rcu-barrier-v5-1-100a3b5d9090@linux.dev>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] rt_genid_bump_ipv4() in net/ipv4/route.c can return without
  changing net->ipv4.rt_genid, so a requested route-cache flush is…
- [Low] The commit message describes a netns-isolation bug in the current
  tree, but the patch has no Fixes: tag and no Cc: stable.
- [Low] The fix relies on every rt_genid value being unique across netns,
  and that only holds until the global 32-bit rt_genid_seq wraps.

--

ipv4: draw rt_genid from a sequence shared by all netns

This patch replaces the per-netns atomic_inc() of the IPv4 rt_genid with
values drawn from one global sequence shared by all netns. That sequence
never returns 0. Each drawn value is published with a cmpxchg on the netns
rt_genid, so a route cached in one netns cannot pass rt_is_expired() after
its device moves to a netns whose rt_genid happens to match.

> When a device moves to another netns, routes cached through it remain
> usable until dst_dev_put() points them to blackhole_netdev. For a route
> using a nexthop object this happens in nexthop_free_rcu(), which
> free_fib_info_rcu() queues from inside an RCU callback, so the
> rcu_barrier() in __dev_change_net_namespace() does not wait for it. If
> the rt_genid of the new netns matches the cached one in that window,
> ipv4_dst_check() accepts the route and a socket in the old netns keeps
> sending through a device that now belongs to another netns.

[Severity: Low]
This describes a netns isolation bug in the current tree, but the patch has
no Fixes: tag and no Cc: stable. Should it have them?

The window does exist before this patch. free_fib_info_rcu() runs as an
RCU callback, and from there the nexthop release is queued as a second,
nested callback:

free_fib_info_rcu()
  nexthop_put(fi->nh)
    call_rcu_hurry(&nh->rcu, nexthop_free_rcu)

The rcu_barrier() in __dev_change_net_namespace() does not wait for that
nested callback.

The likely origin is the change that let fib_info use nexthop objects.
Could the exact commit be identified and cited, so stable maintainers know
which kernels need this?

> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index d0930ae4c5ae6..ece931f7d9e4d 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -393,6 +393,42 @@ static inline int ip_rt_proc_init(void)
>  }
>  #endif /* CONFIG_PROC_FS */
>  
> +/*
> + * Draw rt_genid bumps from one sequence shared by all netns. A route keeps
> + * the genid of the netns it was created in, and is checked against the netns
> + * its device is in now, so distinct values make that check fail once the
> + * device has moved. Every netns starts at 0, which the sequence never hands
> + * out, and inserting a route bumps the genid, so cached routes carry values
> + * drawn from the sequence.
> + */
> +static atomic_t rt_genid_seq;

[Severity: Low]
Values from this sequence are unique only until the 32-bit rt_genid_seq
wraps. The commit message says so ("until it wraps after 2^32 bumps"), but
it doesn't mention that an unprivileged user can now force the wrap. Is
that intended?

sysctl_route_net_init() keeps the flush sysctl for netns owned by non-init
user namespaces:

net/ipv4/route.c:sysctl_route_net_init() {
    ...
		if (net->user_ns != &init_user_ns) {
			if (tbl[0].procname != ipv4_route_flush_procname)
				table_size = 0;
		}
    ...
}

After unshare -Urn, each write to /proc/sys/net/ipv4/route/flush takes
this path:

ipv4_sysctl_rtcache_flush()->rt_cache_flush()->rt_genid_bump_ipv4()

Each write advances the global rt_genid_seq, and this is cheap to repeat.

After a wrap, the genid that netns B draws can equal the genid cached on
routes in netns A. One example is the draw at NETDEV_UP after a device
move. A netns can also draw back the value of an older generation that was
invalidated, for example by an xfrm policy insertion. Either case lets
rt_is_expired() accept a stale route again.

This is hard to hit on purpose. rt_genid is not visible to userspace, so a
collision is roughly a 1 in 2^32 exact match. Per-netns 32-bit counters
could also be driven by unprivileged users before this patch.

It matters more once the later patch in the series, "net: remove
rcu_barrier() from __dev_change_net_namespace()", removes the barrier.
After that, genid uniqueness is the only check that rejects IPv4 routes
cached through a moved device.

Would a 64-bit generation be worth considering here? If not, could the
comment and commit message say that unprivileged users can drive the wrap?

> +
> +static int rt_genid_draw(void)
> +{
> +	int genid;
> +
> +	do {
> +		genid = atomic_inc_return(&rt_genid_seq);
> +	} while (!genid);
> +
> +	return genid;
> +}
> +
> +/*
> + * Publish the drawn value with a cmpxchg on the netns genid, drawing again if
> + * another bump got there first, so that a stalled bump never overwrites a
> + * newer value and each bump is ordered after the ones it replaces.
> + */
> +void rt_genid_bump_ipv4(struct net *net)
> +{
> +	int genid, old = atomic_read(&net->ipv4.rt_genid);
> +
> +	do {
> +		genid = rt_genid_draw();
> +	} while (!atomic_try_cmpxchg(&net->ipv4.rt_genid, &old, genid));

[Severity: Medium]
Can this bump return without changing net->ipv4.rt_genid?

rt_genid_draw() rejects only 0. Nothing compares the drawn value with the
current genid of the netns.

Say netns A last drew V. Other netns then advance the shared rt_genid_seq
until it wraps back to V, and A's next bump draws V again. In that case
atomic_try_cmpxchg() runs with old == genid == V. It succeeds, the loop
exits, and A's rt_genid stays at V.

The old atomic_inc() always changed the value. Now the requested flush is
silently lost, and rt_is_expired() keeps accepting routes cached before it
until the next bump.

Callers that depend on the flush include:

- fib_trie route insert and delete
- rt_cache_flush() from the NETDEV_UP/NETDEV_DOWN and address handlers
- xfrm policy insertion in xfrm_policy.c
- rt_genid_bump_all() on SELinux policy reload

Would redrawing while genid == old avoid this? For example:

	do {
		do {
			genid = rt_genid_draw();
		} while (genid == old);
	} while (!atomic_try_cmpxchg(&net->ipv4.rt_genid, &old, genid));

> +}
> +EXPORT_SYMBOL_GPL(rt_genid_bump_ipv4);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-bug-net-netns-move-rcu-barrier-v5-0-100a3b5d9090%40linux.dev

  parent reply	other threads:[~2026-11-23  0:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 23:21 [PATCH net-next v5 0/4] net: make moving a device to another netns cheaper Qiliang Yuan
2026-11-21 23:21 ` [PATCH net-next v5 1/4] ipv4: draw rt_genid from a sequence shared by all netns Qiliang Yuan
2026-11-22  9:02   ` Ralf Lici
2026-11-23  0:25   ` netdev-bot+sashiko [this message]
2026-11-21 23:21 ` [PATCH net-next v5 2/4] ipv6: take fib6_sernum " Qiliang Yuan
2026-11-22  9:03   ` Ralf Lici
2026-11-23  0:25   ` netdev-bot+sashiko
2026-11-21 23:21 ` [PATCH net-next v5 3/4] nexthop: release cached routes when a nexthop leaves a group Qiliang Yuan
2026-11-23  0:25   ` netdev-bot+sashiko
2026-11-21 23:21 ` [PATCH net-next v5 4/4] net: remove rcu_barrier() from __dev_change_net_namespace() Qiliang Yuan
2026-11-23  0:25   ` netdev-bot+sashiko

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=179539354213.3135.13464015676697562807@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --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=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qiliang.yuan@linux.dev \
    --cc=ralf@mandelbit.com \
    --cc=razor@blackwall.org \
    /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

all inboxes | Powered by JetHome®