Skip to contentSkip to conversation

md/raid5: fail invalid raid5_set_limits() geometry

PATCH In review Chen Cheng 2 participants 2 messages Aug 11 – Sep 5 MD RAID

lore
Share & tools
lore

Chen Cheng

author
#0 lore raw

PATCH 1/1 md/raid5: fail invalid raid5_set_limits() geometry

From: Chen Cheng <[email protected]>

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

Reported-by [email protected]
Fixes f63f17350e537300312 ("md/raid5: use the atomic queue limit update APIs")
---
 drivers/md/raid5.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/raid5.c +2 -0
index ffb5fcde54a9..c0adb73b1dd4 100644
@@ -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
 	 */
Signature · 1 line
2.55.0
maintainer
#1 lore raw

Hi,

Quoted 8 lines · Chen Cheng

From: Chen Cheng <[email protected]>

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

Reported-by [email protected]
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.

Quoted 11 lines
---
  drivers/md/raid5.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/md/raid5.c +0 -0
index ffb5fcde54a9..c0adb73b1dd4 100644

drivers/md/raid5.c static int raid5_set_limits(struct mddev *mddev) · line 7831

Quoted 7 lines
drivers/md/raid5.c +2 -0
@@ -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/[email protected]/T/#m635e3614888a7ec9d9a1cc4fd15660d538dedfd0>

Just raid5 should contain at lease 3 disks.

Quoted 5 lines
drivers/md/raid5.c +0 -0
  	/*
  	 * We can only discard a whole stripe. It doesn't make sense to
  	 * discard data disk but write parity disk
  	 */
Signature · 2 lines
Thanks,
Kuai