linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md/bitmap: avoid read out of the disk
@ 2017-10-10 21:20 Shaohua Li
  2017-10-11 12:41 ` Joshua Kinard
  2017-10-12  3:09 ` NeilBrown
  0 siblings, 2 replies; 22+ messages in thread
From: Shaohua Li @ 2017-10-10 21:20 UTC (permalink / raw)
  To: linux-raid; +Cc: kumba, Shaohua Li, Song Liu

From: Shaohua Li <shli@fb.com>

If PAGE_SIZE is bigger than 4k, we could read out of the disk boundary. Limit
the read size to the end of disk. Write path already has similar limitation.

Fix: 8031c3ddc70a(md/bitmap: copy correct data for bitmap super)
Reported-by: Joshua Kinard <kumba@gentoo.org>
Tested-by: Joshua Kinard <kumba@gentoo.org>
Cc: Song Liu <songliubraving@fb.com>
Signed-off-by: Shaohua Li <shli@fb.com>
---
 drivers/md/bitmap.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index d2121637b4ab..f68ec973fbdd 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -153,6 +153,7 @@ static int read_sb_page(struct mddev *mddev, loff_t offset,
 
 	struct md_rdev *rdev;
 	sector_t target;
+	int target_size;
 
 	rdev_for_each(rdev, mddev) {
 		if (! test_bit(In_sync, &rdev->flags)
@@ -161,9 +162,12 @@ static int read_sb_page(struct mddev *mddev, loff_t offset,
 			continue;
 
 		target = offset + index * (PAGE_SIZE/512);
+		target_size = min_t(u64, size, i_size_read(rdev->bdev->bd_inode) -
+			((target + rdev->sb_start) << 9));
+		target_size = roundup(target_size,
+			bdev_logical_block_size(rdev->bdev));
 
-		if (sync_page_io(rdev, target,
-				 roundup(size, bdev_logical_block_size(rdev->bdev)),
+		if (sync_page_io(rdev, target, target_size,
 				 page, REQ_OP_READ, 0, true)) {
 			page->index = index;
 			return 0;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2017-10-19 23:21 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-10 21:20 [PATCH] md/bitmap: avoid read out of the disk Shaohua Li
2017-10-11 12:41 ` Joshua Kinard
2017-10-12  3:09 ` NeilBrown
2017-10-12 17:30   ` Shaohua Li
2017-10-12 17:53     ` Song Liu
2017-10-12 21:46       ` NeilBrown
2017-10-12 22:51         ` Shaohua Li
2017-10-13  5:16       ` NeilBrown
2017-10-13 19:51         ` Shaohua Li
2017-10-16 16:21           ` Song Liu
2017-10-16 21:15             ` NeilBrown
2017-10-16 23:56               ` Shaohua Li
2017-10-17  3:24                 ` [PATCH] md: forbid a RAID5 from having both a bitmap and a journal NeilBrown
2017-10-17 20:41                   ` John Stoffel
2017-10-17 21:03                     ` NeilBrown
2017-10-18  1:51                       ` Joshua Kinard
2017-10-19 23:16                         ` Wols Lists
2017-10-18 14:48                       ` John Stoffel
2017-10-19 23:21                         ` Wols Lists
2017-10-18  1:50                   ` Joshua Kinard
2017-10-19  3:16                   ` Shaohua Li
2017-10-12 21:44     ` [PATCH] md/bitmap: avoid read out of the disk NeilBrown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).