fs: port inode_owner_or_capable() to mnt_idmap
authorChristian Brauner <brauner@kernel.org>
Fri, 13 Jan 2023 11:49:26 +0000 (12:49 +0100)
committerChristian Brauner (Microsoft) <brauner@kernel.org>
Thu, 19 Jan 2023 08:24:29 +0000 (09:24 +0100)
Convert to struct mnt_idmap.

Last cycle we merged the necessary infrastructure in
256c8aed2b42 ("fs: introduce dedicated idmap type for mounts").
This is just the conversion to struct mnt_idmap.

Currently we still pass around the plain namespace that was attached to a
mount. This is in general pretty convenient but it makes it easy to
conflate namespaces that are relevant on the filesystem with namespaces
that are relevent on the mount level. Especially for non-vfs developers
without detailed knowledge in this area this can be a potential source for
bugs.

Once the conversion to struct mnt_idmap is done all helpers down to the
really low-level helpers will take a struct mnt_idmap argument instead of
two namespace arguments. This way it becomes impossible to conflate the two
eliminating the possibility of any bugs. All of the vfs and all filesystems
only operate on struct mnt_idmap.

Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
22 files changed:
fs/9p/acl.c
fs/attr.c
fs/btrfs/ioctl.c
fs/crypto/policy.c
fs/ext2/ioctl.c
fs/ext4/ioctl.c
fs/f2fs/file.c
fs/f2fs/xattr.c
fs/fcntl.c
fs/inode.c
fs/ioctl.c
fs/namei.c
fs/overlayfs/file.c
fs/overlayfs/inode.c
fs/overlayfs/util.c
fs/posix_acl.c
fs/reiserfs/ioctl.c
fs/xattr.c
include/linux/fs.h
mm/madvise.c
mm/mincore.c
security/selinux/hooks.c

index 33036305b4fd41eba3bb87aafad505136901ae39..eed551d8555f8d1001fb98d679fd08144a97b554 100644 (file)
@@ -195,7 +195,7 @@ int v9fs_iop_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
                goto err_out;
        }
 
-       if (!inode_owner_or_capable(&init_user_ns, inode)) {
+       if (!inode_owner_or_capable(&nop_mnt_idmap, inode)) {
                retval = -EPERM;
                goto err_out;
        }
index 1093db43ab9e40b770043b394289e3c68d0ba4dc..bd8d542e13b9f2bbb6a20ad58a3f6cb13ea99df7 100644 (file)
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -196,7 +196,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry,
        if (ia_valid & ATTR_MODE) {
                vfsgid_t vfsgid;
 
-               if (!inode_owner_or_capable(mnt_userns, inode))
+               if (!inode_owner_or_capable(idmap, inode))
                        return -EPERM;
 
                if (ia_valid & ATTR_GID)
@@ -211,7 +211,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry,
 
        /* Check for setting the inode time. */
        if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) {
-               if (!inode_owner_or_capable(mnt_userns, inode))
+               if (!inode_owner_or_capable(idmap, inode))
                        return -EPERM;
        }
 
@@ -328,7 +328,6 @@ int may_setattr(struct mnt_idmap *idmap, struct inode *inode,
                unsigned int ia_valid)
 {
        int error;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
                if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
@@ -343,7 +342,7 @@ int may_setattr(struct mnt_idmap *idmap, struct inode *inode,
                if (IS_IMMUTABLE(inode))
                        return -EPERM;
 
-               if (!inode_owner_or_capable(mnt_userns, inode)) {
+               if (!inode_owner_or_capable(idmap, inode)) {
                        error = inode_permission(idmap, inode, MAY_WRITE);
                        if (error)
                                return error;
index 7c6bb1ff41b39b4e253471f660c4b2c561e0b9c9..6affe071bdfd8ed1903fcb251ee2641059c0d124 100644 (file)
@@ -1248,7 +1248,6 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
 {
        int namelen;
        int ret = 0;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (!S_ISDIR(file_inode(file)->i_mode))
                return -ENOTDIR;
@@ -1285,7 +1284,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
                        btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
                                   "Snapshot src from another FS");
                        ret = -EXDEV;
-               } else if (!inode_owner_or_capable(mnt_userns, src_inode)) {
+               } else if (!inode_owner_or_capable(idmap, src_inode)) {
                        /*
                         * Subvolume creation is not restricted, but snapshots
                         * are limited to own subvolumes only
@@ -1424,7 +1423,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
        u64 flags;
        int ret = 0;
 
-       if (!inode_owner_or_capable(file_mnt_user_ns(file), inode))
+       if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
                return -EPERM;
 
        ret = mnt_want_write_file(file);
@@ -3909,7 +3908,7 @@ static long btrfs_ioctl_quota_rescan_wait(struct btrfs_fs_info *fs_info,
 }
 
 static long _btrfs_ioctl_set_received_subvol(struct file *file,
-                                           struct user_namespace *mnt_userns,
+                                           struct mnt_idmap *idmap,
                                            struct btrfs_ioctl_received_subvol_args *sa)
 {
        struct inode *inode = file_inode(file);
@@ -3921,7 +3920,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
        int ret = 0;
        int received_uuid_changed;
 
-       if (!inode_owner_or_capable(mnt_userns, inode))
+       if (!inode_owner_or_capable(idmap, inode))
                return -EPERM;
 
        ret = mnt_want_write_file(file);
@@ -4026,7 +4025,7 @@ static long btrfs_ioctl_set_received_subvol_32(struct file *file,
        args64->rtime.nsec = args32->rtime.nsec;
        args64->flags = args32->flags;
 
-       ret = _btrfs_ioctl_set_received_subvol(file, file_mnt_user_ns(file), args64);
+       ret = _btrfs_ioctl_set_received_subvol(file, file_mnt_idmap(file), args64);
        if (ret)
                goto out;
 
@@ -4060,7 +4059,7 @@ static long btrfs_ioctl_set_received_subvol(struct file *file,
        if (IS_ERR(sa))
                return PTR_ERR(sa);
 
-       ret = _btrfs_ioctl_set_received_subvol(file, file_mnt_user_ns(file), sa);
+       ret = _btrfs_ioctl_set_received_subvol(file, file_mnt_idmap(file), sa);
 
        if (ret)
                goto out;
index 893661b523769f4ad44e4afa735341908e8884b6..fa09c925bda85b0113ee823211f7b1e7776bd818 100644 (file)
@@ -506,7 +506,7 @@ int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
                return -EFAULT;
        policy.version = version;
 
-       if (!inode_owner_or_capable(&init_user_ns, inode))
+       if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
                return -EACCES;
 
        ret = mnt_want_write_file(filp);
index dbd7de812cc1d23f5a04e6f603171472227da0b6..cc87d413eb435d7106e8c4444cb164be16a0f87b 100644 (file)
@@ -66,7 +66,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        case EXT2_IOC_SETVERSION: {
                __u32 generation;
 
-               if (!inode_owner_or_capable(&init_user_ns, inode))
+               if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
                        return -EPERM;
                ret = mnt_want_write_file(filp);
                if (ret)
@@ -99,7 +99,7 @@ setversion_out:
                if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
                        return -ENOTTY;
 
-               if (!inode_owner_or_capable(&init_user_ns, inode))
+               if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
                        return -EACCES;
 
                if (get_user(rsv_window_size, (int __user *)arg))
index f49496087102981c81ddba7c356af8f45f1465fd..b0dc7212694e28a3cdf2a11d108115ad89a8a705 100644 (file)
@@ -358,12 +358,12 @@ void ext4_reset_inode_seed(struct inode *inode)
  * important fields of the inodes.
  *
  * @sb:         the super block of the filesystem
- * @mnt_userns:        user namespace of the mount the inode was found from
+ * @idmap:     idmap of the mount the inode was found from
  * @inode:      the inode to swap with EXT4_BOOT_LOADER_INO
  *
  */
 static long swap_inode_boot_loader(struct super_block *sb,
-                               struct user_namespace *mnt_userns,
+                               struct mnt_idmap *idmap,
                                struct inode *inode)
 {
        handle_t *handle;
@@ -393,7 +393,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
        }
 
        if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) ||
-           !inode_owner_or_capable(mnt_userns, inode) ||
+           !inode_owner_or_capable(idmap, inode) ||
            !capable(CAP_SYS_ADMIN)) {
                err = -EPERM;
                goto journal_err_out;
@@ -1217,7 +1217,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
        struct inode *inode = file_inode(filp);
        struct super_block *sb = inode->i_sb;
-       struct user_namespace *mnt_userns = file_mnt_user_ns(filp);
+       struct mnt_idmap *idmap = file_mnt_idmap(filp);
 
        ext4_debug("cmd = %u, arg = %lu\n", cmd, arg);
 
@@ -1234,7 +1234,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                __u32 generation;
                int err;
 
-               if (!inode_owner_or_capable(mnt_userns, inode))
+               if (!inode_owner_or_capable(idmap, inode))
                        return -EPERM;
 
                if (ext4_has_metadata_csum(inode->i_sb)) {
@@ -1376,7 +1376,7 @@ mext_out:
        case EXT4_IOC_MIGRATE:
        {
                int err;
-               if (!inode_owner_or_capable(mnt_userns, inode))
+               if (!inode_owner_or_capable(idmap, inode))
                        return -EACCES;
 
                err = mnt_want_write_file(filp);
@@ -1398,7 +1398,7 @@ mext_out:
        case EXT4_IOC_ALLOC_DA_BLKS:
        {
                int err;
-               if (!inode_owner_or_capable(mnt_userns, inode))
+               if (!inode_owner_or_capable(idmap, inode))
                        return -EACCES;
 
                err = mnt_want_write_file(filp);
@@ -1417,7 +1417,7 @@ mext_out:
                err = mnt_want_write_file(filp);
                if (err)
                        return err;
-               err = swap_inode_boot_loader(sb, mnt_userns, inode);
+               err = swap_inode_boot_loader(sb, idmap, inode);
                mnt_drop_write_file(filp);
                return err;
        }
@@ -1542,7 +1542,7 @@ resizefs_out:
 
        case EXT4_IOC_CLEAR_ES_CACHE:
        {
-               if (!inode_owner_or_capable(mnt_userns, inode))
+               if (!inode_owner_or_capable(idmap, inode))
                        return -EACCES;
                ext4_clear_inode_es(inode);
                return 0;
index 1d514515a6e7feea53d20bd49d9e2d3eac20ac02..33e6334bc0c634b81a61a290ca6047fce3a5f1ab 100644 (file)
@@ -2041,14 +2041,13 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
 {
        struct inode *inode = file_inode(filp);
        struct mnt_idmap *idmap = file_mnt_idmap(filp);
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct f2fs_inode_info *fi = F2FS_I(inode);
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct inode *pinode;
        loff_t isize;
        int ret;
 
-       if (!inode_owner_or_capable(mnt_userns, inode))
+       if (!inode_owner_or_capable(idmap, inode))
                return -EACCES;
 
        if (!S_ISREG(inode->i_mode))
@@ -2138,10 +2137,10 @@ out:
 static int f2fs_ioc_commit_atomic_write(struct file *filp)
 {
        struct inode *inode = file_inode(filp);
-       struct user_namespace *mnt_userns = file_mnt_user_ns(filp);
+       struct mnt_idmap *idmap = file_mnt_idmap(filp);
        int ret;
 
-       if (!inode_owner_or_capable(mnt_userns, inode))
+       if (!inode_owner_or_capable(idmap, inode))
                return -EACCES;
 
        ret = mnt_want_write_file(filp);
@@ -2170,10 +2169,10 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
 static int f2fs_ioc_abort_atomic_write(struct file *filp)
 {
        struct inode *inode = file_inode(filp);
-       struct user_namespace *mnt_userns = file_mnt_user_ns(filp);
+       struct mnt_idmap *idmap = file_mnt_idmap(filp);
        int ret;
 
-       if (!inode_owner_or_capable(mnt_userns, inode))
+       if (!inode_owner_or_capable(idmap, inode))
                return -EACCES;
 
        ret = mnt_want_write_file(filp);
index 044b74322ec45cb542ceae3d05cf101add38ed2c..d92edbbdc30e72f1bb1a9fe1e231d009c6d309c2 100644 (file)
@@ -117,7 +117,7 @@ static int f2fs_xattr_advise_set(const struct xattr_handler *handler,
        unsigned char old_advise = F2FS_I(inode)->i_advise;
        unsigned char new_advise;
 
-       if (!inode_owner_or_capable(&init_user_ns, inode))
+       if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
                return -EPERM;
        if (value == NULL)
                return -EINVAL;
index 146c9ab0cd4b7c81e6f661205e79ae562da11cee..4c043b1b9b9830b07c3c7c407eb95c0a019234fc 100644 (file)
@@ -47,7 +47,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
 
        /* O_NOATIME can only be set by the owner or superuser */
        if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
-               if (!inode_owner_or_capable(file_mnt_user_ns(filp), inode))
+               if (!inode_owner_or_capable(file_mnt_idmap(filp), inode))
                        return -EPERM;
 
        /* required for strict SunOS emulation */
index 413b7380a08942b839271363c4f15689a39f7e16..0a86c316937ed6ab53feb2efb00ed8cf521cd95c 100644 (file)
@@ -2310,23 +2310,24 @@ EXPORT_SYMBOL(inode_init_owner);
 
 /**
  * inode_owner_or_capable - check current task permissions to inode
- * @mnt_userns:        user namespace of the mount the inode was found from
+ * @idmap: idmap of the mount the inode was found from
  * @inode: inode being checked
  *
  * Return true if current either has CAP_FOWNER in a namespace with the
  * inode owner uid mapped, or owns the file.
  *
- * If the inode has been found through an idmapped mount the user namespace of
- * the vfsmount must be passed through @mnt_userns. This function will then take
- * care to map the inode according to @mnt_userns before checking permissions.
+ * If the inode has been found through an idmapped mount the idmap of
+ * the vfsmount must be passed through @idmap. This function will then take
+ * care to map the inode according to @idmap before checking permissions.
  * On non-idmapped mounts or if permission checking is to be performed on the
- * raw inode simply passs init_user_ns.
+ * raw inode simply passs @nop_mnt_idmap.
  */
-bool inode_owner_or_capable(struct user_namespace *mnt_userns,
+bool inode_owner_or_capable(struct mnt_idmap *idmap,
                            const struct inode *inode)
 {
        vfsuid_t vfsuid;
        struct user_namespace *ns;
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
        if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
index 2bf1bdaec2eeebcfa3d5d6ded0977c9cac7b071b..5b2481cd475012286c72b492297af55789f50dbf 100644 (file)
@@ -675,7 +675,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
        if (!inode->i_op->fileattr_set)
                return -ENOIOCTLCMD;
 
-       if (!inode_owner_or_capable(mnt_idmap_owner(idmap), inode))
+       if (!inode_owner_or_capable(idmap, inode))
                return -EPERM;
 
        inode_lock(inode);
index 637f8bee713239996993c61d0b0bd0eb59cae618..48dd44251ddae0edaf3a10adcf09550a4a8212a5 100644 (file)
@@ -1197,7 +1197,7 @@ int may_linkat(struct mnt_idmap *idmap, const struct path *link)
         * otherwise, it must be a safe source.
         */
        if (safe_hardlink_source(idmap, inode) ||
-           inode_owner_or_capable(mnt_userns, inode))
+           inode_owner_or_capable(idmap, inode))
                return 0;
 
        audit_log_path_denied(AUDIT_ANOM_LINK, "linkat");
@@ -3158,7 +3158,6 @@ bool may_open_dev(const struct path *path)
 static int may_open(struct mnt_idmap *idmap, const struct path *path,
                    int acc_mode, int flag)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct dentry *dentry = path->dentry;
        struct inode *inode = dentry->d_inode;
        int error;
@@ -3207,7 +3206,7 @@ static int may_open(struct mnt_idmap *idmap, const struct path *path,
        }
 
        /* O_NOATIME can only be set by the owner or superuser */
-       if (flag & O_NOATIME && !inode_owner_or_capable(mnt_userns, inode))
+       if (flag & O_NOATIME && !inode_owner_or_capable(idmap, inode))
                return -EPERM;
 
        return 0;
index f69d5740c3c431f5f4ebf75a169ef36d1d9888f5..7c04f033aadd75d36d078d3ca1d1669867605a2b 100644 (file)
@@ -43,7 +43,6 @@ static struct file *ovl_open_realfile(const struct file *file,
        struct inode *realinode = d_inode(realpath->dentry);
        struct inode *inode = file_inode(file);
        struct mnt_idmap *real_idmap;
-       struct user_namespace *real_mnt_userns;
        struct file *realfile;
        const struct cred *old_cred;
        int flags = file->f_flags | OVL_OPEN_FLAGS;
@@ -55,12 +54,11 @@ static struct file *ovl_open_realfile(const struct file *file,
 
        old_cred = ovl_override_creds(inode->i_sb);
        real_idmap = mnt_idmap(realpath->mnt);
-       real_mnt_userns = mnt_idmap_owner(real_idmap);
        err = inode_permission(real_idmap, realinode, MAY_OPEN | acc_mode);
        if (err) {
                realfile = ERR_PTR(err);
        } else {
-               if (!inode_owner_or_capable(real_mnt_userns, realinode))
+               if (!inode_owner_or_capable(real_idmap, realinode))
                        flags &= ~O_NOATIME;
 
                realfile = open_with_fake_path(&file->f_path, flags, realinode,
index d906cf073fbaf5e5ea5ce291a835b849b38661c8..3ba3110243d1005e72210572309e294aca47e3e4 100644 (file)
@@ -667,7 +667,7 @@ int ovl_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
                return -EOPNOTSUPP;
        if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
                return acl ? -EACCES : 0;
-       if (!inode_owner_or_capable(&init_user_ns, inode))
+       if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
                return -EPERM;
 
        /*
index 48a3c3fee1b6e61c29ed6d2e061d5ab511c7bbc8..1166f7b22bc7839b2851b6a8e6a40f248989a1b5 100644 (file)
@@ -492,7 +492,6 @@ struct file *ovl_path_open(const struct path *path, int flags)
 {
        struct inode *inode = d_inode(path->dentry);
        struct mnt_idmap *real_idmap = mnt_idmap(path->mnt);
-       struct user_namespace *real_mnt_userns = mnt_idmap_owner(real_idmap);
        int err, acc_mode;
 
        if (flags & ~(O_ACCMODE | O_LARGEFILE))
@@ -514,7 +513,7 @@ struct file *ovl_path_open(const struct path *path, int flags)
                return ERR_PTR(err);
 
        /* O_NOATIME is an optimization, don't fail if not permitted */
-       if (inode_owner_or_capable(real_mnt_userns, inode))
+       if (inode_owner_or_capable(real_idmap, inode))
                flags |= O_NOATIME;
 
        return dentry_open(path, flags, current_cred());
index b6c3b5b1943558f607e939660024b37e9d3d912d..ea2620050b4027cfd8a874f8c36507b7e5e03141 100644 (file)
@@ -948,7 +948,7 @@ set_posix_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 
        if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
                return acl ? -EACCES : 0;
-       if (!inode_owner_or_capable(mnt_idmap_owner(idmap), inode))
+       if (!inode_owner_or_capable(idmap, inode))
                return -EPERM;
 
        if (acl) {
index 12800dfc11a9f11574c0f130d6dc17909e879d0d..6bf9b54e58ca0a82d5010daf8d92448c9e452867 100644 (file)
@@ -96,7 +96,7 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                err = put_user(inode->i_generation, (int __user *)arg);
                break;
        case REISERFS_IOC_SETVERSION:
-               if (!inode_owner_or_capable(&init_user_ns, inode)) {
+               if (!inode_owner_or_capable(&nop_mnt_idmap, inode)) {
                        err = -EPERM;
                        break;
                }
index 1cc1420ecccef294bff6854458a84f68bf20651e..80a6460b620c45c9aaa77d6e5c0f4b95c53f3129 100644 (file)
@@ -113,8 +113,6 @@ static int
 xattr_permission(struct mnt_idmap *idmap, struct inode *inode,
                 const char *name, int mask)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-
        if (mask & MAY_WRITE) {
                int ret;
 
@@ -150,7 +148,7 @@ xattr_permission(struct mnt_idmap *idmap, struct inode *inode,
                        return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
                if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
                    (mask & MAY_WRITE) &&
-                   !inode_owner_or_capable(mnt_userns, inode))
+                   !inode_owner_or_capable(idmap, inode))
                        return -EPERM;
        }
 
index c1d698923d15908dfda9234582ea1eedd1bd4b2a..e6c76f308f5f6e0dcadd1b33c7c168cc27badeae 100644 (file)
@@ -1939,7 +1939,7 @@ static inline bool sb_start_intwrite_trylock(struct super_block *sb)
        return __sb_start_write_trylock(sb, SB_FREEZE_FS);
 }
 
-bool inode_owner_or_capable(struct user_namespace *mnt_userns,
+bool inode_owner_or_capable(struct mnt_idmap *idmap,
                            const struct inode *inode);
 
 /*
index a56a6d17e201e3cecc3f2b8d66361db2ee5e91b0..72297d5edab77075cca90935de222313f3c34ee4 100644 (file)
@@ -329,7 +329,7 @@ static inline bool can_do_file_pageout(struct vm_area_struct *vma)
         * otherwise we'd be including shared non-exclusive mappings, which
         * opens a side channel.
         */
-       return inode_owner_or_capable(&init_user_ns,
+       return inode_owner_or_capable(&nop_mnt_idmap,
                                      file_inode(vma->vm_file)) ||
               file_permission(vma->vm_file, MAY_WRITE) == 0;
 }
index a085a2aeabd8e6b1787971b1a3e068e2e9ceb41e..cd69b9db00812655c42fdc91957d6826bd97d9d6 100644 (file)
@@ -168,7 +168,7 @@ static inline bool can_do_mincore(struct vm_area_struct *vma)
         * for writing; otherwise we'd be including shared non-exclusive
         * mappings, which opens a side channel.
         */
-       return inode_owner_or_capable(&init_user_ns,
+       return inode_owner_or_capable(&nop_mnt_idmap,
                                      file_inode(vma->vm_file)) ||
               file_permission(vma->vm_file, MAY_WRITE) == 0;
 }
index f32fa3359502f199554789585999fcacfbffd8d6..9a5bdfc2131471b4b74ba68ee224d0002942f5aa 100644 (file)
@@ -3154,7 +3154,6 @@ static int selinux_inode_setxattr(struct mnt_idmap *idmap,
        struct superblock_security_struct *sbsec;
        struct common_audit_data ad;
        u32 newsid, sid = current_sid();
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        int rc = 0;
 
        if (strcmp(name, XATTR_NAME_SELINUX)) {
@@ -3168,13 +3167,13 @@ static int selinux_inode_setxattr(struct mnt_idmap *idmap,
        }
 
        if (!selinux_initialized(&selinux_state))
-               return (inode_owner_or_capable(mnt_userns, inode) ? 0 : -EPERM);
+               return (inode_owner_or_capable(idmap, inode) ? 0 : -EPERM);
 
        sbsec = selinux_superblock(inode->i_sb);
        if (!(sbsec->flags & SBLABEL_MNT))
                return -EOPNOTSUPP;
 
-       if (!inode_owner_or_capable(mnt_userns, inode))
+       if (!inode_owner_or_capable(idmap, inode))
                return -EPERM;
 
        ad.type = LSM_AUDIT_DATA_DENTRY;