diff options
author | Jan Kara <jack@suse.cz> | 2015-11-30 12:15:42 -0500 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2015-11-30 12:15:42 -0500 |
commit | 74cedf9b6c603f2278a05bc91b140b32b434d0b5 (patch) | |
tree | 0d4412cee169295a290867b72545b65c742527a8 | |
parent | bf4e6b4e757488dee1b6a581f49c7ac34cd217f8 (diff) |
direct-io: Fix negative return from dio read beyond eof
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and
we issue direct IO read at offset 1024, blockdev_direct_IO() reads the
tail of the last block and the logic for handling short DIO reads in
dio_complete() results in a return value -24 (1000 - 1024) which
obviously confuses userspace.
Fix the problem by bailing out early once we sample i_size and can
reliably check that direct IO read starts beyond i_size.
Reported-by: Avi Kivity <avi@scylladb.com>
Fixes: 9fe55eea7e4b444bafc42fa0000cc2d1d2847275
CC: stable@vger.kernel.org
CC: Steven Whitehouse <swhiteho@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | fs/direct-io.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/fs/direct-io.c b/fs/direct-io.c index cb5337d8c273..1c75a3a07f8f 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -1169,6 +1169,15 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, | |||
1169 | } | 1169 | } |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | /* Once we sampled i_size check for reads beyond EOF */ | ||
1173 | dio->i_size = i_size_read(inode); | ||
1174 | if (iov_iter_rw(iter) == READ && offset >= dio->i_size) { | ||
1175 | if (dio->flags & DIO_LOCKING) | ||
1176 | mutex_unlock(&inode->i_mutex); | ||
1177 | kmem_cache_free(dio_cache, dio); | ||
1178 | goto out; | ||
1179 | } | ||
1180 | |||
1172 | /* | 1181 | /* |
1173 | * For file extending writes updating i_size before data writeouts | 1182 | * For file extending writes updating i_size before data writeouts |
1174 | * complete can expose uninitialized blocks in dumb filesystems. | 1183 | * complete can expose uninitialized blocks in dumb filesystems. |
@@ -1222,7 +1231,6 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, | |||
1222 | sdio.next_block_for_io = -1; | 1231 | sdio.next_block_for_io = -1; |
1223 | 1232 | ||
1224 | dio->iocb = iocb; | 1233 | dio->iocb = iocb; |
1225 | dio->i_size = i_size_read(inode); | ||
1226 | 1234 | ||
1227 | spin_lock_init(&dio->bio_lock); | 1235 | spin_lock_init(&dio->bio_lock); |
1228 | dio->refcount = 1; | 1236 | dio->refcount = 1; |