Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] md/raid0: validate device count before allocating devlist
@ 2026-09-07 13:29 Chandradhar Kumar
  2026-09-12  3:50 ` yu kuai
  0 siblings, 1 reply; 2+ messages in thread
From: Chandradhar Kumar @ 2026-09-07 13:29 UTC (permalink / raw)
  To: song, yukuai
  Cc: magiclinan, xiao, linux-raid, linux-kernel,
	syzbot+a32ff75e417c0f49a8e9, Chandradhar Kumar

create_strip_zones() allocates conf->devlist based on mddev->raid_disks
before verifying that number of devices matches raid_disks. Move the
existing device count validation before allocation to reject invalid
configurations before attempting a potentially excessive allocation.

Fixes: 078d1d8e688d ("md/raid0: use kvzalloc/kvfree for strip_zone and devlist allocations")
Reported-by: syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=a32ff75e417c0f49a8e9
Signed-off-by: Chandradhar Kumar <chandradhar.2003@gmail.com>
---
v2 -> v3:
- Move the existing device count validation before the allocation
- Add the requested fixes tag

v1: https://lore.kernel.org/all/20260906143928.105165-1-chandradhar.2003@gmail.com/
v2: https://lore.kernel.org/all/20260906184406.2141-1-chandradhar.2003@gmail.com/

 drivers/md/raid0.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 35e103f0c2c3..453e8abda22b 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -79,7 +79,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
 	*private_conf = ERR_PTR(-ENOMEM);
 	if (!conf)
 		return -ENOMEM;
+
+	cnt = 0;
 	rdev_for_each(rdev1, mddev) {
+		cnt++;
 		pr_debug("md/raid0:%s: looking at %pg\n",
 			 mdname(mddev),
 			 rdev1->bdev);
@@ -144,6 +147,14 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
 	}
 
 	err = -ENOMEM;
+
+	if (cnt != mddev->raid_disks) {
+		pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
+			mdname(mddev), cnt, mddev->raid_disks);
+		err = -EINVAL;
+		goto abort;
+	}
+
 	conf->strip_zone = kvzalloc_objs(struct strip_zone, conf->nr_strip_zones);
 	if (!conf->strip_zone)
 		goto abort;
@@ -200,11 +211,6 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
 			smallest = rdev1;
 		cnt++;
 	}
-	if (cnt != mddev->raid_disks) {
-		pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
-			mdname(mddev), cnt, mddev->raid_disks);
-		goto abort;
-	}
 	zone->nb_dev = cnt;
 	zone->zone_end = smallest->sectors * cnt;
 
-- 
2.55.0


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

* Re: [PATCH v3] md/raid0: validate device count before allocating devlist
  2026-09-07 13:29 [PATCH v3] md/raid0: validate device count before allocating devlist Chandradhar Kumar
@ 2026-09-12  3:50 ` yu kuai
  0 siblings, 0 replies; 2+ messages in thread
From: yu kuai @ 2026-09-12  3:50 UTC (permalink / raw)
  To: Chandradhar Kumar, song, yu kuai
  Cc: magiclinan, xiao, linux-raid, linux-kernel,
	syzbot+a32ff75e417c0f49a8e9

在 2026/9/7 21:29, Chandradhar Kumar 写道:

> create_strip_zones() allocates conf->devlist based on mddev->raid_disks
> before verifying that number of devices matches raid_disks. Move the
> existing device count validation before allocation to reject invalid
> configurations before attempting a potentially excessive allocation.
>
> Fixes: 078d1d8e688d ("md/raid0: use kvzalloc/kvfree for strip_zone and devlist allocations")
> Reported-by:syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com
> Closes:https://syzbot.org/bug?extid=a32ff75e417c0f49a8e9
> Signed-off-by: Chandradhar Kumar<chandradhar.2003@gmail.com>
> ---
> v2 -> v3:
> - Move the existing device count validation before the allocation
> - Add the requested fixes tag
>
> v1:https://lore.kernel.org/all/20260906143928.105165-1-chandradhar.2003@gmail.com/
> v2:https://lore.kernel.org/all/20260906184406.2141-1-chandradhar.2003@gmail.com/
>
>   drivers/md/raid0.c | 16 +++++++++++-----
>   1 file changed, 11 insertions(+), 5 deletions(-)
Applied to md-7.3

-- 
Thanks,
Kuai

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

end of thread, other threads:[~2026-09-12  3:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07 13:29 [PATCH v3] md/raid0: validate device count before allocating devlist Chandradhar Kumar
2026-09-12  3:50 ` yu kuai

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