Skip to contentSkip to conversation

net: don't try to ops lock uninitialized devs

PATCH Applied Jakub Kicinski 4 participants 4 messages Apr 15, 2025 – Apr 17, 2025

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net: don't try to ops lock uninitialized devs

We need to be careful when operating on dev while in rtnl_create_link(). Some devices (vxlan) initialize netdev_ops in ->newlink, so later on. Avoid using netdev_lock_ops(), the device isn't registered so we cannot legally call its ops or generate any notifications for it.

netdev_ops_assert_locked_or_invisible() is safe to use, it checks registration status first.

Reported-by [email protected]
Fixes 04efcee6ef8d ("net: hold instance lock during NETDEV_CHANGE")

---
CC: [email protected]
CC: [email protected]

I wasn't sure whether Kuniyuki is going to send this or he's waiting for me to send.. so let me send and get this off my tracking list :)

---
 net/core/dev.c       | 2 ++
 net/core/rtnetlink.c | 5 +----
 2 files changed, 3 insertions(+), 4 deletions(-)
net/core/dev.c +2 -0
index 03d20a98f8b7..c5e15701cfb3 100644
@@ -1572,6 +1572,8 @@ EXPORT_SYMBOL(netdev_features_change);
 
 void netif_state_change(struct net_device *dev)
 {
+	netdev_ops_assert_locked_or_invisible(dev);
+
 	if (dev->flags & IFF_UP) {
 		struct netdev_notifier_change_info change_info = {
 			.info.dev = dev,
net/core/rtnetlink.c +1 -4
index 38526210b8fd..bb624fc6ca8a 100644
@@ -3677,11 +3677,8 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
 				nla_len(tb[IFLA_BROADCAST]));
 	if (tb[IFLA_TXQLEN])
 		dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
-	if (tb[IFLA_OPERSTATE]) {
-		netdev_lock_ops(dev);
+	if (tb[IFLA_OPERSTATE])
 		set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
-		netdev_unlock_ops(dev);
-	}
 	if (tb[IFLA_LINKMODE])
 		dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
 	if (tb[IFLA_GROUP])
Signature · 1 line
2.49.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jakub Kicinski

We need to be careful when operating on dev while in rtnl_create_link(). Some devices (vxlan) initialize netdev_ops in ->newlink, so later on. Avoid using netdev_lock_ops(), the device isn't registered so we cannot legally call its ops or generate any notifications for it.

netdev_ops_assert_locked_or_invisible() is safe to use, it checks registration status first.

Reported-by [email protected]
Fixes 04efcee6ef8d ("net: hold instance lock during NETDEV_CHANGE")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski

From: Jakub Kicinski <[email protected]>
Date: Tue, 15 Apr 2025 08:15:52 -0700

Quoted 11 lines

We need to be careful when operating on dev while in rtnl_create_link(). Some devices (vxlan) initialize netdev_ops in ->newlink, so later on. Avoid using netdev_lock_ops(), the device isn't registered so we cannot legally call its ops or generate any notifications for it.

netdev_ops_assert_locked_or_invisible() is safe to use, it checks registration status first.

Reported-by [email protected]
Fixes 04efcee6ef8d ("net: hold instance lock during NETDEV_CHANGE")
Quoted 6 lines

---
CC: [email protected]
CC: [email protected]

I wasn't sure whether Kuniyuki is going to send this or he's waiting for me to send.. so let me send and get this off my tracking list :)

wondering the same, thanks!

#3 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Tue, 15 Apr 2025 08:15:52 -0700 you wrote:

We need to be careful when operating on dev while in rtnl_create_link(). Some devices (vxlan) initialize netdev_ops in ->newlink, so later on. Avoid using netdev_lock_ops(), the device isn't registered so we cannot legally call its ops or generate any notifications for it.

netdev_ops_assert_locked_or_invisible() is safe to use, it checks registration status first.

[...]

Here is the summary with links:
- [net] net: don't try to ops lock uninitialized devs

    https://git.kernel.org/netdev/net/c/4798cfa2097f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html