Skip to contentSkip to conversation

net: fix the missing unlock for detached devices

PATCH Applied Jakub Kicinski 4 participants 6 messages Apr 18, 2025 – Apr 22, 2025

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 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.

Fixes 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations")

---
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
index 5d7af50fe702..230743bdbb14 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jakub Kicinski

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.

Fixes 1d22d3060b9b ("net: drop rtnl_lock for queue_mgmt operations")
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
index 5d7af50fe702..230743bdbb14 100644

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 -4
        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;
--

2.49.0

Signature · 2 lines
Thanks,
Mina
#2 lore raw
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() to netdev_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")

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?

#3 lore raw
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() to netdev_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")
Quoted 6 lines
Quoted 1 line

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
#4 lore raw
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() to netdev_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")

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.

#5 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 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() to netdev_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")

[...]

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