Commit 01beba79 authored by Christian Brauner's avatar Christian Brauner Committed by Christian Brauner (Microsoft)

fs: port inode_owner_or_capable() to mnt_idmap

Convert to struct mnt_idmap.

Last cycle we merged the necessary infrastructure in
256c8aed ("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: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarChristian Brauner (Microsoft) <brauner@kernel.org>
parent f2d40141
...@@ -195,7 +195,7 @@ int v9fs_iop_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, ...@@ -195,7 +195,7 @@ int v9fs_iop_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
goto err_out; goto err_out;
} }
if (!inode_owner_or_capable(&init_user_ns, inode)) { if (!inode_owner_or_capable(&nop_mnt_idmap, inode)) {
retval = -EPERM; retval = -EPERM;
goto err_out; goto err_out;
} }
......
...@@ -196,7 +196,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry, ...@@ -196,7 +196,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry,
if (ia_valid & ATTR_MODE) { if (ia_valid & ATTR_MODE) {
vfsgid_t vfsgid; vfsgid_t vfsgid;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EPERM; return -EPERM;
if (ia_valid & ATTR_GID) if (ia_valid & ATTR_GID)
...@@ -211,7 +211,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry, ...@@ -211,7 +211,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry,
/* Check for setting the inode time. */ /* Check for setting the inode time. */
if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) { 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; return -EPERM;
} }
...@@ -328,7 +328,6 @@ int may_setattr(struct mnt_idmap *idmap, struct inode *inode, ...@@ -328,7 +328,6 @@ int may_setattr(struct mnt_idmap *idmap, struct inode *inode,
unsigned int ia_valid) unsigned int ia_valid)
{ {
int error; int error;
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) { if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
...@@ -343,7 +342,7 @@ int may_setattr(struct mnt_idmap *idmap, struct inode *inode, ...@@ -343,7 +342,7 @@ int may_setattr(struct mnt_idmap *idmap, struct inode *inode,
if (IS_IMMUTABLE(inode)) if (IS_IMMUTABLE(inode))
return -EPERM; return -EPERM;
if (!inode_owner_or_capable(mnt_userns, inode)) { if (!inode_owner_or_capable(idmap, inode)) {
error = inode_permission(idmap, inode, MAY_WRITE); error = inode_permission(idmap, inode, MAY_WRITE);
if (error) if (error)
return error; return error;
......
...@@ -1248,7 +1248,6 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, ...@@ -1248,7 +1248,6 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
{ {
int namelen; int namelen;
int ret = 0; int ret = 0;
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
if (!S_ISDIR(file_inode(file)->i_mode)) if (!S_ISDIR(file_inode(file)->i_mode))
return -ENOTDIR; return -ENOTDIR;
...@@ -1285,7 +1284,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file, ...@@ -1285,7 +1284,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,
btrfs_info(BTRFS_I(file_inode(file))->root->fs_info, btrfs_info(BTRFS_I(file_inode(file))->root->fs_info,
"Snapshot src from another FS"); "Snapshot src from another FS");
ret = -EXDEV; 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 * Subvolume creation is not restricted, but snapshots
* are limited to own subvolumes only * are limited to own subvolumes only
...@@ -1424,7 +1423,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file, ...@@ -1424,7 +1423,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
u64 flags; u64 flags;
int ret = 0; 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; return -EPERM;
ret = mnt_want_write_file(file); ret = mnt_want_write_file(file);
...@@ -3909,7 +3908,7 @@ static long btrfs_ioctl_quota_rescan_wait(struct btrfs_fs_info *fs_info, ...@@ -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, 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 btrfs_ioctl_received_subvol_args *sa)
{ {
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
...@@ -3921,7 +3920,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file, ...@@ -3921,7 +3920,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
int ret = 0; int ret = 0;
int received_uuid_changed; int received_uuid_changed;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EPERM; return -EPERM;
ret = mnt_want_write_file(file); ret = mnt_want_write_file(file);
...@@ -4026,7 +4025,7 @@ static long btrfs_ioctl_set_received_subvol_32(struct file *file, ...@@ -4026,7 +4025,7 @@ static long btrfs_ioctl_set_received_subvol_32(struct file *file,
args64->rtime.nsec = args32->rtime.nsec; args64->rtime.nsec = args32->rtime.nsec;
args64->flags = args32->flags; 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) if (ret)
goto out; goto out;
...@@ -4060,7 +4059,7 @@ static long btrfs_ioctl_set_received_subvol(struct file *file, ...@@ -4060,7 +4059,7 @@ static long btrfs_ioctl_set_received_subvol(struct file *file,
if (IS_ERR(sa)) if (IS_ERR(sa))
return PTR_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) if (ret)
goto out; goto out;
......
...@@ -506,7 +506,7 @@ int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg) ...@@ -506,7 +506,7 @@ int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
return -EFAULT; return -EFAULT;
policy.version = version; policy.version = version;
if (!inode_owner_or_capable(&init_user_ns, inode)) if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
return -EACCES; return -EACCES;
ret = mnt_want_write_file(filp); ret = mnt_want_write_file(filp);
......
...@@ -66,7 +66,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -66,7 +66,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
case EXT2_IOC_SETVERSION: { case EXT2_IOC_SETVERSION: {
__u32 generation; __u32 generation;
if (!inode_owner_or_capable(&init_user_ns, inode)) if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
return -EPERM; return -EPERM;
ret = mnt_want_write_file(filp); ret = mnt_want_write_file(filp);
if (ret) if (ret)
...@@ -99,7 +99,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -99,7 +99,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode)) if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
return -ENOTTY; return -ENOTTY;
if (!inode_owner_or_capable(&init_user_ns, inode)) if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
return -EACCES; return -EACCES;
if (get_user(rsv_window_size, (int __user *)arg)) if (get_user(rsv_window_size, (int __user *)arg))
......
...@@ -358,12 +358,12 @@ void ext4_reset_inode_seed(struct inode *inode) ...@@ -358,12 +358,12 @@ void ext4_reset_inode_seed(struct inode *inode)
* important fields of the inodes. * important fields of the inodes.
* *
* @sb: the super block of the filesystem * @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 * @inode: the inode to swap with EXT4_BOOT_LOADER_INO
* *
*/ */
static long swap_inode_boot_loader(struct super_block *sb, static long swap_inode_boot_loader(struct super_block *sb,
struct user_namespace *mnt_userns, struct mnt_idmap *idmap,
struct inode *inode) struct inode *inode)
{ {
handle_t *handle; handle_t *handle;
...@@ -393,7 +393,7 @@ static long swap_inode_boot_loader(struct super_block *sb, ...@@ -393,7 +393,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
} }
if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) || 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)) { !capable(CAP_SYS_ADMIN)) {
err = -EPERM; err = -EPERM;
goto journal_err_out; goto journal_err_out;
...@@ -1217,7 +1217,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1217,7 +1217,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
struct super_block *sb = inode->i_sb; 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); 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) ...@@ -1234,7 +1234,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
__u32 generation; __u32 generation;
int err; int err;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EPERM; return -EPERM;
if (ext4_has_metadata_csum(inode->i_sb)) { if (ext4_has_metadata_csum(inode->i_sb)) {
...@@ -1376,7 +1376,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1376,7 +1376,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
case EXT4_IOC_MIGRATE: case EXT4_IOC_MIGRATE:
{ {
int err; int err;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EACCES; return -EACCES;
err = mnt_want_write_file(filp); err = mnt_want_write_file(filp);
...@@ -1398,7 +1398,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1398,7 +1398,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
case EXT4_IOC_ALLOC_DA_BLKS: case EXT4_IOC_ALLOC_DA_BLKS:
{ {
int err; int err;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EACCES; return -EACCES;
err = mnt_want_write_file(filp); err = mnt_want_write_file(filp);
...@@ -1417,7 +1417,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1417,7 +1417,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
err = mnt_want_write_file(filp); err = mnt_want_write_file(filp);
if (err) if (err)
return 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); mnt_drop_write_file(filp);
return err; return err;
} }
...@@ -1542,7 +1542,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1542,7 +1542,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
case EXT4_IOC_CLEAR_ES_CACHE: case EXT4_IOC_CLEAR_ES_CACHE:
{ {
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EACCES; return -EACCES;
ext4_clear_inode_es(inode); ext4_clear_inode_es(inode);
return 0; return 0;
......
...@@ -2041,14 +2041,13 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) ...@@ -2041,14 +2041,13 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
struct mnt_idmap *idmap = file_mnt_idmap(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_inode_info *fi = F2FS_I(inode);
struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct inode *pinode; struct inode *pinode;
loff_t isize; loff_t isize;
int ret; int ret;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EACCES; return -EACCES;
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
...@@ -2138,10 +2137,10 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) ...@@ -2138,10 +2137,10 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
static int f2fs_ioc_commit_atomic_write(struct file *filp) static int f2fs_ioc_commit_atomic_write(struct file *filp)
{ {
struct inode *inode = file_inode(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; int ret;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EACCES; return -EACCES;
ret = mnt_want_write_file(filp); ret = mnt_want_write_file(filp);
...@@ -2170,10 +2169,10 @@ static int f2fs_ioc_commit_atomic_write(struct 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) static int f2fs_ioc_abort_atomic_write(struct file *filp)
{ {
struct inode *inode = file_inode(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; int ret;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EACCES; return -EACCES;
ret = mnt_want_write_file(filp); ret = mnt_want_write_file(filp);
......
...@@ -117,7 +117,7 @@ static int f2fs_xattr_advise_set(const struct xattr_handler *handler, ...@@ -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 old_advise = F2FS_I(inode)->i_advise;
unsigned char new_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; return -EPERM;
if (value == NULL) if (value == NULL)
return -EINVAL; return -EINVAL;
......
...@@ -47,7 +47,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg) ...@@ -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 */ /* O_NOATIME can only be set by the owner or superuser */
if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) 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; return -EPERM;
/* required for strict SunOS emulation */ /* required for strict SunOS emulation */
......
...@@ -2310,23 +2310,24 @@ EXPORT_SYMBOL(inode_init_owner); ...@@ -2310,23 +2310,24 @@ EXPORT_SYMBOL(inode_init_owner);
/** /**
* inode_owner_or_capable - check current task permissions to inode * 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 * @inode: inode being checked
* *
* Return true if current either has CAP_FOWNER in a namespace with the * Return true if current either has CAP_FOWNER in a namespace with the
* inode owner uid mapped, or owns the file. * inode owner uid mapped, or owns the file.
* *
* If the inode has been found through an idmapped mount the user namespace of * If the inode has been found through an idmapped mount the idmap of
* the vfsmount must be passed through @mnt_userns. This function will then take * the vfsmount must be passed through @idmap. This function will then take
* care to map the inode according to @mnt_userns before checking permissions. * 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 * 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) const struct inode *inode)
{ {
vfsuid_t vfsuid; vfsuid_t vfsuid;
struct user_namespace *ns; struct user_namespace *ns;
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
vfsuid = i_uid_into_vfsuid(mnt_userns, inode); vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
if (vfsuid_eq_kuid(vfsuid, current_fsuid())) if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
......
...@@ -675,7 +675,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, ...@@ -675,7 +675,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
if (!inode->i_op->fileattr_set) if (!inode->i_op->fileattr_set)
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
if (!inode_owner_or_capable(mnt_idmap_owner(idmap), inode)) if (!inode_owner_or_capable(idmap, inode))
return -EPERM; return -EPERM;
inode_lock(inode); inode_lock(inode);
......
...@@ -1197,7 +1197,7 @@ int may_linkat(struct mnt_idmap *idmap, const struct path *link) ...@@ -1197,7 +1197,7 @@ int may_linkat(struct mnt_idmap *idmap, const struct path *link)
* otherwise, it must be a safe source. * otherwise, it must be a safe source.
*/ */
if (safe_hardlink_source(idmap, inode) || if (safe_hardlink_source(idmap, inode) ||
inode_owner_or_capable(mnt_userns, inode)) inode_owner_or_capable(idmap, inode))
return 0; return 0;
audit_log_path_denied(AUDIT_ANOM_LINK, "linkat"); audit_log_path_denied(AUDIT_ANOM_LINK, "linkat");
...@@ -3158,7 +3158,6 @@ bool may_open_dev(const struct path *path) ...@@ -3158,7 +3158,6 @@ bool may_open_dev(const struct path *path)
static int may_open(struct mnt_idmap *idmap, const struct path *path, static int may_open(struct mnt_idmap *idmap, const struct path *path,
int acc_mode, int flag) int acc_mode, int flag)
{ {
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
struct dentry *dentry = path->dentry; struct dentry *dentry = path->dentry;
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
int error; int error;
...@@ -3207,7 +3206,7 @@ static int may_open(struct mnt_idmap *idmap, const struct path *path, ...@@ -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 */ /* 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 -EPERM;
return 0; return 0;
......
...@@ -43,7 +43,6 @@ static struct file *ovl_open_realfile(const struct file *file, ...@@ -43,7 +43,6 @@ static struct file *ovl_open_realfile(const struct file *file,
struct inode *realinode = d_inode(realpath->dentry); struct inode *realinode = d_inode(realpath->dentry);
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct mnt_idmap *real_idmap; struct mnt_idmap *real_idmap;
struct user_namespace *real_mnt_userns;
struct file *realfile; struct file *realfile;
const struct cred *old_cred; const struct cred *old_cred;
int flags = file->f_flags | OVL_OPEN_FLAGS; int flags = file->f_flags | OVL_OPEN_FLAGS;
...@@ -55,12 +54,11 @@ static struct file *ovl_open_realfile(const struct file *file, ...@@ -55,12 +54,11 @@ static struct file *ovl_open_realfile(const struct file *file,
old_cred = ovl_override_creds(inode->i_sb); old_cred = ovl_override_creds(inode->i_sb);
real_idmap = mnt_idmap(realpath->mnt); real_idmap = mnt_idmap(realpath->mnt);
real_mnt_userns = mnt_idmap_owner(real_idmap);
err = inode_permission(real_idmap, realinode, MAY_OPEN | acc_mode); err = inode_permission(real_idmap, realinode, MAY_OPEN | acc_mode);
if (err) { if (err) {
realfile = ERR_PTR(err); realfile = ERR_PTR(err);
} else { } else {
if (!inode_owner_or_capable(real_mnt_userns, realinode)) if (!inode_owner_or_capable(real_idmap, realinode))
flags &= ~O_NOATIME; flags &= ~O_NOATIME;
realfile = open_with_fake_path(&file->f_path, flags, realinode, realfile = open_with_fake_path(&file->f_path, flags, realinode,
......
...@@ -667,7 +667,7 @@ int ovl_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, ...@@ -667,7 +667,7 @@ int ovl_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
return acl ? -EACCES : 0; return acl ? -EACCES : 0;
if (!inode_owner_or_capable(&init_user_ns, inode)) if (!inode_owner_or_capable(&nop_mnt_idmap, inode))
return -EPERM; return -EPERM;
/* /*
......
...@@ -492,7 +492,6 @@ struct file *ovl_path_open(const struct path *path, int flags) ...@@ -492,7 +492,6 @@ struct file *ovl_path_open(const struct path *path, int flags)
{ {
struct inode *inode = d_inode(path->dentry); struct inode *inode = d_inode(path->dentry);
struct mnt_idmap *real_idmap = mnt_idmap(path->mnt); struct mnt_idmap *real_idmap = mnt_idmap(path->mnt);
struct user_namespace *real_mnt_userns = mnt_idmap_owner(real_idmap);
int err, acc_mode; int err, acc_mode;
if (flags & ~(O_ACCMODE | O_LARGEFILE)) if (flags & ~(O_ACCMODE | O_LARGEFILE))
...@@ -514,7 +513,7 @@ struct file *ovl_path_open(const struct path *path, int flags) ...@@ -514,7 +513,7 @@ struct file *ovl_path_open(const struct path *path, int flags)
return ERR_PTR(err); return ERR_PTR(err);
/* O_NOATIME is an optimization, don't fail if not permitted */ /* 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; flags |= O_NOATIME;
return dentry_open(path, flags, current_cred()); return dentry_open(path, flags, current_cred());
......
...@@ -948,7 +948,7 @@ set_posix_acl(struct mnt_idmap *idmap, struct dentry *dentry, ...@@ -948,7 +948,7 @@ set_posix_acl(struct mnt_idmap *idmap, struct dentry *dentry,
if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
return acl ? -EACCES : 0; return acl ? -EACCES : 0;
if (!inode_owner_or_capable(mnt_idmap_owner(idmap), inode)) if (!inode_owner_or_capable(idmap, inode))
return -EPERM; return -EPERM;
if (acl) { if (acl) {
......
...@@ -96,7 +96,7 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -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); err = put_user(inode->i_generation, (int __user *)arg);
break; break;
case REISERFS_IOC_SETVERSION: case REISERFS_IOC_SETVERSION:
if (!inode_owner_or_capable(&init_user_ns, inode)) { if (!inode_owner_or_capable(&nop_mnt_idmap, inode)) {
err = -EPERM; err = -EPERM;
break; break;
} }
......
...@@ -113,8 +113,6 @@ static int ...@@ -113,8 +113,6 @@ static int
xattr_permission(struct mnt_idmap *idmap, struct inode *inode, xattr_permission(struct mnt_idmap *idmap, struct inode *inode,
const char *name, int mask) const char *name, int mask)
{ {
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
if (mask & MAY_WRITE) { if (mask & MAY_WRITE) {
int ret; int ret;
...@@ -150,7 +148,7 @@ xattr_permission(struct mnt_idmap *idmap, struct inode *inode, ...@@ -150,7 +148,7 @@ xattr_permission(struct mnt_idmap *idmap, struct inode *inode,
return (mask & MAY_WRITE) ? -EPERM : -ENODATA; return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) && if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
(mask & MAY_WRITE) && (mask & MAY_WRITE) &&
!inode_owner_or_capable(mnt_userns, inode)) !inode_owner_or_capable(idmap, inode))
return -EPERM; return -EPERM;
} }
......
...@@ -1939,7 +1939,7 @@ static inline bool sb_start_intwrite_trylock(struct super_block *sb) ...@@ -1939,7 +1939,7 @@ static inline bool sb_start_intwrite_trylock(struct super_block *sb)
return __sb_start_write_trylock(sb, SB_FREEZE_FS); 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); const struct inode *inode);
/* /*
......
...@@ -329,7 +329,7 @@ static inline bool can_do_file_pageout(struct vm_area_struct *vma) ...@@ -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 * otherwise we'd be including shared non-exclusive mappings, which
* opens a side channel. * 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_inode(vma->vm_file)) ||
file_permission(vma->vm_file, MAY_WRITE) == 0; file_permission(vma->vm_file, MAY_WRITE) == 0;
} }
......
...@@ -168,7 +168,7 @@ static inline bool can_do_mincore(struct vm_area_struct *vma) ...@@ -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 * for writing; otherwise we'd be including shared non-exclusive
* mappings, which opens a side channel. * 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_inode(vma->vm_file)) ||
file_permission(vma->vm_file, MAY_WRITE) == 0; file_permission(vma->vm_file, MAY_WRITE) == 0;
} }
......
...@@ -3154,7 +3154,6 @@ static int selinux_inode_setxattr(struct mnt_idmap *idmap, ...@@ -3154,7 +3154,6 @@ static int selinux_inode_setxattr(struct mnt_idmap *idmap,
struct superblock_security_struct *sbsec; struct superblock_security_struct *sbsec;
struct common_audit_data ad; struct common_audit_data ad;
u32 newsid, sid = current_sid(); u32 newsid, sid = current_sid();
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
int rc = 0; int rc = 0;
if (strcmp(name, XATTR_NAME_SELINUX)) { if (strcmp(name, XATTR_NAME_SELINUX)) {
...@@ -3168,13 +3167,13 @@ static int selinux_inode_setxattr(struct mnt_idmap *idmap, ...@@ -3168,13 +3167,13 @@ static int selinux_inode_setxattr(struct mnt_idmap *idmap,
} }
if (!selinux_initialized(&selinux_state)) 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); sbsec = selinux_superblock(inode->i_sb);
if (!(sbsec->flags & SBLABEL_MNT)) if (!(sbsec->flags & SBLABEL_MNT))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!inode_owner_or_capable(mnt_userns, inode)) if (!inode_owner_or_capable(idmap, inode))
return -EPERM; return -EPERM;
ad.type = LSM_AUDIT_DATA_DENTRY; ad.type = LSM_AUDIT_DATA_DENTRY;
......
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