Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] md/raid5: reject raid4/5 arrays with too few disks
@ 2026-09-05 10:43 Chen Cheng
  2026-09-05 11:00 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Cheng @ 2026-09-05 10:43 UTC (permalink / raw)
  To: linux-raid, yukuai, xiaoni
  Cc: chencheng, linux-kernel, syzbot+de94ddbfff0c9e6fe030

From: Chen Cheng <chencheng@fnnas.com>

raid4 requires at least two disks and raid5 requires at least three disks,
but setup_conf() only rejects raid6 arrays with fewer than four disks. As a
result, an invalid raid4 or raid5 array can be assembled with no data disks
and later reach raid5_set_limits().

Reject such arrays before the r5conf is created. This prevents the invalid
geometry from reaching queue limit setup, where roundup_pow_of_two() can be
called with a zero stripe size.

Reported-by: syzbot+de94ddbfff0c9e6fe030@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/6a778c82.01d0871a.3a0d52.006a.GAE@google.com/
Fixes: f63f17350e53 ("md/raid5: use the atomic queue limit update APIs")
Signed-off-by: Chen Cheng <chencheng@fnnas.com>
---
v1->v2:
- Fix wrong tags
- Check raid-4 also
---
 drivers/md/raid5.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b91545ce090d..4d8bb0cf2605 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7655,13 +7655,16 @@ static struct r5conf *setup_conf(struct mddev *mddev)
 	     && !algorithm_valid_raid6(mddev->new_layout))) {
 		pr_warn("md/raid:%s: layout %d not supported\n",
 			mdname(mddev), mddev->new_layout);
 		return ERR_PTR(-EIO);
 	}
-	if (mddev->new_level == 6 && mddev->raid_disks < 4) {
-		pr_warn("md/raid:%s: not enough configured devices (%d, minimum 4)\n",
-			mdname(mddev), mddev->raid_disks);
+	if ((mddev->new_level == 4 && mddev->raid_disks < 2) ||
+	    (mddev->new_level == 5 && mddev->raid_disks < 3) ||
+	    (mddev->new_level == 6 && mddev->raid_disks < 4)) {
+		pr_warn("md/raid:%s: not enough configured devices (%d, minimum %d)\n",
+			mdname(mddev), mddev->raid_disks,
+			mddev->new_level - 2);
 		return ERR_PTR(-EINVAL);
 	}
 
 	if (!mddev->new_chunk_sectors ||
 	    (mddev->new_chunk_sectors << 9) % PAGE_SIZE ||
-- 
2.55.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-07  6:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-05 10:43 [PATCH v2] md/raid5: reject raid4/5 arrays with too few disks Chen Cheng
2026-09-05 11:00 ` sashiko-bot
2026-09-07  6:35   ` yu kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox