diff options
author | Lukas Czerner <lczerner@redhat.com> | 2011-09-05 16:34:54 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2011-10-20 18:10:40 +0200 |
commit | f4c697e6406da5dd445eda8d923c53e1138793dd (patch) | |
tree | a572fcd0b9db22177d74c8fd3276ccb6a05c028c /fs/btrfs/ioctl.c | |
parent | 008873eafbc77deb1702aedece33756c58486c6a (diff) | |
download | linux-stable-f4c697e6406da5dd445eda8d923c53e1138793dd.tar.gz linux-stable-f4c697e6406da5dd445eda8d923c53e1138793dd.tar.bz2 linux-stable-f4c697e6406da5dd445eda8d923c53e1138793dd.zip |
btrfs: return EINVAL if start > total_bytes in fitrim ioctl
We should retirn EINVAL if the start is beyond the end of the file
system in the btrfs_ioctl_fitrim(). Fix that by adding the appropriate
check for it.
Also in the btrfs_trim_fs() it is possible that len+start might overflow
if big values are passed. Fix it by decrementing the len so that start+len
is equal to the file system size in the worst case.
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r-- | fs/btrfs/ioctl.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index d524b6697ad9..136a2f980e21 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -282,6 +282,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) struct fstrim_range range; u64 minlen = ULLONG_MAX; u64 num_devices = 0; + u64 total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); int ret; if (!capable(CAP_SYS_ADMIN)) @@ -300,12 +301,15 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) } } rcu_read_unlock(); + if (!num_devices) return -EOPNOTSUPP; - if (copy_from_user(&range, arg, sizeof(range))) return -EFAULT; + if (range.start > total_bytes) + return -EINVAL; + range.len = min(range.len, total_bytes - range.start); range.minlen = max(range.minlen, minlen); ret = btrfs_trim_fs(root, &range); if (ret < 0) |