Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1733569

[PATCH for 4.9 10/39] Btrfs: fix segmentation fault when doing dio read

From "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Newsgroups linux.kernel
Subject [PATCH for 4.9 10/39] Btrfs: fix segmentation fault when doing dio read
Date 2017-09-18 02:30 +0200
Message-ID <uqS6L-6Te-37@gated-at.bofh.it> (permalink)
References <uqS6J-6Te-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Liu Bo <bo.li.liu@oracle.com>

[ 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.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
 fs/btrfs/inode.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 8a05fa7e2152..f089d7d8afe7 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8050,8 +8050,10 @@ static int __btrfs_correct_data_nocsum(struct inode *inode,
 
 		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 @@ static int __btrfs_subio_endio_read(struct inode *inode,
 
 		ASSERT(nr_sectors);
 
-		if (--nr_sectors) {
+		nr_sectors--;
+		if (nr_sectors) {
 			pgoff += sectorsize;
+			ASSERT(pgoff < PAGE_SIZE);
 			goto next_block;
 		}
 	}
-- 
2.11.0

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH for 4.9 01/39] net: core: Prevent from dereferencing null  pointer when releasing SKB "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-18 02:30 +0200
  [PATCH for 4.9 10/39] Btrfs: fix segmentation fault when doing dio  read "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-18 02:30 +0200
  [PATCH for 4.9 14/39] kasan: do not sanitize kexec purgatory "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-18 02:30 +0200
  [PATCH for 4.9 16/39] netfilter: invoke synchronize_rcu after set the  _hook_ to NULL "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-18 02:30 +0200
  Re: [PATCH for 4.9 01/39] net: core: Prevent from dereferencing null  pointer when releasing SKB Greg KH <greg@kroah.com> - 2017-09-18 08:50 +0200
    Re: [PATCH for 4.9 01/39] net: core: Prevent from dereferencing null  pointer when releasing SKB "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-18 16:20 +0200
      Re: [PATCH for 4.9 01/39] net: core: Prevent from dereferencing null  pointer when releasing SKB "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-18 16:40 +0200

csiph-web