The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH net v2] net: Defer netdev KOBJ_ADD uevent until the device is published
@ 2026-08-06  8:07 Dragos Tatulea
  2026-08-06 16:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Dragos Tatulea @ 2026-08-06  8:07 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Jacob Keller, Stanislav Fomichev
  Cc: Dragos Tatulea, tariqt, Shahar Shitrit, netdev, linux-kernel

netdev_register_kobject() calls device_add(), which emits KOBJ_ADD and
wakes udev, but register_netdevice() only makes the device findable by
name later, in list_netdevice().  A udev worker that reacts to the uevent
can therefore run against a device that no lookup can find yet.

This used to be harmless because the ethtool ioctl took the rtnl_lock
when looking the device up, and register_netdevice() runs under rtnl, so
the worker simply blocked until registration finished. The commit in the
fixes tag moved the lookup out from under rtnl for ops-locked drivers.
Now there is a short window in register_netdevice() between
netdev_register_kobject() until list_netdevice() when the device is not
findable by name.

This was reproduced with the mlx5 driver on a kernel with KASAN enabled
during devlink reload: systemd-udevd's net_driver builtin gets -ENODEV
from ETHTOOL_GDRVINFO, which was preventing interface renaming.

Suppress the uevent in netdev_register_kobject() and emit it from
register_netdevice() next to rtmsg_ifinfo(). This is the last point in
register_netdevice() where no error can happen, so only fully registered
devices are announced: the registration error paths never reach it, and
the device_del() that unwinds them stays silent as well, leaving
userspace with neither an add nor a remove.

Fixes: f994752b1127 ("net: ethtool: optionally skip rtnl_lock on IOCTL path")
Assisted-by: Claude:claude-opus-5
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Shahar Shitrit <shshitrit@nvidia.com>
---
Changes in v2:
- Addressed Jakub's comments on code comments.
- Link to v1: https://lore.kernel.org/all/20260804155103.742898-1-dtatulea@nvidia.com/
---
 net/core/dev.c       |  1 +
 net/core/net-sysfs.c | 14 ++++++++++++++
 net/core/net-sysfs.h |  1 +
 3 files changed, 16 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index c1c1be1a6962..32cc092d5d11 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11499,6 +11499,7 @@ int register_netdevice(struct net_device *dev)
 	 *	Prevent userspace races by waiting until the network
 	 *	device is fully setup before sending notifications.
 	 */
+	netdev_uevent_add(dev);
 	if (!(dev->rtnl_link_ops && dev->rtnl_link_initializing))
 		rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U, GFP_KERNEL, 0, NULL);
 
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 0e71c9ed41e8..25546deacec8 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -2334,6 +2334,9 @@ int netdev_register_kobject(struct net_device *ndev)
 		*groups++ = &wireless_group;
 #endif /* CONFIG_SYSFS */
 
+	/* Hold back the KOBJ_ADD uevent until the device is listed. */
+	dev_set_uevent_suppress(dev, 1);
+
 	error = device_add(dev);
 	if (error)
 		return error;
@@ -2349,6 +2352,17 @@ int netdev_register_kobject(struct net_device *ndev)
 	return error;
 }
 
+/* Announce a fully registered device to userspace. This pairs with the uevent
+ * suppression from netdev_register_kobject().
+ */
+void netdev_uevent_add(struct net_device *ndev)
+{
+	struct device *dev = &ndev->dev;
+
+	dev_set_uevent_suppress(dev, 0);
+	kobject_uevent(&dev->kobj, KOBJ_ADD);
+}
+
 /* Change owner for sysfs entries when moving network devices across network
  * namespaces owned by different user namespaces.
  */
diff --git a/net/core/net-sysfs.h b/net/core/net-sysfs.h
index 38e2e3ffd0bd..2f41a4dee866 100644
--- a/net/core/net-sysfs.h
+++ b/net/core/net-sysfs.h
@@ -4,6 +4,7 @@
 
 int __init netdev_kobject_init(void);
 int netdev_register_kobject(struct net_device *);
+void netdev_uevent_add(struct net_device *dev);
 void netdev_unregister_kobject(struct net_device *);
 int net_rx_queue_update_kobjects(struct net_device *, int old_num, int new_num);
 int netdev_queue_update_kobjects(struct net_device *net,
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net v2] net: Defer netdev KOBJ_ADD uevent until the device is published
  2026-08-06  8:07 [PATCH net v2] net: Defer netdev KOBJ_ADD uevent until the device is published Dragos Tatulea
@ 2026-08-06 16:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-06 16:50 UTC (permalink / raw)
  To: Dragos Tatulea
  Cc: davem, edumazet, kuba, pabeni, horms, jacob.e.keller, sdf, tariqt,
	shshitrit, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 6 Aug 2026 11:07:58 +0300 you wrote:
> netdev_register_kobject() calls device_add(), which emits KOBJ_ADD and
> wakes udev, but register_netdevice() only makes the device findable by
> name later, in list_netdevice().  A udev worker that reacts to the uevent
> can therefore run against a device that no lookup can find yet.
> 
> This used to be harmless because the ethtool ioctl took the rtnl_lock
> when looking the device up, and register_netdevice() runs under rtnl, so
> the worker simply blocked until registration finished. The commit in the
> fixes tag moved the lookup out from under rtnl for ops-locked drivers.
> Now there is a short window in register_netdevice() between
> netdev_register_kobject() until list_netdevice() when the device is not
> findable by name.
> 
> [...]

Here is the summary with links:
  - [net,v2] net: Defer netdev KOBJ_ADD uevent until the device is published
    https://git.kernel.org/netdev/net/c/8e63c9e6179a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-06 16:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06  8:07 [PATCH net v2] net: Defer netdev KOBJ_ADD uevent until the device is published Dragos Tatulea
2026-08-06 16:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox