[PATCH] md/raid5: fail invalid raid5_set_limits() geometry

Chen Cheng posted 1 patch 1 month, 2 weeks ago
drivers/md/raid5.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] md/raid5: fail invalid raid5_set_limits() geometry
Posted by Chen Cheng 1 month, 2 weeks ago
From: Chen Cheng <chencheng@fnnas.com>

Prevent raid5_set_limits() from building a stripe size when the array
geometry reports no data disks.

Reported-by: syzbot+de94ddbfff0c9e6fe030@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=de94ddbfff0c9e6fe030
Fixes: f63f17350e537300312 ("md/raid5: use the atomic queue limit update APIs")

Signed-off-by: Chen Cheng <chencheng@fnnas.com>
---
 drivers/md/raid5.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index ffb5fcde54a9..c0adb73b1dd4 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7825,10 +7825,12 @@ static int raid5_set_limits(struct mddev *mddev)
 	/*
 	 * The read-ahead size must cover two whole stripes, which is
 	 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices.
 	 */
 	data_disks = conf->previous_raid_disks - conf->max_degraded;
+	if (data_disks <= 0)
+		return -EINVAL;
 
 	/*
 	 * We can only discard a whole stripe. It doesn't make sense to
 	 * discard data disk but write parity disk
 	 */
-- 
2.55.0
Re: [PATCH] md/raid5: fail invalid raid5_set_limits() geometry
Posted by yu kuai 3 weeks, 3 days ago
Hi,

在 2026/8/11 18:14, Chen Cheng 写道:
> From: Chen Cheng <chencheng@fnnas.com>
>
> Prevent raid5_set_limits() from building a stripe size when the array
> geometry reports no data disks.
>
> Reported-by: syzbot+de94ddbfff0c9e6fe030@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=de94ddbfff0c9e6fe030
> Fixes: f63f17350e537300312 ("md/raid5: use the atomic queue limit update APIs")

The closes link is wrong, please use lore url. And the fix tag is wrong as well,
12-character SHA should be used.

>
> Signed-off-by: Chen Cheng <chencheng@fnnas.com>
> ---
>   drivers/md/raid5.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
> index ffb5fcde54a9..c0adb73b1dd4 100644
> --- a/drivers/md/raid5.c
> +++ b/drivers/md/raid5.c
> @@ -7825,10 +7825,12 @@ static int raid5_set_limits(struct mddev *mddev)
>   	/*
>   	 * The read-ahead size must cover two whole stripes, which is
>   	 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices.
>   	 */
>   	data_disks = conf->previous_raid_disks - conf->max_degraded;
> +	if (data_disks <= 0)
> +		return -EINVAL;

Looks like following is the correct fix:

[syzbot] [raid?] UBSAN: shift-out-of-bounds in raid5_set_limits 
<https://lore.kernel.org/all/6a778c82.01d0871a.3a0d52.006a.GAE@google.com/T/#m635e3614888a7ec9d9a1cc4fd15660d538dedfd0>

Just raid5 should contain at lease 3 disks.

>   
>   	/*
>   	 * We can only discard a whole stripe. It doesn't make sense to
>   	 * discard data disk but write parity disk
>   	 */

-- 
Thanks,
Kuai