Commit 97bf5a55 authored by Liu Bo's avatar Liu Bo Committed by David Sterba

Btrfs: fix segmentation fault when doing dio read

Commit 2dabb324 ("Btrfs: Direct I/O read: Work on sectorsized blocks")
introduced this bug during iterating bio pages in dio read's endio hook,
and it could end up with segment fault of the dio reading task.

So the reason is 'if (nr_sectors--)', and it makes the code assume that
there is one more block in the same page, so page offset is increased and
the bio which is created to repair the bad block then has an incorrect
bvec.bv_offset, and a later access of the page content would throw a
segmentation fault.

This also adds ASSERT to check page offset against page size.
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2e949b0a
...@@ -7972,8 +7972,10 @@ static int __btrfs_correct_data_nocsum(struct inode *inode, ...@@ -7972,8 +7972,10 @@ static int __btrfs_correct_data_nocsum(struct inode *inode,
start += sectorsize; start += sectorsize;
if (nr_sectors--) { nr_sectors--;
if (nr_sectors) {
pgoff += sectorsize; pgoff += sectorsize;
ASSERT(pgoff < PAGE_SIZE);
goto next_block_or_try_again; goto next_block_or_try_again;
} }
} }
...@@ -8074,8 +8076,10 @@ static int __btrfs_subio_endio_read(struct inode *inode, ...@@ -8074,8 +8076,10 @@ static int __btrfs_subio_endio_read(struct inode *inode,
ASSERT(nr_sectors); ASSERT(nr_sectors);
if (--nr_sectors) { nr_sectors--;
if (nr_sectors) {
pgoff += sectorsize; pgoff += sectorsize;
ASSERT(pgoff < PAGE_SIZE);
goto next_block; goto next_block;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment