* [PATCH v3] md/raid5: reject raid4/5 arrays with too few disks
@ 2026-09-11 4:15 Chen Cheng
2026-09-11 4:27 ` sashiko-bot
2026-09-12 11:46 ` yu kuai
0 siblings, 2 replies; 4+ messages in thread
From: Chen Cheng @ 2026-09-11 4:15 UTC (permalink / raw)
To: linux-raid, yukuai, nixiao
Cc: chencheng, linux-kernel, syzbot+de94ddbfff0c9e6fe030
From: Chen Cheng <chencheng@fnnas.com>
raid4 and raid5 require at least two disks, while raid6 requires at least
four disks. 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
v2->v3:
- Keep two-disk raid5 arrays valid by rejecting raid4/5 only below two disks
---
drivers/md/raid5.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index b91545ce090d..e1f20035703b 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7655,13 +7655,15 @@ 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 != 6 && mddev->raid_disks < 2) ||
+ (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 == 6 ? 4 : 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] 4+ messages in thread* Re: [PATCH v3] md/raid5: reject raid4/5 arrays with too few disks
2026-09-11 4:15 [PATCH v3] md/raid5: reject raid4/5 arrays with too few disks Chen Cheng
@ 2026-09-11 4:27 ` sashiko-bot
2026-09-12 11:45 ` yu kuai
2026-09-12 11:46 ` yu kuai
1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-09-11 4:27 UTC (permalink / raw)
To: Chen Cheng; +Cc: linux-raid, yukuai
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Division by zero in `raid5_run()` when assembling an array with an active reshape and insufficient data disks.
--
commit e2bb0701d8414cbf17eed6287965f8022ffe5eab
Author: Chen Cheng <chencheng@fnnas.com>
md/raid5: reject raid4/5 arrays with too few disks
raid4 and raid5 require at least two disks, while raid6 requires at least
four disks. 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().
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")
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index b91545ce090de..e1f20035703ba 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -7657,9 +7657,11 @@ static struct r5conf *setup_conf(struct mddev *mddev)
> 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 != 6 && mddev->raid_disks < 2) ||
> + (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 == 6 ? 4 : 2);
[Severity: High]
This isn't a bug introduced by this patch, but does this fully prevent
invalid array geometries from causing panics during array assembly?
In raid5_run(), if there is an active reshape and the array is assembled with
insufficient data disks, we calculate new_data_disks and divide by it before
setup_conf() is called to validate the array geometry:
drivers/md/raid5.c:raid5_run() {
if (mddev->reshape_position != MaxSector) {
...
new_data_disks = mddev->raid_disks - max_degraded;
if (sector_div(here_new, chunk_sectors * new_data_disks)) {
...
}
...
sector_div(here_old, chunk_sectors * (old_disks-max_degraded));
}
...
if (mddev->private == NULL)
conf = setup_conf(mddev);
}
If a crafted superblock sets raid_disks <= max_degraded and reshape_position
is not MaxSector, these divisions by zero are reached before the new checks
in setup_conf() can reject the array.
Could these checks be moved earlier in the assembly path to prevent the
divide-by-zero panics?
> return ERR_PTR(-EINVAL);
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260911041521.2433222-1-chencheng@fnnas.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v3] md/raid5: reject raid4/5 arrays with too few disks
2026-09-11 4:27 ` sashiko-bot
@ 2026-09-12 11:45 ` yu kuai
0 siblings, 0 replies; 4+ messages in thread
From: yu kuai @ 2026-09-12 11:45 UTC (permalink / raw)
To: sashiko-reviews, Chen Cheng, yu kuai; +Cc: linux-raid
Hi,
在 2026/9/11 12:27, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Division by zero in `raid5_run()` when assembling an array with an active reshape and insufficient data disks.
> --
>
> commit e2bb0701d8414cbf17eed6287965f8022ffe5eab
> Author: Chen Cheng <chencheng@fnnas.com>
>
> md/raid5: reject raid4/5 arrays with too few disks
>
> raid4 and raid5 require at least two disks, while raid6 requires at least
> four disks. 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().
>
> 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")
>
>> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
>> index b91545ce090de..e1f20035703ba 100644
>> --- a/drivers/md/raid5.c
>> +++ b/drivers/md/raid5.c
>> @@ -7657,9 +7657,11 @@ static struct r5conf *setup_conf(struct mddev *mddev)
>> 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 != 6 && mddev->raid_disks < 2) ||
>> + (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 == 6 ? 4 : 2);
> [Severity: High]
> This isn't a bug introduced by this patch, but does this fully prevent
> invalid array geometries from causing panics during array assembly?
>
> In raid5_run(), if there is an active reshape and the array is assembled with
> insufficient data disks, we calculate new_data_disks and divide by it before
> setup_conf() is called to validate the array geometry:
>
> drivers/md/raid5.c:raid5_run() {
> if (mddev->reshape_position != MaxSector) {
> ...
> new_data_disks = mddev->raid_disks - max_degraded;
> if (sector_div(here_new, chunk_sectors * new_data_disks)) {
> ...
> }
> ...
> sector_div(here_old, chunk_sectors * (old_disks-max_degraded));
> }
> ...
> if (mddev->private == NULL)
> conf = setup_conf(mddev);
> }
This looks like a valid problem as well.
>
> If a crafted superblock sets raid_disks <= max_degraded and reshape_position
> is not MaxSector, these divisions by zero are reached before the new checks
> in setup_conf() can reject the array.
>
> Could these checks be moved earlier in the assembly path to prevent the
> divide-by-zero panics?
>
>> return ERR_PTR(-EINVAL);
>> }
>>
--
Thanks,
Kuai
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] md/raid5: reject raid4/5 arrays with too few disks
2026-09-11 4:15 [PATCH v3] md/raid5: reject raid4/5 arrays with too few disks Chen Cheng
2026-09-11 4:27 ` sashiko-bot
@ 2026-09-12 11:46 ` yu kuai
1 sibling, 0 replies; 4+ messages in thread
From: yu kuai @ 2026-09-12 11:46 UTC (permalink / raw)
To: Chen Cheng, linux-raid, nixiao, yu kuai
Cc: linux-kernel, syzbot+de94ddbfff0c9e6fe030
在 2026/9/11 12:15, Chen Cheng 写道:
> From: Chen Cheng<chencheng@fnnas.com>
>
> raid4 and raid5 require at least two disks, while raid6 requires at least
> four disks. 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
>
> v2->v3:
> - Keep two-disk raid5 arrays valid by rejecting raid4/5 only below two disks
> ---
> drivers/md/raid5.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
Applied to md-7.3
--
Thanks,
Kuai
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-12 11:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 4:15 [PATCH v3] md/raid5: reject raid4/5 arrays with too few disks Chen Cheng
2026-09-11 4:27 ` sashiko-bot
2026-09-12 11:45 ` yu kuai
2026-09-12 11:46 ` yu kuai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox