Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

user namespace: fix copy_user_ns return value

When a CONFIG_USER_NS=n and a user tries to unshare some namespace other
than the user namespace, the dummy copy_user_ns returns NULL rather than
the old_ns.

This value then gets assigned to task->nsproxy->user_ns, so that a
subsequent setuid, which uses task->nsproxy->user_ns, causes a NULL
pointer deref.

Fix this by returning old_ns.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Serge E. Hallyn and committed by
Linus Torvalds
626ac545 9550b105

+1 -1
+1 -1
include/linux/user_namespace.h
··· 49 if (flags & CLONE_NEWUSER) 50 return ERR_PTR(-EINVAL); 51 52 - return NULL; 53 } 54 55 static inline void put_user_ns(struct user_namespace *ns)
··· 49 if (flags & CLONE_NEWUSER) 50 return ERR_PTR(-EINVAL); 51 52 + return old_ns; 53 } 54 55 static inline void put_user_ns(struct user_namespace *ns)