diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 427ab1b41de3c6c05fc7203a33ebf5c15b0437a0..300d62015c2457899ef547c367ff9c148137e763 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -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)