f2fs: check range before defragment
authorSheng Yong <shengyong1@huawei.com>
Wed, 8 Mar 2017 02:47:12 +0000 (10:47 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 22 Mar 2017 02:34:25 +0000 (22:34 -0400)
This patch checks the parameter range passed by ioctl to void that range
exceeds the max_file_blocks limit.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c

index 427ab1b41de3c6c05fc7203a33ebf5c15b0437a0..300d62015c2457899ef547c367ff9c148137e763 100644 (file)
@@ -2054,6 +2054,12 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg)
                goto out;
        }
 
+       if (unlikely((range.start + range.len) >> PAGE_SHIFT >
+                                       sbi->max_file_blocks)) {
+               err = -EINVAL;
+               goto out;
+       }
+
        err = f2fs_defragment_range(sbi, filp, &range);
        f2fs_update_time(sbi, REQ_TIME);
        if (err < 0)