diff options
author | Julian Anastasov <ja@ssi.bg> | 2012-04-16 00:43:15 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-04-18 00:05:33 -0400 |
commit | b922934d017f1cc831b017913ed7d1a56c558b43 (patch) | |
tree | 6d0d08fc459a3eb2d36bccea023059ef76b90dfe /net | |
parent | 9fe5642f4a3b13beb43c2633db7df22dd9d99250 (diff) |
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>
Diffstat (limited to 'net')
-rw-r--r-- | net/core/net_namespace.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 0e950fda9a0a..31a5ae51a45c 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c | |||
@@ -83,21 +83,29 @@ assign: | |||
83 | 83 | ||
84 | static int ops_init(const struct pernet_operations *ops, struct net *net) | 84 | static int ops_init(const struct pernet_operations *ops, struct net *net) |
85 | { | 85 | { |
86 | int err; | 86 | int err = -ENOMEM; |
87 | void *data = NULL; | ||
88 | |||
87 | if (ops->id && ops->size) { | 89 | if (ops->id && ops->size) { |
88 | void *data = kzalloc(ops->size, GFP_KERNEL); | 90 | data = kzalloc(ops->size, GFP_KERNEL); |
89 | if (!data) | 91 | if (!data) |
90 | return -ENOMEM; | 92 | goto out; |
91 | 93 | ||
92 | err = net_assign_generic(net, *ops->id, data); | 94 | err = net_assign_generic(net, *ops->id, data); |
93 | if (err) { | 95 | if (err) |
94 | kfree(data); | 96 | goto cleanup; |
95 | return err; | ||
96 | } | ||
97 | } | 97 | } |
98 | err = 0; | ||
98 | if (ops->init) | 99 | if (ops->init) |
99 | return ops->init(net); | 100 | err = ops->init(net); |
100 | return 0; | 101 | if (!err) |
102 | return 0; | ||
103 | |||
104 | cleanup: | ||
105 | kfree(data); | ||
106 | |||
107 | out: | ||
108 | return err; | ||
101 | } | 109 | } |
102 | 110 | ||
103 | static void ops_free(const struct pernet_operations *ops, struct net *net) | 111 | 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) | |||
448 | static int __register_pernet_operations(struct list_head *list, | 456 | static int __register_pernet_operations(struct list_head *list, |
449 | struct pernet_operations *ops) | 457 | struct pernet_operations *ops) |
450 | { | 458 | { |
451 | int err = 0; | 459 | return ops_init(ops, &init_net); |
452 | err = ops_init(ops, &init_net); | ||
453 | if (err) | ||
454 | ops_free(ops, &init_net); | ||
455 | return err; | ||
456 | |||
457 | } | 460 | } |
458 | 461 | ||
459 | static void __unregister_pernet_operations(struct pernet_operations *ops) | 462 | static void __unregister_pernet_operations(struct pernet_operations *ops) |