Re: [PATCH net-next v4 4/4] net: remove rcu_barrier() from __dev_change_net_namespace()

From: netdev-bot+sashiko

Date: Sat Nov 21 2026 - 22:14:41 EST


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

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

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] net: race in __dev_change_net_namespace() leaves moved dev on
xfrm_dst
- [Medium] net: missing dst_dev_put() wait in
__dev_change_net_namespace()

--

> diff --git a/net/core/dev.c b/net/core/dev.c
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -13153,7 +13153,6 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net,
> * the device is just moving and can keep their slaves up.
> */
> call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
> - rcu_barrier();
>
> new_nsid = peernet2id_alloc(dev_net(dev), net, GFP_KERNEL);
>
>

[Severity: Medium]
The changelog says routes cached through the moved device are
rejected once the netns changes. That only covers users that go
through dst_check(). Is that enough here?

For routes without a nexthop object, dst_dev_put() on the per-cpu
and exception dsts only happens in two places: free_fib_info_rcu() ->
fib_nh_release(), and fib6_info_destroy_rcu() ->
fib6_nh_release() -> fib6_nh_release_dsts(). On NETDEV_UNREGISTER,
fib6_drop_pcpu_from() only clears ->from.

Without rcu_barrier(), __dev_change_net_namespace() can therefore
return while those dsts still have dst->output set to ip_output() /
ip6_output() and dst->dev_rcu pointing at dev.

A few users don't call dst_check():

A corked UDP, UDPv6 or RAW socket in the old netns keeps the dst from
ip_setup_cork() / ip6_setup_cork(). On uncork,
udp_push_pending_frames() -> ip_send_skb() -> dst_output() uses it
as is. If dev has already been brought up in its new netns, the
corked packet goes out there.

The following read dst_dev_rcu(__sk_dst_get(sk)) directly:
get_netdev_for_sock() in net/tls/tls_device.c,
net_devmem_get_sock_binding(), smc_clc_prfx_set(),
smc_clc_prfx_match(), smc_vlan_by_tcpsk() and
smc_pnet_find_roce_resource(). They would get the moved device
rather than blackhole_netdev, and attach offload state to a device
in another netns.

The window is small. The synchronize_net() at the end means the
grace period has elapsed and only callback invocation is pending.
But rcu_barrier() closed it completely before.

Could the changelog cover these users? If the barrier has to go,
would it be better to release the cached dsts of routes on dev
synchronously in the NETDEV_UNREGISTER handlers? Or is there a
reason these paths don't matter?

[Severity: Medium]
Does dropping the barrier open a window where an xfrm bundle gets
built on the moved device after the uncached list flush has run?

NETDEV_UNREGISTER queues free_fib_info_rcu() and
fib6_info_destroy_rcu(), and those are what call dst_dev_put() on
the per-cpu and exception routes. Until they run, dst_dev_rcu() on
such a route still returns dev. netif_is_alive(dev) also stays true,
because reg_state remains NETREG_REGISTERED across the move.

ip_route_output_flow() and ip6_dst_lookup_flow() take a reference on
the base route and drop rcu_read_lock() before calling
xfrm_lookup_route(). So the synchronize_net() earlier in
__dev_change_net_namespace() does not wait for them.
xfrm_policy_queue_process() also passes xfrm_dst_path(skb_dst(skb))
from the hold queue to xfrm_lookup() without a dst_check().

Suppose xfrm_bundle_create() or xfrm_create_dummy_bundle() runs
after NETDEV_UNREGISTER has done rt_flush_dev() and
rt6_uncached_list_flush_dev(), but before the RCU callbacks.
xfrm4_fill_dst() / xfrm6_fill_dst() then take a reference on dev.
Once NETDEV_REGISTER has run in the target netns, they also take a
reference on the inet6_dev that ipv6_add_dev() just allocated there.

The xdst is then added to rt_uncached_list / rt6_uncached_list with
no flush left to catch it. It keeps the moved device and the new
inet6_dev referenced, and traffic can leave through dev in its new
netns.

With rcu_barrier() in place, dst_dev_put() had already switched these
routes to blackhole_netdev before dev_net_set().

The rt_genid / fib6_sernum argument in the changelog relies on
dst_check(), which these xfrm paths don't seem to do. Did you look
at them? Is there something else that closes this window, or does
the move still need to wait for these callbacks in some form?

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