Patch "Btrfs: fix segmentation fault when doing dio read" has been added to the 4.9-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
Btrfs: fix segmentation fault when doing dio read
to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
btrfs-fix-segmentation-fault-when-doing-dio-read.patch
and it can be found in the queue-4.9 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Thu Oct 5 10:28:31 CEST 2017
From: Liu Bo <[email protected]>
Date: Fri, 7 Apr 2017 13:11:10 -0700
Subject: Btrfs: fix segmentation fault when doing dio read
From: Liu Bo <[email protected]>
[ Upstream commit 97bf5a5589aa3a59c60aa775fc12ec0483fc5002 ]
Commit 2dabb3248453 ("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.
--- fs/btrfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +6 -2
@@ -8050,8 +8050,10 @@ next_block_or_try_again: start += sectorsize; -if (nr_sectors--) { + nr_sectors--; +if (nr_sectors) { pgoff += sectorsize; +ASSERT (pgoff <PAGE_SIZE ); goto next_block_or_try_again; } }
@@ -8157,8 +8159,10 @@ next:ASSERT (nr_sectors); -if (--nr_sectors) { + nr_sectors--; +if (nr_sectors) { pgoff += sectorsize; +ASSERT (pgoff <PAGE_SIZE ); goto next_block; } }
Patches currently in stable-queue which might be from [email protected] are
queue-4.9/btrfs-fix-potential-use-after-free-for-cloned-bio.patch queue-4.9/btrfs-fix-segmentation-fault-when-doing-dio-read.patch