Skip to contentSkip to conversation

devlink: fix netns refcount leak in devlink_nl_cmd_reload()

PATCH Applied Eric Dumazet 3 participants 3 messages Dec 5, 2021 – Dec 7, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devlink: fix netns refcount leak in devlink_nl_cmd_reload()

From: Eric Dumazet <[email protected]>

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")
Cc Moshe Shemesh <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Jacob Keller <[email protected]>
Cc Jiri Pirko <[email protected]>
---
 net/core/devlink.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
net/core/devlink.c +8 -8
index 5ad72dbfcd0797ae045734b83fbbdc090ae3ff53..c06c9ba6e8c5ea00a3999700a6724a404c1f05f9 100644
@@ -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)
Signature · 1 line
2.34.1.400.ga245620fadb-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

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")
Cc Moshe Shemesh <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Jacob Keller <[email protected]>
Cc Jiri Pirko <[email protected]>
Quoted 4 lines
---
 net/core/devlink.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Thanks,

#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Sun, 5 Dec 2021 11:28:22 -0800 you wrote:

From: Eric Dumazet <[email protected]>

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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html