Skip to content

Commit e66eded

Browse files
ebiedermtorvalds
authored andcommitted
userns: Don't allow CLONE_NEWUSER | CLONE_FS
Don't allowing sharing the root directory with processes in a different user namespace. There doesn't seem to be any point, and to allow it would require the overhead of putting a user namespace reference in fs_struct (for permission checks) and incrementing that reference count on practically every call to fork. So just perform the inexpensive test of forbidding sharing fs_struct acrosss processes in different user namespaces. We already disallow other forms of threading when unsharing a user namespace so this should be no real burden in practice. This updates setns, clone, and unshare to disallow multiple user namespaces sharing an fs_struct. Cc: stable@vger.kernel.org Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6c23cbb commit e66eded

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎kernel/fork.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
11411141
if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
11421142
return ERR_PTR(-EINVAL);
11431143

1144+
if ((clone_flags & (CLONE_NEWUSER|CLONE_FS)) == (CLONE_NEWUSER|CLONE_FS))
1145+
return ERR_PTR(-EINVAL);
1146+
11441147
/*
11451148
* Thread groups must share signals as well, and detached threads
11461149
* can only be started up within the thread group.
@@ -1807,7 +1810,7 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
18071810
* If unsharing a user namespace must also unshare the thread.
18081811
*/
18091812
if (unshare_flags & CLONE_NEWUSER)
1810-
unshare_flags |= CLONE_THREAD;
1813+
unshare_flags |= CLONE_THREAD | CLONE_FS;
18111814
/*
18121815
* If unsharing a pid namespace must also unshare the thread.
18131816
*/

‎kernel/user_namespace.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/uaccess.h>
2222
#include <linux/ctype.h>
2323
#include <linux/projid.h>
24+
#include <linux/fs_struct.h>
2425

2526
static struct kmem_cache *user_ns_cachep __read_mostly;
2627

@@ -837,6 +838,9 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
837838
if (atomic_read(&current->mm->mm_users) > 1)
838839
return -EINVAL;
839840

841+
if (current->fs->users != 1)
842+
return -EINVAL;
843+
840844
if (!ns_capable(user_ns, CAP_SYS_ADMIN))
841845
return -EPERM;
842846

0 commit comments

Comments
 (0)