[Devel] [PATCH 03/10] user namespaces: reset task's credentials on CLONE_NEWUSER
Serge E. Hallyn
serue at us.ibm.com
Fri Aug 22 12:45:58 PDT 2008
Currently, creating a new user namespace does not reset
the task's uid or gid. Since generally that is done as
root because it requires CAP_SYS_ADMIN, and since the
first uid in the new namespace is 0, one usually doesn't
notice. However, if one does
capset cap_sys_admin=ep ns_exec
su - hallyn
ns_exec -U /bin/sh
id
then one will see hallyn's userid, and all preexisting
groups.
With this patch, cloning a new user namespace will set
the task's uid and gid to 0, and reset the group_info to
the empty set assigned to init.
Signed-off-by: Serge E. Hallyn <serue at us.ibm.com>
---
kernel/user_namespace.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 0045dd0..39aea7b 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -11,6 +11,9 @@
#include <linux/slab.h>
#include <linux/user_namespace.h>
+/* defined in kernel/sys.c */
+extern struct group_info init_groups;
+
/*
* Clone a new ns copying an original user ns, setting refcount to 1
* @old_ns: namespace to clone
@@ -48,6 +51,17 @@ int create_new_userns(int flags, struct task_struct *tsk)
put_user_ns(ns);
task_switch_uid(tsk, ns->root_user);
+ tsk->uid = tsk->euid = tsk->suid = tsk->fsuid = 0;
+ tsk->gid = tsk->egid = tsk->sgid = tsk->fsgid = 0;
+
+ /* this can't be safe for unshare, can it? it's safe
+ * for fork, though. I'm tempted to limit clone_newuser to
+ * fork only */
+ task_lock(tsk);
+ put_group_info(tsk->group_info);
+ tsk->group_info = &init_groups;
+ get_group_info(tsk->group_info);
+ task_unlock(tsk);
return 0;
}
--
1.5.4.3
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
More information about the Devel
mailing list