netns: do not leak net_generic data on failed init
ops_init should free the net_generic data on init failure and __register_pernet_operations should not call ops_free when NET_NS is not enabled. Signed-off-by: Julian Anastasov <ja@ssi.bg> Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
9fe5642f4a
commit
b922934d01
1 changed files with 18 additions and 15 deletions
|
@ -83,21 +83,29 @@ static int net_assign_generic(struct net *net, int id, void *data)
|
||||||
|
|
||||||
static int ops_init(const struct pernet_operations *ops, struct net *net)
|
static int ops_init(const struct pernet_operations *ops, struct net *net)
|
||||||
{
|
{
|
||||||
int err;
|
int err = -ENOMEM;
|
||||||
|
void *data = NULL;
|
||||||
|
|
||||||
if (ops->id && ops->size) {
|
if (ops->id && ops->size) {
|
||||||
void *data = kzalloc(ops->size, GFP_KERNEL);
|
data = kzalloc(ops->size, GFP_KERNEL);
|
||||||
if (!data)
|
if (!data)
|
||||||
return -ENOMEM;
|
goto out;
|
||||||
|
|
||||||
err = net_assign_generic(net, *ops->id, data);
|
err = net_assign_generic(net, *ops->id, data);
|
||||||
if (err) {
|
if (err)
|
||||||
kfree(data);
|
goto cleanup;
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
err = 0;
|
||||||
if (ops->init)
|
if (ops->init)
|
||||||
return ops->init(net);
|
err = ops->init(net);
|
||||||
return 0;
|
if (!err)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
kfree(data);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ops_free(const struct pernet_operations *ops, struct net *net)
|
static void ops_free(const struct pernet_operations *ops, struct net *net)
|
||||||
|
@ -448,12 +456,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
|
||||||
static int __register_pernet_operations(struct list_head *list,
|
static int __register_pernet_operations(struct list_head *list,
|
||||||
struct pernet_operations *ops)
|
struct pernet_operations *ops)
|
||||||
{
|
{
|
||||||
int err = 0;
|
return ops_init(ops, &init_net);
|
||||||
err = ops_init(ops, &init_net);
|
|
||||||
if (err)
|
|
||||||
ops_free(ops, &init_net);
|
|
||||||
return err;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __unregister_pernet_operations(struct pernet_operations *ops)
|
static void __unregister_pernet_operations(struct pernet_operations *ops)
|
||||||
|
|
Loading…
Reference in a new issue