f2fs: fix negative value for lseek offset
authorJaegeuk Kim <jaegeuk@kernel.org>
Mon, 8 Sep 2014 17:59:43 +0000 (10:59 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 9 Sep 2014 21:46:36 +0000 (14:46 -0700)
If application throws negative value of lseek with SEEK_DATA|SEEK_HOLE,
previous f2fs went into BUG_ON in get_dnode_of_data, which was reported
by Tommi Rantala.

He could make a simple code to detect this having:
lseek(fd, -17595150933902LL, SEEK_DATA);

This patch should resolve that bug.

Reported-by: Tommi Rentala <tt.rantala@gmail.com>
[Jaegeuk Kim: relocate the condition as suggested by Chao]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c

index 9f0ea3d3251be88c88f5e385e6e7ac7aa81251ac..5cde363cf7a827602169fbf7bec15676086a8e5c 100644 (file)
@@ -353,6 +353,8 @@ static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence)
                                                maxbytes, i_size_read(inode));
        case SEEK_DATA:
        case SEEK_HOLE:
+               if (offset < 0)
+                       return -ENXIO;
                return f2fs_seek_block(file, offset, whence);
        }