aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ioctl.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2014-01-16 09:50:22 -0500
committerChris Mason <clm@fb.com>2014-01-28 16:20:41 -0500
commitbd60ea0fe947029df4b7b7aa9d6557baf2a5a138 (patch)
tree572b5d652fb6a4c2977bfbc1cc26dac8e3f79d89 /fs/btrfs/ioctl.c
parentd024206133ce21936b3d5780359afc00247655b7 (diff)
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: David Sterba <dsterba@suse.cz> Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r--fs/btrfs/ioctl.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 8d4457f329f5..62c62b4fa55b 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -192,6 +192,9 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
192 unsigned int i_oldflags; 192 unsigned int i_oldflags;
193 umode_t mode; 193 umode_t mode;
194 194
195 if (!inode_owner_or_capable(inode))
196 return -EPERM;
197
195 if (btrfs_root_readonly(root)) 198 if (btrfs_root_readonly(root))
196 return -EROFS; 199 return -EROFS;
197 200
@@ -202,9 +205,6 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
202 if (ret) 205 if (ret)
203 return ret; 206 return ret;
204 207
205 if (!inode_owner_or_capable(inode))
206 return -EACCES;
207
208 ret = mnt_want_write_file(file); 208 ret = mnt_want_write_file(file);
209 if (ret) 209 if (ret)
210 return ret; 210 return ret;
@@ -1697,6 +1697,9 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
1697 u64 flags; 1697 u64 flags;
1698 int ret = 0; 1698 int ret = 0;
1699 1699
1700 if (!inode_owner_or_capable(inode))
1701 return -EPERM;
1702
1700 ret = mnt_want_write_file(file); 1703 ret = mnt_want_write_file(file);
1701 if (ret) 1704 if (ret)
1702 goto out; 1705 goto out;
@@ -1721,11 +1724,6 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
1721 goto out_drop_write; 1724 goto out_drop_write;
1722 } 1725 }
1723 1726
1724 if (!inode_owner_or_capable(inode)) {
1725 ret = -EACCES;
1726 goto out_drop_write;
1727 }
1728
1729 down_write(&root->fs_info->subvol_sem); 1727 down_write(&root->fs_info->subvol_sem);
1730 1728
1731 /* nothing to do */ 1729 /* nothing to do */
@@ -4403,6 +4401,9 @@ static long btrfs_ioctl_set_received_subvol(struct file *file,
4403 int ret = 0; 4401 int ret = 0;
4404 int received_uuid_changed; 4402 int received_uuid_changed;
4405 4403
4404 if (!inode_owner_or_capable(inode))
4405 return -EPERM;
4406
4406 ret = mnt_want_write_file(file); 4407 ret = mnt_want_write_file(file);
4407 if (ret < 0) 4408 if (ret < 0)
4408 return ret; 4409 return ret;
@@ -4419,11 +4420,6 @@ static long btrfs_ioctl_set_received_subvol(struct file *file,
4419 goto out; 4420 goto out;
4420 } 4421 }
4421 4422
4422 if (!inode_owner_or_capable(inode)) {
4423 ret = -EACCES;
4424 goto out;
4425 }
4426
4427 sa = memdup_user(arg, sizeof(*sa)); 4423 sa = memdup_user(arg, sizeof(*sa));
4428 if (IS_ERR(sa)) { 4424 if (IS_ERR(sa)) {
4429 ret = PTR_ERR(sa); 4425 ret = PTR_ERR(sa);