Skip to content

Commit a7297a6

Browse files
Ming Leiaxboe
authored andcommitted
block: loop: fix filesystem corruption in case of aio/dio
Starting from commit e36f620(block: split bios to max possible length), block core starts to split bio in the middle of bvec. Unfortunately loop dio/aio doesn't consider this situation, and always treat 'iter.iov_offset' as zero. Then filesystem corruption is observed. This patch figures out the offset of the base bvevc via 'bio->bi_iter.bi_bvec_done' and fixes the issue by passing the offset to iov iterator. Fixes: e36f620 (block: split bios to max possible length) Cc: Keith Busch <keith.busch@intel.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: stable@vger.kernel.org (4.5) Signed-off-by: Ming Lei <ming.lei@canonical.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent a522905 commit a7297a6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/block/loop.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
488488
bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
489489
iov_iter_bvec(&iter, ITER_BVEC | rw, bvec,
490490
bio_segments(bio), blk_rq_bytes(cmd->rq));
491+
/*
492+
* This bio may be started from the middle of the 'bvec'
493+
* because of bio splitting, so offset from the bvec must
494+
* be passed to iov iterator
495+
*/
496+
iter.iov_offset = bio->bi_iter.bi_bvec_done;
491497

492498
cmd->iocb.ki_pos = pos;
493499
cmd->iocb.ki_filp = file;

0 commit comments

Comments
 (0)