[PATCH v1 2/2] md/raid5: reject invalid reshape disks in raid5_run()

From: Chen Cheng

Date: Mon Sep 14 2026 - 09:36:55 EST


From: Chen Cheng <chencheng@xxxxxxxxx>

Check disk count before dividing by data disks while assembling a
reshape, otherwise too few disks can cause division by zero.

Reported-by: sashiko-bot <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Chen Cheng <chencheng@xxxxxxxxx>
---
drivers/md/raid5.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 4ab31af34b9f..bb0dd9324811 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -8051,10 +8051,11 @@ static int raid5_run(struct mddev *mddev)
* the array in read-only mode, so we check for that.
*/
sector_t here_new, here_old;
int old_disks;
int max_degraded = (mddev->level == 6 ? 2 : 1);
+ int min_disks = min_raid_disks(mddev->level);
int chunk_sectors;
int new_data_disks;

if (journal_dev) {
pr_warn("md/raid:%s: don't support reshape with journal - aborting.\n",
@@ -8066,10 +8067,16 @@ static int raid5_run(struct mddev *mddev)
pr_warn("md/raid:%s: unsupported reshape required - aborting.\n",
mdname(mddev));
return -EINVAL;
}
old_disks = mddev->raid_disks - mddev->delta_disks;
+ if (mddev->raid_disks < min_disks || old_disks < min_disks) {
+ pr_warn("md/raid:%s: invalid reshape disks (%d -> %d, min %d)\n",
+ mdname(mddev), old_disks, mddev->raid_disks,
+ min_disks);
+ return -EINVAL;
+ }
/* reshape_position must be on a new-stripe boundary, and one
* further up in new geometry must map after here in old
* geometry.
* If the chunk sizes are different, then as we perform reshape
* in units of the largest of the two, reshape_position needs
--
2.55.0