summaryrefslogtreecommitdiff
path: root/kernel/user_namespace.c
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-08-27 15:40:03 +0100
committerMark Brown <broonie@linaro.org>2013-08-27 15:40:03 +0100
commitdc1632321ba1e93dde25870e96cebe21b7d52517 (patch)
treed52d934c79b23f91654c571d983e1a6ec41b71fd /kernel/user_namespace.c
parent8c193b8dce4f2a2474dc2bc39ec972454df9d439 (diff)
parenta85f9da707366e856c0aad9e329db0cc59475290 (diff)
Merge remote-tracking branch 'asoc/topic/dmic' into asoc-core
Diffstat (limited to 'kernel/user_namespace.c')
-rw-r--r--kernel/user_namespace.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index d8c30db06c5b..9064b919a406 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -62,6 +62,9 @@ int create_user_ns(struct cred *new)
kgid_t group = new->egid;
int ret;
+ if (parent_ns->level > 32)
+ return -EUSERS;
+
/*
* Verify that we can not violate the policy of which files
* may be accessed that is specified by the root directory,
@@ -92,6 +95,7 @@ int create_user_ns(struct cred *new)
atomic_set(&ns->count, 1);
/* Leave the new->user_ns reference with the new user namespace. */
ns->parent = parent_ns;
+ ns->level = parent_ns->level + 1;
ns->owner = owner;
ns->group = group;
@@ -105,16 +109,21 @@ int create_user_ns(struct cred *new)
int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
{
struct cred *cred;
+ int err = -ENOMEM;
if (!(unshare_flags & CLONE_NEWUSER))
return 0;
cred = prepare_creds();
- if (!cred)
- return -ENOMEM;
+ if (cred) {
+ err = create_user_ns(cred);
+ if (err)
+ put_cred(cred);
+ else
+ *new_cred = cred;
+ }
- *new_cred = cred;
- return create_user_ns(cred);
+ return err;
}
void free_user_ns(struct user_namespace *ns)