md/bitmap: Avoid chunksize overflow
Subsystems (2)
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.
Signed-off-by Jack Wang <[email protected]>
--- drivers/md/md-bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/md-bitmap.c +1 -1
@@ -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