summaryrefslogtreecommitdiffstats
path: root/kernel/user_namespace.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2011-11-16 21:59:43 -0800
committerEric W. Biederman <ebiederm@xmission.com>2012-04-07 16:55:52 -0700
commitaeb3ae9da9b50a386b22af786d19b623e8d9f0fa (patch)
tree3db9772ea99c931914bec7ded51f896f1d2e24ec /kernel/user_namespace.c
parent0093ccb68f3753c0ba4d74c89d7e0f444b8d6123 (diff)
downloadblackbird-op-linux-aeb3ae9da9b50a386b22af786d19b623e8d9f0fa.tar.gz
blackbird-op-linux-aeb3ae9da9b50a386b22af786d19b623e8d9f0fa.zip
userns: Add an explicit reference to the parent user namespace
I am about to remove the struct user_namespace reference from struct user_struct. So keep an explicit track of the parent user namespace. Take advantage of this new reference and replace instances of user_ns->creator->user_ns with user_ns->parent. Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'kernel/user_namespace.c')
-rw-r--r--kernel/user_namespace.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 58bb8781a778..c15e533d6bc5 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -45,6 +45,7 @@ int create_user_ns(struct cred *new)
}
/* set the new root user in the credentials under preparation */
+ ns->parent = parent_ns;
ns->creator = new->user;
new->user = root_user;
new->uid = new->euid = new->suid = new->fsuid = 0;
@@ -60,8 +61,6 @@ int create_user_ns(struct cred *new)
/* Leave the reference to our user_ns with the new cred */
new->user_ns = ns;
- put_user_ns(parent_ns);
-
return 0;
}
@@ -72,10 +71,12 @@ int create_user_ns(struct cred *new)
*/
static void free_user_ns_work(struct work_struct *work)
{
- struct user_namespace *ns =
+ struct user_namespace *parent, *ns =
container_of(work, struct user_namespace, destroyer);
+ parent = ns->parent;
free_uid(ns->creator);
kmem_cache_free(user_ns_cachep, ns);
+ put_user_ns(parent);
}
void free_user_ns(struct kref *kref)
@@ -99,8 +100,7 @@ uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t
/* Is cred->user the creator of the target user_ns
* or the creator of one of it's parents?
*/
- for ( tmp = to; tmp != &init_user_ns;
- tmp = tmp->creator->user_ns ) {
+ for ( tmp = to; tmp != &init_user_ns; tmp = tmp->parent ) {
if (cred->user == tmp->creator) {
return (uid_t)0;
}
@@ -120,8 +120,7 @@ gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t
/* Is cred->user the creator of the target user_ns
* or the creator of one of it's parents?
*/
- for ( tmp = to; tmp != &init_user_ns;
- tmp = tmp->creator->user_ns ) {
+ for ( tmp = to; tmp != &init_user_ns; tmp = tmp->parent ) {
if (cred->user == tmp->creator) {
return (gid_t)0;
}
OpenPOWER on IntegriCloud