Skip to content

Commit

Permalink
devlink: fix possible use-after-free and memory leaks in devlink_init()
Browse files Browse the repository at this point in the history
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: 687125b ("devlink: split out core code")
Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
Link: https://lore.kernel.org/r/20240215203400.29976-1-kovalev@altlinux.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Vasiliy Kovalev authored and Paolo Abeni committed Feb 20, 2024
1 parent 5559cea commit def689f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions net/devlink/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit def689f

Please sign in to comment.