stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md/bitmap: Avoid chunksize overflow
@ 2022-10-04  9:45 Jack Wang
  0 siblings, 0 replies; only message in thread
From: Jack Wang @ 2022-10-04  9:45 UTC (permalink / raw)
  To: linux-raid; +Cc: song, stable

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@vger.kernel.org
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-04  9:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04  9:45 [PATCH] md/bitmap: Avoid chunksize overflow Jack Wang

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