netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: fix the missing unlock for detached devices
@ 2025-04-18  1:53 Jakub Kicinski
  2025-04-18 11:51 ` Mina Almasry
  2025-04-22  9:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 6+ messages in thread
From: Jakub Kicinski @ 2025-04-18  1:53 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, andrew+netdev, horms, Jakub Kicinski,
	jdamato, almasrymina, sdf, ap420073

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")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: jdamato@fastly.com
CC: almasrymina@google.com
CC: sdf@fomichev.me
CC: ap420073@gmail.com
---
 net/core/netdev-genl.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 5d7af50fe702..230743bdbb14 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -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;
-- 
2.49.0


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

* Re: [PATCH net] net: fix the missing unlock for detached devices
  2025-04-18  1:53 [PATCH net] net: fix the missing unlock for detached devices Jakub Kicinski
@ 2025-04-18 11:51 ` Mina Almasry
  2025-04-18 14:14   ` Stanislav Fomichev
  2025-04-22  9:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 6+ messages in thread
From: Mina Almasry @ 2025-04-18 11:51 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, jdamato,
	sdf, ap420073

On Thu, Apr 17, 2025 at 6:53 PM Jakub Kicinski <kuba@kernel.org> 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")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Mina Almasry <almasrymina@google.com>

> ---
> CC: jdamato@fastly.com
> CC: almasrymina@google.com
> CC: sdf@fomichev.me
> CC: ap420073@gmail.com
> ---
>  net/core/netdev-genl.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
> index 5d7af50fe702..230743bdbb14 100644
> --- a/net/core/netdev-genl.c
> +++ b/net/core/netdev-genl.c
> @@ -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.

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


-- 
Thanks,
Mina

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

* Re: [PATCH net] net: fix the missing unlock for detached devices
  2025-04-18 11:51 ` Mina Almasry
@ 2025-04-18 14:14   ` Stanislav Fomichev
  2025-04-18 20:38     ` Mina Almasry
  0 siblings, 1 reply; 6+ messages in thread
From: Stanislav Fomichev @ 2025-04-18 14:14 UTC (permalink / raw)
  To: Mina Almasry
  Cc: Jakub Kicinski, davem, netdev, edumazet, pabeni, andrew+netdev,
	horms, jdamato, sdf, ap420073

On 04/18, Mina Almasry wrote:
> On Thu, Apr 17, 2025 at 6:53 PM Jakub Kicinski <kuba@kernel.org> 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")
> > Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> 
> Reviewed-by: Mina Almasry <almasrymina@google.com>

Mina, the same (unlock netedev on !present) needs to happen for
https://lore.kernel.org/netdev/20250417231540.2780723-5-almasrymina@google.com/

Presumably you'll do another repost at some point?

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

* Re: [PATCH net] net: fix the missing unlock for detached devices
  2025-04-18 14:14   ` Stanislav Fomichev
@ 2025-04-18 20:38     ` Mina Almasry
  2025-04-21 15:24       ` Stanislav Fomichev
  0 siblings, 1 reply; 6+ messages in thread
From: Mina Almasry @ 2025-04-18 20:38 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: Jakub Kicinski, davem, netdev, edumazet, pabeni, andrew+netdev,
	horms, jdamato, sdf, ap420073

On Fri, Apr 18, 2025 at 7:14 AM Stanislav Fomichev <stfomichev@gmail.com> wrote:
>
> On 04/18, Mina Almasry wrote:
> > On Thu, Apr 17, 2025 at 6:53 PM Jakub Kicinski <kuba@kernel.org> 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")
> > > Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> >
> > Reviewed-by: Mina Almasry <almasrymina@google.com>
>
> Mina, the same (unlock netedev on !present) needs to happen for
> https://lore.kernel.org/netdev/20250417231540.2780723-5-almasrymina@google.com/
>
> 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.

-- 
Thanks,
Mina

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

* Re: [PATCH net] net: fix the missing unlock for detached devices
  2025-04-18 20:38     ` Mina Almasry
@ 2025-04-21 15:24       ` Stanislav Fomichev
  0 siblings, 0 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2025-04-21 15:24 UTC (permalink / raw)
  To: Mina Almasry
  Cc: Jakub Kicinski, davem, netdev, edumazet, pabeni, andrew+netdev,
	horms, jdamato, sdf, ap420073

On 04/18, Mina Almasry wrote:
> On Fri, Apr 18, 2025 at 7:14 AM Stanislav Fomichev <stfomichev@gmail.com> wrote:
> >
> > On 04/18, Mina Almasry wrote:
> > > On Thu, Apr 17, 2025 at 6:53 PM Jakub Kicinski <kuba@kernel.org> 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")
> > > > Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> > >
> > > Reviewed-by: Mina Almasry <almasrymina@google.com>
> >
> > Mina, the same (unlock netedev on !present) needs to happen for
> > https://lore.kernel.org/netdev/20250417231540.2780723-5-almasrymina@google.com/
> >
> > 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.

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

* Re: [PATCH net] net: fix the missing unlock for detached devices
  2025-04-18  1:53 [PATCH net] net: fix the missing unlock for detached devices Jakub Kicinski
  2025-04-18 11:51 ` Mina Almasry
@ 2025-04-22  9:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-22  9:10 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, andrew+netdev, horms, jdamato,
	almasrymina, sdf, ap420073

Hello:

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

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")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-04-22  9:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18  1:53 [PATCH net] net: fix the missing unlock for detached devices Jakub Kicinski
2025-04-18 11:51 ` Mina Almasry
2025-04-18 14:14   ` Stanislav Fomichev
2025-04-18 20:38     ` Mina Almasry
2025-04-21 15:24       ` Stanislav Fomichev
2025-04-22  9:10 ` 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;
as well as URLs for NNTP newsgroup(s).