Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Lock netdevices during dev_shutdown

__qdisc_destroy() calls into various qdiscs .destroy() op, which in turn
can call .ndo_setup_tc(), which requires the netdev instance lock.

This commit extends the critical section in
unregister_netdevice_many_notify() to cover dev_shutdown() (and
dev_tcx_uninstall() as a side-effect) and acquires the netdev instance
lock in __dev_change_net_namespace() for the other dev_shutdown() call.

This should now guarantee that for all qdisc ops, the netdev instance
lock is held during .ndo_setup_tc().

Fixes: a0527ee2df3f ("net: hold netdev instance lock during qdisc ndo_setup_tc")
Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250505194713.1723399-1-cratiu@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Cosmin Ratiu and committed by
Jakub Kicinski
08e9f2d5 0093cb19

+3 -1
+3 -1
net/core/dev.c
··· 11966 11966 struct sk_buff *skb = NULL; 11967 11967 11968 11968 /* Shutdown queueing discipline. */ 11969 + netdev_lock_ops(dev); 11969 11970 dev_shutdown(dev); 11970 11971 dev_tcx_uninstall(dev); 11971 - netdev_lock_ops(dev); 11972 11972 dev_xdp_uninstall(dev); 11973 11973 dev_memory_provider_uninstall(dev); 11974 11974 netdev_unlock_ops(dev); ··· 12161 12161 synchronize_net(); 12162 12162 12163 12163 /* Shutdown queueing discipline. */ 12164 + netdev_lock_ops(dev); 12164 12165 dev_shutdown(dev); 12166 + netdev_unlock_ops(dev); 12165 12167 12166 12168 /* Notify protocols, that we are about to destroy 12167 12169 * this device. They should clean all the things.