diff options
author | Vasiliy Kovalev <kovalev@altlinux.org> | 2024-02-15 23:34:00 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-03-01 13:35:07 +0100 |
commit | 919092bd5482b7070ae66d1daef73b600738f3a2 (patch) | |
tree | 2efcfea31966668b41b73333e2d2d0ab959f67ed /net/devlink | |
parent | 9e02973dbc6a91e40aa4f5d87b8c47446fbfce44 (diff) | |
download | linux-stable-919092bd5482b7070ae66d1daef73b600738f3a2.tar.gz linux-stable-919092bd5482b7070ae66d1daef73b600738f3a2.tar.bz2 linux-stable-919092bd5482b7070ae66d1daef73b600738f3a2.zip |
devlink: fix possible use-after-free and memory leaks in devlink_init()
[ Upstream commit def689fc26b9a9622d2e2cb0c4933dd3b1c8071c ]
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")
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net/devlink')
-rw-r--r-- | net/devlink/core.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/net/devlink/core.c b/net/devlink/core.c index 6cec4afb01fb..451f2bc141a0 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -308,14 +308,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; |