Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
[linux-2.6-microblaze.git] / kernel / user_namespace.c
index 9a4b980..ef82d40 100644 (file)
@@ -85,7 +85,7 @@ int create_user_ns(struct cred *new)
        /*
         * Verify that we can not violate the policy of which files
         * may be accessed that is specified by the root directory,
-        * by verifing that the root directory is at the root of the
+        * by verifying that the root directory is at the root of the
         * mount namespace which allows all files to be accessed.
         */
        ret = -EPERM;
@@ -119,9 +119,13 @@ int create_user_ns(struct cred *new)
        ns->owner = owner;
        ns->group = group;
        INIT_WORK(&ns->work, free_user_ns);
-       for (i = 0; i < UCOUNT_COUNTS; i++) {
+       for (i = 0; i < MAX_PER_NAMESPACE_UCOUNTS; i++) {
                ns->ucount_max[i] = INT_MAX;
        }
+       set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC));
+       set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_MSGQUEUE, rlimit(RLIMIT_MSGQUEUE));
+       set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_SIGPENDING, rlimit(RLIMIT_SIGPENDING));
+       set_rlimit_ucount_max(ns, UCOUNT_RLIMIT_MEMLOCK, rlimit(RLIMIT_MEMLOCK));
        ns->ucounts = ucounts;
 
        /* Inherit USERNS_SETGROUPS_ALLOWED from our parent */
@@ -1014,7 +1018,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
                        goto out;
                ret = -EINVAL;
        }
-       /* Be very certaint the new map actually exists */
+       /* Be very certain the new map actually exists */
        if (new_map.nr_extents == 0)
                goto out;
 
@@ -1169,7 +1173,7 @@ static bool new_idmap_permitted(const struct file *file,
 
        /* Allow the specified ids if we have the appropriate capability
         * (CAP_SETUID or CAP_SETGID) over the parent user namespace.
-        * And the opener of the id file also had the approprpiate capability.
+        * And the opener of the id file also has the appropriate capability.
         */
        if (ns_capable(ns->parent, cap_setid) &&
            file_ns_capable(file, ns->parent, cap_setid))
@@ -1340,6 +1344,9 @@ static int userns_install(struct nsset *nsset, struct ns_common *ns)
        put_user_ns(cred->user_ns);
        set_cred_user_ns(cred, get_user_ns(user_ns));
 
+       if (set_cred_ucounts(cred) < 0)
+               return -EINVAL;
+
        return 0;
 }