vfs: Verify acls are valid within superblock's s_user_ns.
authorEric W. Biederman <ebiederm@xmission.com>
Mon, 27 Jun 2016 21:04:06 +0000 (16:04 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Thu, 30 Jun 2016 23:04:58 +0000 (18:04 -0500)
Update posix_acl_valid to verify that an acl is within a user namespace.

Update the callers of posix_acl_valid to pass in an appropriate
user namespace.  For posix_acl_xattr_set and v9fs_xattr_set_acl pass in
inode->i_sb->s_user_ns to posix_acl_valid.  For md_unpack_acl pass in
&init_user_ns as no inode or superblock is in sight.

Acked-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
drivers/staging/lustre/lustre/mdc/mdc_request.c
fs/9p/acl.c
fs/posix_acl.c
include/linux/posix_acl.h

index 86b7445365f43b2c16ace7e57b0ec57d26e2605a..40cf57fad58197730a2512a9dc8660d98cb4f29c 100644 (file)
@@ -434,7 +434,7 @@ static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
                return rc;
        }
 
-       rc = posix_acl_valid(acl);
+       rc = posix_acl_valid(&init_user_ns, acl);
        if (rc) {
                CERROR("validate acl: %d\n", rc);
                posix_acl_release(acl);
index 0576eaeb60b952341f8b739db4e458128aab757c..5b6a1743ea17bdf33f3c76a3929dde92d8051eb6 100644 (file)
@@ -266,7 +266,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
                if (IS_ERR(acl))
                        return PTR_ERR(acl);
                else if (acl) {
-                       retval = posix_acl_valid(acl);
+                       retval = posix_acl_valid(inode->i_sb->s_user_ns, acl);
                        if (retval)
                                goto err_out;
                }
index 8a4a266beff39dda0be9ca39df74bc847fd0a2d3..647c28180675b31b1b54c435421c68a571aadfab 100644 (file)
@@ -205,7 +205,7 @@ posix_acl_clone(const struct posix_acl *acl, gfp_t flags)
  * Check if an acl is valid. Returns 0 if it is, or -E... otherwise.
  */
 int
-posix_acl_valid(const struct posix_acl *acl)
+posix_acl_valid(struct user_namespace *user_ns, const struct posix_acl *acl)
 {
        const struct posix_acl_entry *pa, *pe;
        int state = ACL_USER_OBJ;
@@ -225,7 +225,7 @@ posix_acl_valid(const struct posix_acl *acl)
                        case ACL_USER:
                                if (state != ACL_USER)
                                        return -EINVAL;
-                               if (!uid_valid(pa->e_uid))
+                               if (!kuid_has_mapping(user_ns, pa->e_uid))
                                        return -EINVAL;
                                needs_mask = 1;
                                break;
@@ -240,7 +240,7 @@ posix_acl_valid(const struct posix_acl *acl)
                        case ACL_GROUP:
                                if (state != ACL_GROUP)
                                        return -EINVAL;
-                               if (!gid_valid(pa->e_gid))
+                               if (!kgid_has_mapping(user_ns, pa->e_gid))
                                        return -EINVAL;
                                needs_mask = 1;
                                break;
@@ -845,7 +845,7 @@ posix_acl_xattr_set(const struct xattr_handler *handler,
                        return PTR_ERR(acl);
 
                if (acl) {
-                       ret = posix_acl_valid(acl);
+                       ret = posix_acl_valid(inode->i_sb->s_user_ns, acl);
                        if (ret)
                                goto out;
                }
index 5b5a80cc59265882813cddba568b0875797e5e6b..1af6438fde3e405ca8f61de51f05b357565dc043 100644 (file)
@@ -81,7 +81,7 @@ posix_acl_release(struct posix_acl *acl)
 
 extern void posix_acl_init(struct posix_acl *, int);
 extern struct posix_acl *posix_acl_alloc(int, gfp_t);
-extern int posix_acl_valid(const struct posix_acl *);
+extern int posix_acl_valid(struct user_namespace *, const struct posix_acl *);
 extern int posix_acl_permission(struct inode *, const struct posix_acl *, int);
 extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
 extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);