[PATCH] md/bitmap: Avoid chunksize overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When grow an array with bitmap to 4 TiB, the bitmap chunksize
will be
head /sys/block/md0/md/bitmap/chunksize <==
18446744071562067968

with 8 Tib, the chunksize is 4, which lead to assemble failure.
The root cause is due to left shift count >= width of type and overflow.

The fix is simple, do a type cast before shift, the bug is pretty old
since kernel 4.0 at least.

Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jack Wang <jinpu.wang@xxxxxxxxx>
---
 drivers/md/md-bitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index bf6dffadbe6f..b4d7a606a9d8 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2150,7 +2150,7 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
 	bitmap->counts.missing_pages = pages;
 	bitmap->counts.chunkshift = chunkshift;
 	bitmap->counts.chunks = chunks;
-	bitmap->mddev->bitmap_info.chunksize = 1 << (chunkshift +
+	bitmap->mddev->bitmap_info.chunksize = 1UL << (chunkshift +
 						     BITMAP_BLOCK_SHIFT);
 
 	blocks = min(old_counts.chunks << old_counts.chunkshift,
-- 
2.34.1




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux