Skip to contentSkip to conversation

devlink: fix possible use-after-free and memory leaks in devlink_init()

PATCH Applied [email protected] 2 participants 2 messages Feb 15, 2024 – Feb 20, 2024

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

PATCH 1/1 devlink: fix possible use-after-free and memory leaks in devlink_init()

From: Vasiliy Kovalev <[email protected]>

The pernet operations structure for the subsystem must be registered before registering the generic netlink family.

Make an unregister in case of unsuccessful registration.

Fixes 687125b5799c ("devlink: split out core code")
---
 net/devlink/core.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
net/devlink/core.c +9 -3
index 4275a2bc6d8e06..b3178512878d65 100644
@@ -529,14 +529,20 @@ static int __init devlink_init(void)
 {
 	int err;
 
-	err = genl_register_family(&devlink_nl_family);
-	if (err)
-		goto out;
 	err = register_pernet_subsys(&devlink_pernet_ops);
 	if (err)
 		goto out;
+	err = genl_register_family(&devlink_nl_family);
+	if (err)
+		goto out_unreg_pernet_subsys;
 	err = register_netdevice_notifier(&devlink_port_netdevice_nb);
+	if (!err)
+		return 0;
+
+	genl_unregister_family(&devlink_nl_family);
 
+out_unreg_pernet_subsys:
+	unregister_pernet_subsys(&devlink_pernet_ops);
 out:
 	WARN_ON(err);
 	return err;
Signature · 1 line
2.33.8
#1 lore raw
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Thu, 15 Feb 2024 23:34:00 +0300 you wrote:

From: Vasiliy Kovalev <[email protected]>

The pernet operations structure for the subsystem must be registered before registering the generic netlink family.

Make an unregister in case of unsuccessful registration.

[...]

Here is the summary with links:
- devlink: fix possible use-after-free and memory leaks in devlink_init()

    https://git.kernel.org/netdev/net/c/def689fc26b9

You are awesome, thank you!

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