diff options
author | Cedric Le Goater <clg@fr.ibm.com> | 2007-06-23 20:16:25 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-06-24 11:59:10 -0400 |
commit | 4e71e474c784dc274f28ec8bb22a5dbabc6dc7c5 (patch) | |
tree | 2a14a2d1efe99fe2a8e9c01ba851d6c28ddbef23 /kernel/nsproxy.c | |
parent | 6d79af701d334777541136e914a9c0969b2ad307 (diff) |
fix refcounting of nsproxy object when unshared
When a namespace is unshared, a refcount on the previous nsproxy is
abusively taken, leading to a memory leak of nsproxy objects.
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Cc: Badari Pulavarty <pbadari@us.ibm.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/nsproxy.c')
-rw-r--r-- | kernel/nsproxy.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index 1bc4b55241a8..9e83b589f754 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c | |||
@@ -145,13 +145,11 @@ void free_nsproxy(struct nsproxy *ns) | |||
145 | 145 | ||
146 | /* | 146 | /* |
147 | * Called from unshare. Unshare all the namespaces part of nsproxy. | 147 | * Called from unshare. Unshare all the namespaces part of nsproxy. |
148 | * On sucess, returns the new nsproxy and a reference to old nsproxy | 148 | * On success, returns the new nsproxy. |
149 | * to make sure it stays around. | ||
150 | */ | 149 | */ |
151 | int unshare_nsproxy_namespaces(unsigned long unshare_flags, | 150 | int unshare_nsproxy_namespaces(unsigned long unshare_flags, |
152 | struct nsproxy **new_nsp, struct fs_struct *new_fs) | 151 | struct nsproxy **new_nsp, struct fs_struct *new_fs) |
153 | { | 152 | { |
154 | struct nsproxy *old_ns = current->nsproxy; | ||
155 | int err = 0; | 153 | int err = 0; |
156 | 154 | ||
157 | if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC))) | 155 | if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC))) |
@@ -170,13 +168,9 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags, | |||
170 | if (!capable(CAP_SYS_ADMIN)) | 168 | if (!capable(CAP_SYS_ADMIN)) |
171 | return -EPERM; | 169 | return -EPERM; |
172 | 170 | ||
173 | get_nsproxy(old_ns); | ||
174 | |||
175 | *new_nsp = create_new_namespaces(unshare_flags, current, | 171 | *new_nsp = create_new_namespaces(unshare_flags, current, |
176 | new_fs ? new_fs : current->fs); | 172 | new_fs ? new_fs : current->fs); |
177 | if (IS_ERR(*new_nsp)) { | 173 | if (IS_ERR(*new_nsp)) |
178 | err = PTR_ERR(*new_nsp); | 174 | err = PTR_ERR(*new_nsp); |
179 | put_nsproxy(old_ns); | ||
180 | } | ||
181 | return err; | 175 | return err; |
182 | } | 176 | } |