Skip to contentSkip to conversation

md/bitmap: Avoid chunksize overflow

PATCH New Jack Wang 1 participant 1 message Oct 4, 2022

Subsystems (2)
lore
Share & tools
lore

Jack Wang

author
#0 lore raw

PATCH 1/1 md/bitmap: Avoid chunksize overflow

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.

---
 drivers/md/md-bitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-bitmap.c +1 -1
index bf6dffadbe6f..b4d7a606a9d8 100644
@@ -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,
Signature · 1 line
2.34.1