提交 bd60ea0f 编写于 作者: D David Sterba 提交者: Chris Mason

btrfs: call permission checks earlier in ioctls and return EPERM

The owner and capability checks in IOC_SUBVOL_SETFLAGS and
SET_RECEIVED_SUBVOL should be called before any other checks are done.

Also unify the error code to EPERM.
Signed-off-by: NDavid Sterba <dsterba@suse.cz>
Signed-off-by: NJosef Bacik <jbacik@fb.com>
Signed-off-by: NChris Mason <clm@fb.com>
上级 d0242061
...@@ -192,6 +192,9 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -192,6 +192,9 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
unsigned int i_oldflags; unsigned int i_oldflags;
umode_t mode; umode_t mode;
if (!inode_owner_or_capable(inode))
return -EPERM;
if (btrfs_root_readonly(root)) if (btrfs_root_readonly(root))
return -EROFS; return -EROFS;
...@@ -202,9 +205,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ...@@ -202,9 +205,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
if (ret) if (ret)
return ret; return ret;
if (!inode_owner_or_capable(inode))
return -EACCES;
ret = mnt_want_write_file(file); ret = mnt_want_write_file(file);
if (ret) if (ret)
return ret; return ret;
...@@ -1697,6 +1697,9 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file, ...@@ -1697,6 +1697,9 @@ 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(inode))
return -EPERM;
ret = mnt_want_write_file(file); ret = mnt_want_write_file(file);
if (ret) if (ret)
goto out; goto out;
...@@ -1721,11 +1724,6 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file, ...@@ -1721,11 +1724,6 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
goto out_drop_write; goto out_drop_write;
} }
if (!inode_owner_or_capable(inode)) {
ret = -EACCES;
goto out_drop_write;
}
down_write(&root->fs_info->subvol_sem); down_write(&root->fs_info->subvol_sem);
/* nothing to do */ /* nothing to do */
...@@ -4403,6 +4401,9 @@ static long btrfs_ioctl_set_received_subvol(struct file *file, ...@@ -4403,6 +4401,9 @@ 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(inode))
return -EPERM;
ret = mnt_want_write_file(file); ret = mnt_want_write_file(file);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -4419,11 +4420,6 @@ static long btrfs_ioctl_set_received_subvol(struct file *file, ...@@ -4419,11 +4420,6 @@ static long btrfs_ioctl_set_received_subvol(struct file *file,
goto out; goto out;
} }
if (!inode_owner_or_capable(inode)) {
ret = -EACCES;
goto out;
}
sa = memdup_user(arg, sizeof(*sa)); sa = memdup_user(arg, sizeof(*sa));
if (IS_ERR(sa)) { if (IS_ERR(sa)) {
ret = PTR_ERR(sa); ret = PTR_ERR(sa);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册