Netdev List
 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,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v4 1/4] ipv4: draw rt_genid from a sequence shared by all netns
Date: Sun, 22 Nov 2026 03:14:10 +0000	[thread overview]
Message-ID: <179531725087.3135.405511503096660392@kernel.org> (raw)
In-Reply-To: <20261117-bug-net-netns-move-rcu-barrier-v4-1-43e1ca0aac7f@linux.dev>

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

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

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] The fix depends on one guarantee: no other netns holds a given
  rt_genid value until the global 32-bit rt_genid_seq wraps.
- [Low] The commit fixes a cross-netns isolation bug that already exists
  in the current tree but has no Fixes: tag and no Cc: stable.

--

ipv4: draw rt_genid from a sequence shared by all netns

This patch moves rt_genid_bump_ipv4() out of line and takes every IPv4
rt_genid value from one global atomic sequence shared by all netns. That
sequence never returns 0. The aim is to make sure a route cached in one
netns cannot match the rt_genid of the netns its device has moved to.

> 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]
Should this carry a Fixes: tag and a Cc: stable?

The premise holds in the current tree. For a fib_info that uses a nexthop
object, free_fib_info_rcu() in net/ipv4/fib_semantics.c only drops the
nexthop reference:

    if (fi->nh) {
        nexthop_put(fi->nh);
    } else {

The cached rtables are released later, through this chain:

    nexthop_free_rcu()->nexthop_free_single()->fib_nh_release()

That runs from an RCU callback queued inside another RCU callback, so the
rcu_barrier() in __dev_change_net_namespace() does not wait for it.

The old rt_genid_bump_ipv4() was a plain atomic_inc() from 0 in every
netns, so this cross-netns leak is visible to users in released kernels.
It most likely dates from when nexthop object support was added to
fib_info.

Without a Fixes: tag, how can backporters tell which stable trees need
this?

[ ... ]

> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index b9f5397336d34..294c9c278c403 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -393,6 +393,27 @@ 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;
> +
> +void rt_genid_bump_ipv4(struct net *net)
> +{
> +	int genid;
> +
> +	do {
> +		genid = atomic_inc_return(&rt_genid_seq);
> +	} while (!genid);
> +	atomic_set(&net->ipv4.rt_genid, genid);
> +}

[Severity: Medium]
Can an unprivileged user force rt_genid_seq to wrap and bring back the
collision this patch is meant to close?

The fix assumes no other netns holds a given value until the 32-bit
sequence wraps. However, sysctl_route_net_init() deliberately keeps the
per-netns route flush sysctl for netns owned by non-init user namespaces:

    /* Don't export non-whitelisted sysctls to unprivileged users */
    if (net->user_ns != &init_user_ns) {
        if (tbl[0].procname != ipv4_route_flush_procname)
            table_size = 0;
    }

Each write to that sysctl advances the global counter, with no rate limit:

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

Route add/delete loops and xfrm_policy_insert() also advance it. The
period is 2^32-1 nonzero values, so a few threads could cycle it in
anywhere from minutes to about an hour.

After a wrap, the NETDEV_UP rt_cache_flush() in the device's new netns B
can hand out the same value that a route cached in the old netns A
carries. rt_is_expired() only tests for equality:

    res = rth->rt_genid != rt_genid_ipv4(dev_net_rcu(rth->dst.dev));

so ipv4_dst_check() would accept the stale route. A socket in A would
then send through a device that belongs to B until dst_dev_put() runs.

Lining up the exact count between the two draws without being able to
read the counter is uncertain. Still, the commit message's "no other
netns holds until it wraps after 2^32 bumps" seems to treat the wrap as
unreachable.

This matters more later in the series. "net: remove rcu_barrier() from
__dev_change_net_namespace()" removes the barrier, so rt_genid uniqueness
becomes the only guard for all IPv4 cached routes, not just nexthop
object routes, until the deferred dst_dev_put() runs.

Would comparing netns identity, or using a wider sequence, avoid relying
on a value that unprivileged users can cycle?

> +EXPORT_SYMBOL_GPL(rt_genid_bump_ipv4);
> +
>  static inline bool rt_is_expired(const struct rtable *rth)
>  {
>  	bool res;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117-bug-net-netns-move-rcu-barrier-v4-0-43e1ca0aac7f%40linux.dev

  reply	other threads:[~2026-11-22  3:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  2:28 [PATCH net-next v4 0/4] net: make moving a device to another netns cheaper Qiliang Yuan
2026-11-18  2:28 ` [PATCH net-next v4 1/4] ipv4: draw rt_genid from a sequence shared by all netns Qiliang Yuan
2026-11-22  3:14   ` netdev-bot+sashiko [this message]
2026-11-18  2:28 ` [PATCH net-next v4 2/4] ipv6: take fib6_sernum " Qiliang Yuan
2026-11-20 17:52   ` Ralf Lici
2026-11-20 23:13     ` Qiliang Yuan
2026-11-22  3:14   ` netdev-bot+sashiko
2026-11-18  2:28 ` [PATCH net-next v4 3/4] nexthop: release cached routes when a nexthop leaves a group Qiliang Yuan
2026-11-22  3:14   ` netdev-bot+sashiko
2026-11-18  2:28 ` [PATCH net-next v4 4/4] net: remove rcu_barrier() from __dev_change_net_namespace() Qiliang Yuan
2026-11-22  3:14   ` 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=179531725087.3135.405511503096660392@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=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