Skip to content

Commit 4e71e47

Browse files
Cedric Le GoaterLinus Torvalds
authored andcommitted
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>
1 parent 6d79af7 commit 4e71e47

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

‎kernel/nsproxy.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,11 @@ void free_nsproxy(struct nsproxy *ns)
145145

146146
/*
147147
* Called from unshare. Unshare all the namespaces part of nsproxy.
148-
* On sucess, returns the new nsproxy and a reference to old nsproxy
149-
* to make sure it stays around.
148+
* On success, returns the new nsproxy.
150149
*/
151150
int unshare_nsproxy_namespaces(unsigned long unshare_flags,
152151
struct nsproxy **new_nsp, struct fs_struct *new_fs)
153152
{
154-
struct nsproxy *old_ns = current->nsproxy;
155153
int err = 0;
156154

157155
if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC)))
@@ -170,13 +168,9 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
170168
if (!capable(CAP_SYS_ADMIN))
171169
return -EPERM;
172170

173-
get_nsproxy(old_ns);
174-
175171
*new_nsp = create_new_namespaces(unshare_flags, current,
176172
new_fs ? new_fs : current->fs);
177-
if (IS_ERR(*new_nsp)) {
173+
if (IS_ERR(*new_nsp))
178174
err = PTR_ERR(*new_nsp);
179-
put_nsproxy(old_ns);
180-
}
181175
return err;
182176
}

0 commit comments

Comments
 (0)