From: Liu Bo Date: Tue, 16 Apr 2013 09:20:28 +0000 (+0000) Subject: Btrfs: return error when we specify wrong start to defrag X-Git-Tag: v3.10-rc2~7^2~46 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0abd5b17249ea5ca49a3a9ad4285cac3dfa8c30b;p=platform%2Fkernel%2Flinux-3.10.git Btrfs: return error when we specify wrong start to defrag We need such a sanity check for wrong start when we defrag a file, otherwise, even with a wrong start that's larger than file size, we can end up changing not only inode's force compress flag but also FS's incompat flags. Signed-off-by: Liu Bo Reviewed-by: David Sterba Signed-off-by: Josef Bacik --- diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index ace88c1..a74edc7 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1154,8 +1154,11 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, u64 new_align = ~((u64)128 * 1024 - 1); struct page **pages = NULL; - if (extent_thresh == 0) - extent_thresh = 256 * 1024; + if (isize == 0) + return 0; + + if (range->start >= isize) + return -EINVAL; if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) { if (range->compress_type > BTRFS_COMPRESS_TYPES) @@ -1164,8 +1167,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, compress_type = range->compress_type; } - if (isize == 0) - return 0; + if (extent_thresh == 0) + extent_thresh = 256 * 1024; /* * if we were not given a file, allocate a readahead