net: don't try to ops lock uninitialized devs
Subsystems (2)
Jakub Kicinski
maintainerPATCH 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.
---
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
@@ -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
@@ -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
Quoted 11 lines · Jakub Kicinski
We need to be careful when operating on dev while in
rtnl_create_link(). Some devices (vxlan) initializenetdev_opsin ->newlink, so later on. Avoid usingnetdev_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")Signed-off-by Jakub Kicinski <[email protected]>
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) initializenetdev_opsin ->newlink, so later on. Avoid usingnetdev_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")Signed-off-by Jakub Kicinski <[email protected]>
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!
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) initializenetdev_opsin ->newlink, so later on. Avoid usingnetdev_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