netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] devlink: fix netns refcount leak in devlink_nl_cmd_reload()
@ 2021-12-05 19:28 Eric Dumazet
  2021-12-06  7:16 ` Leon Romanovsky
  2021-12-07  1:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2021-12-05 19:28 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski
  Cc: netdev, Eric Dumazet, Eric Dumazet, Moshe Shemesh, Jacob Keller,
	Jiri Pirko

From: Eric Dumazet <edumazet@google.com>

While preparing my patch series adding netns refcount tracking,
I spotted bugs in devlink_nl_cmd_reload()

Some error paths forgot to release a refcount on a netns.

To fix this, we can reduce the scope of get_net()/put_net()
section around the call to devlink_reload().

Fixes: ccdf07219da6 ("devlink: Add reload action option to devlink reload command")
Fixes: dc64cc7c6310 ("devlink: Add devlink reload limit option")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Moshe Shemesh <moshe@mellanox.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiri Pirko <jiri@nvidia.com>
---
 net/core/devlink.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index 5ad72dbfcd0797ae045734b83fbbdc090ae3ff53..c06c9ba6e8c5ea00a3999700a6724a404c1f05f9 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -4110,14 +4110,6 @@ static int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info)
 		return err;
 	}
 
-	if (info->attrs[DEVLINK_ATTR_NETNS_PID] ||
-	    info->attrs[DEVLINK_ATTR_NETNS_FD] ||
-	    info->attrs[DEVLINK_ATTR_NETNS_ID]) {
-		dest_net = devlink_netns_get(skb, info);
-		if (IS_ERR(dest_net))
-			return PTR_ERR(dest_net);
-	}
-
 	if (info->attrs[DEVLINK_ATTR_RELOAD_ACTION])
 		action = nla_get_u8(info->attrs[DEVLINK_ATTR_RELOAD_ACTION]);
 	else
@@ -4160,6 +4152,14 @@ static int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info)
 			return -EINVAL;
 		}
 	}
+	if (info->attrs[DEVLINK_ATTR_NETNS_PID] ||
+	    info->attrs[DEVLINK_ATTR_NETNS_FD] ||
+	    info->attrs[DEVLINK_ATTR_NETNS_ID]) {
+		dest_net = devlink_netns_get(skb, info);
+		if (IS_ERR(dest_net))
+			return PTR_ERR(dest_net);
+	}
+
 	err = devlink_reload(devlink, dest_net, action, limit, &actions_performed, info->extack);
 
 	if (dest_net)
-- 
2.34.1.400.ga245620fadb-goog


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

* Re: [PATCH net] devlink: fix netns refcount leak in devlink_nl_cmd_reload()
  2021-12-05 19:28 [PATCH net] devlink: fix netns refcount leak in devlink_nl_cmd_reload() Eric Dumazet
@ 2021-12-06  7:16 ` Leon Romanovsky
  2021-12-07  1:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2021-12-06  7:16 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, netdev, Eric Dumazet,
	Moshe Shemesh, Jacob Keller, Jiri Pirko

On Sun, Dec 05, 2021 at 11:28:22AM -0800, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> While preparing my patch series adding netns refcount tracking,
> I spotted bugs in devlink_nl_cmd_reload()
> 
> Some error paths forgot to release a refcount on a netns.
> 
> To fix this, we can reduce the scope of get_net()/put_net()
> section around the call to devlink_reload().
> 
> Fixes: ccdf07219da6 ("devlink: Add reload action option to devlink reload command")
> Fixes: dc64cc7c6310 ("devlink: Add devlink reload limit option")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Moshe Shemesh <moshe@mellanox.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Jacob Keller <jacob.e.keller@intel.com>
> Cc: Jiri Pirko <jiri@nvidia.com>
> ---
>  net/core/devlink.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 

Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>

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

* Re: [PATCH net] devlink: fix netns refcount leak in devlink_nl_cmd_reload()
  2021-12-05 19:28 [PATCH net] devlink: fix netns refcount leak in devlink_nl_cmd_reload() Eric Dumazet
  2021-12-06  7:16 ` Leon Romanovsky
@ 2021-12-07  1:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-07  1:10 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, netdev, edumazet, moshe, jacob.e.keller, jiri

Hello:

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

On Sun,  5 Dec 2021 11:28:22 -0800 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> While preparing my patch series adding netns refcount tracking,
> I spotted bugs in devlink_nl_cmd_reload()
> 
> Some error paths forgot to release a refcount on a netns.
> 
> [...]

Here is the summary with links:
  - [net] devlink: fix netns refcount leak in devlink_nl_cmd_reload()
    https://git.kernel.org/netdev/net/c/4dbb0dad8e63

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] 3+ messages in thread

end of thread, other threads:[~2021-12-07  1:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-05 19:28 [PATCH net] devlink: fix netns refcount leak in devlink_nl_cmd_reload() Eric Dumazet
2021-12-06  7:16 ` Leon Romanovsky
2021-12-07  1: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).