Commit 392767a8 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Luis Henriques

(namespace) vfs: Verify acls are valid within superblock's s_user_ns.

BugLink: http://bugs.launchpad.net/bugs/1634964

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: default avatarSeth Forshee <seth.forshee@canonical.com>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
(backported from commit 0d4d717f)
[ saf: Adjust context for addition of set_posix_acl(), update zfs
  calls to posix_acl_valid() ]
Signed-off-by: default avatarSeth Forshee <seth.forshee@canonical.com>
Acked-by: default avatarTim Gardner <tim.gardner@canonical.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent aad49181
...@@ -433,7 +433,7 @@ static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md) ...@@ -433,7 +433,7 @@ static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
return rc; return rc;
} }
rc = posix_acl_valid(acl); rc = posix_acl_valid(&init_user_ns, acl);
if (rc) { if (rc) {
CERROR("validate acl: %d\n", rc); CERROR("validate acl: %d\n", rc);
posix_acl_release(acl); posix_acl_release(acl);
......
...@@ -272,7 +272,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler, ...@@ -272,7 +272,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
if (IS_ERR(acl)) if (IS_ERR(acl))
return PTR_ERR(acl); return PTR_ERR(acl);
else if (acl) { else if (acl) {
retval = posix_acl_valid(acl); retval = posix_acl_valid(inode->i_sb->s_user_ns, acl);
if (retval) if (retval)
goto err_out; goto err_out;
} }
......
...@@ -171,7 +171,7 @@ posix_acl_clone(const struct posix_acl *acl, gfp_t flags) ...@@ -171,7 +171,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. * Check if an acl is valid. Returns 0 if it is, or -E... otherwise.
*/ */
int 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; const struct posix_acl_entry *pa, *pe;
int state = ACL_USER_OBJ; int state = ACL_USER_OBJ;
...@@ -191,7 +191,7 @@ posix_acl_valid(const struct posix_acl *acl) ...@@ -191,7 +191,7 @@ posix_acl_valid(const struct posix_acl *acl)
case ACL_USER: case ACL_USER:
if (state != ACL_USER) if (state != ACL_USER)
return -EINVAL; return -EINVAL;
if (!uid_valid(pa->e_uid)) if (!kuid_has_mapping(user_ns, pa->e_uid))
return -EINVAL; return -EINVAL;
needs_mask = 1; needs_mask = 1;
break; break;
...@@ -206,7 +206,7 @@ posix_acl_valid(const struct posix_acl *acl) ...@@ -206,7 +206,7 @@ posix_acl_valid(const struct posix_acl *acl)
case ACL_GROUP: case ACL_GROUP:
if (state != ACL_GROUP) if (state != ACL_GROUP)
return -EINVAL; return -EINVAL;
if (!gid_valid(pa->e_gid)) if (!kgid_has_mapping(user_ns, pa->e_gid))
return -EINVAL; return -EINVAL;
needs_mask = 1; needs_mask = 1;
break; break;
...@@ -833,7 +833,7 @@ set_posix_acl(struct inode *inode, int type, struct posix_acl *acl) ...@@ -833,7 +833,7 @@ set_posix_acl(struct inode *inode, int type, struct posix_acl *acl)
return -EPERM; return -EPERM;
if (acl) { if (acl) {
int ret = posix_acl_valid(acl); int ret = posix_acl_valid(inode->i_sb->s_user_ns, acl);
if (ret) if (ret)
return ret; return ret;
} }
......
...@@ -81,7 +81,7 @@ posix_acl_release(struct posix_acl *acl) ...@@ -81,7 +81,7 @@ posix_acl_release(struct posix_acl *acl)
extern void posix_acl_init(struct posix_acl *, int); extern void posix_acl_init(struct posix_acl *, int);
extern struct posix_acl *posix_acl_alloc(int, gfp_t); 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 int posix_acl_permission(struct inode *, const struct posix_acl *, int);
extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t); extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t);
extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *); extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *);
......
...@@ -1281,7 +1281,7 @@ __zpl_xattr_acl_set_access(struct inode *ip, const char *name, ...@@ -1281,7 +1281,7 @@ __zpl_xattr_acl_set_access(struct inode *ip, const char *name,
if (IS_ERR(acl)) if (IS_ERR(acl))
return (PTR_ERR(acl)); return (PTR_ERR(acl));
else if (acl) { else if (acl) {
error = posix_acl_valid(acl); error = posix_acl_valid(ip->i_sb->s_user_ns, acl);
if (error) { if (error) {
zpl_posix_acl_release(acl); zpl_posix_acl_release(acl);
return (error); return (error);
...@@ -1320,7 +1320,7 @@ __zpl_xattr_acl_set_default(struct inode *ip, const char *name, ...@@ -1320,7 +1320,7 @@ __zpl_xattr_acl_set_default(struct inode *ip, const char *name,
if (IS_ERR(acl)) if (IS_ERR(acl))
return (PTR_ERR(acl)); return (PTR_ERR(acl));
else if (acl) { else if (acl) {
error = posix_acl_valid(acl); error = posix_acl_valid(ip->i_sb->s_user_ns, acl);
if (error) { if (error) {
zpl_posix_acl_release(acl); zpl_posix_acl_release(acl);
return (error); return (error);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment