net: fix the missing unlock for detached devices
Subsystems (2)
Jakub Kicinski
maintainerPATCH 1/1 net: fix the missing unlock for detached devices
The combined condition was left as is when we converted from __dev_get_by_index() to netdev_get_by_index_lock(). There was no need to undo anything with the former, for the latter we need an unlock.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- net/core/netdev-genl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/core/netdev-genl.c +6 -3
@@ -861,14 +861,17 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)mutex_lock (&priv->lock); + err =0 ; netdev =netdev_get_by_index_lock (genl_info_net (info), ifindex); -if (!netdev || !netif_device_present (netdev)) { +if (!netdev) { err = -ENODEV ; goto err_unlock_sock; } - -if (!netdev_need_ops_lock (netdev)) { +if (!netif_device_present (netdev)) + err = -ENODEV ; +else if (!netdev_need_ops_lock (netdev)) err = -EOPNOTSUPP ; +if (err) {NL_SET_BAD_ATTR (info->extack, info->attrs[NETDEV_A_DEV_IFINDEX ]); goto err_unlock;
Signature · 1 line
2.49.0
Quoted 8 lines · Jakub Kicinski
The combined condition was left as is when we converted from
__dev_get_by_index()tonetdev_get_by_index_lock(). There was no need to undo anything with the former, for the latter we need an unlock.Fixes 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations")Signed-off-by Jakub Kicinski <[email protected]>
Quoted 14 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- net/core/netdev-genl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)net/core/netdev-genl.c +0
-0
net/core/netdev-genl.c int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) · line 864
Quoted 4 lines
net/core/netdev-genl.c +1
-0@@ -861,14 +861,17 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)mutex_lock (&priv->lock); + err =0 ;
nit: AFAICT, this setting to 0 is redundant. err is 0 initialized and I don't see a code path that sets err but doesn't goto.
Quoted 19 lines
net/core/netdev-genl.c +5
-4netdev =netdev_get_by_index_lock (genl_info_net (info), ifindex); -if (!netdev || !netif_device_present (netdev)) { +if (!netdev) { err = -ENODEV ; goto err_unlock_sock; } - -if (!netdev_need_ops_lock (netdev)) { +if (!netif_device_present (netdev)) + err = -ENODEV ; +else if (!netdev_need_ops_lock (netdev)) err = -EOPNOTSUPP ; +if (err) {NL_SET_BAD_ATTR (info->extack, info->attrs[NETDEV_A_DEV_IFINDEX ]); goto err_unlock; --2.49.0
Signature · 2 lines
Thanks, Mina
Quoted 11 lines · Mina Almasry
Quoted 8 lines · Jakub Kicinski
The combined condition was left as is when we converted from
__dev_get_by_index()tonetdev_get_by_index_lock(). There was no need to undo anything with the former, for the latter we need an unlock.Fixes 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations")Signed-off-by Jakub Kicinski <[email protected]>Reviewed-by Mina Almasry <[email protected]>
Mina, the same (unlock netedev on !present) needs to happen for
https://lore.kernel.org/netdev/[email protected]/
Presumably you'll do another repost at some point?
Quoted 12 lines · Stanislav Fomichev
Quoted 10 lines · Mina Almasry
Quoted 8 lines · Jakub Kicinski
The combined condition was left as is when we converted from
__dev_get_by_index()tonetdev_get_by_index_lock(). There was no need to undo anything with the former, for the latter we need an unlock.Fixes 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations")Signed-off-by Jakub Kicinski <[email protected]>
Quoted 6 lines
Quoted 1 line
Reviewed-by Mina Almasry <[email protected]>Mina, the same (unlock netedev on !present) needs to happen for
https://lore.kernel.org/netdev/[email protected]/Presumably you'll do another repost at some point?
Yes, and there is also a lot going on in that series outside of this locking point. If the rest of the series looks good and is merged I can also look into porting this fix to the tx path as a follow up, if acceptable.
Signature · 2 lines
Thanks, Mina
Quoted 18 lines · Mina Almasry
Quoted 17 lines · Stanislav Fomichev
Quoted 11 lines · Mina Almasry
Quoted 8 lines · Jakub Kicinski
The combined condition was left as is when we converted from
__dev_get_by_index()tonetdev_get_by_index_lock(). There was no need to undo anything with the former, for the latter we need an unlock.Fixes 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations")Signed-off-by Jakub Kicinski <[email protected]>Reviewed-by Mina Almasry <[email protected]>Mina, the same (unlock netedev on !present) needs to happen for
https://lore.kernel.org/netdev/[email protected]/
Quoted 6 lines
Quoted 1 line
Presumably you'll do another repost at some point?
Yes, and there is also a lot going on in that series outside of this locking point. If the rest of the series looks good and is merged I can also look into porting this fix to the tx path as a follow up, if acceptable.
I'd be surprised if the maintainers gonna pull buggy code :-) Why not repost with a fix? It's a three lines change.
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 Thu, 17 Apr 2025 18:53:17 -0700 you wrote:
The combined condition was left as is when we converted from
__dev_get_by_index()tonetdev_get_by_index_lock(). There was no need to undo anything with the former, for the latter we need an unlock.Fixes 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations")Signed-off-by Jakub Kicinski <[email protected]>[...]
Here is the summary with links:
- [net] net: fix the missing unlock for detached devices
https://git.kernel.org/netdev/net/c/d3153c3b4270
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html