* [PATCH v2] md/raid0: validate device count before allocating devlist
@ 2026-09-06 18:44 Chandradhar Kumar
2026-09-07 6:49 ` yu kuai
0 siblings, 1 reply; 3+ messages in thread
From: Chandradhar Kumar @ 2026-09-06 18:44 UTC (permalink / raw)
To: song, yukuai, linux-raid
Cc: magiclinan, xiao, linux-kernel, Chandradhar Kumar,
syzbot+a32ff75e417c0f49a8e9
create_strip_zones() allocates conf->devlist based on mddev->raid_disks
before verifying that enough devices are present. Validate the number of
member devices before allocating devlist to reject invalid
configurations early.
The existing validation later in the function already rejects this
condition, but it occurs after the potentially excessive allocation.
Reported-by: syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=a32ff75e417c0f49a8e9
Signed-off-by: Chandradhar Kumar <chandradhar.2003@gmail.com>
v2:
- Reject non-positive raid-disks values, which can bypass the device
count validation and result in an oversized allocation.
---
drivers/md/raid0.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 35e103f0c2c3..8eaf078606d6 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -69,7 +69,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
sector_t curr_zone_end, sectors;
struct md_rdev *smallest, *rdev1, *rdev2, *rdev, **dev;
struct strip_zone *zone;
- int cnt;
+ int cnt, nr_devs;
struct r0conf *conf = kzalloc_obj(*conf);
unsigned int blksize = 512;
@@ -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;
+
+ nr_devs = 0;
rdev_for_each(rdev1, mddev) {
+ nr_devs++;
pr_debug("md/raid0:%s: looking at %pg\n",
mdname(mddev),
rdev1->bdev);
@@ -144,6 +147,21 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
}
err = -ENOMEM;
+
+ if (mddev->raid_disks <= 0) {
+ pr_warn("md/raid0:%s: invalid number of disks %d - aborting!\n",
+ mdname(mddev), mddev->raid_disks);
+ err = -EINVAL;
+ goto abort;
+ }
+
+ if (nr_devs < mddev->raid_disks) {
+ pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
+ mdname(mddev), nr_devs, 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;
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] md/raid0: validate device count before allocating devlist
2026-09-06 18:44 [PATCH v2] md/raid0: validate device count before allocating devlist Chandradhar Kumar
@ 2026-09-07 6:49 ` yu kuai
0 siblings, 0 replies; 3+ messages in thread
From: yu kuai @ 2026-09-07 6:49 UTC (permalink / raw)
To: Chandradhar Kumar, song, linux-raid, yu kuai
Cc: magiclinan, xiao, linux-kernel, syzbot+a32ff75e417c0f49a8e9
Hi,
在 2026/9/7 2:44, Chandradhar Kumar 写道:
> create_strip_zones() allocates conf->devlist based on mddev->raid_disks
> before verifying that enough devices are present. Validate the number of
> member devices before allocating devlist to reject invalid
> configurations early.
>
> The existing validation later in the function already rejects this
> condition, but it occurs after the potentially excessive allocation.
Since there is already a checking cnt != mddev->raid_disks, it doesn't make
sense to introduce redundant checking. Please move the checking forward to
fix the problem.
>
> Reported-by: syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com
> Closes: https://syzbot.org/bug?extid=a32ff75e417c0f49a8e9
Please add a fix tag.
> Signed-off-by: Chandradhar Kumar <chandradhar.2003@gmail.com>
>
> v2:
> - Reject non-positive raid-disks values, which can bypass the device
> count validation and result in an oversized allocation.
> ---
And change log should not be placed in commit message. Just move them here, and they
will be dropped when I apply the patch.
> drivers/md/raid0.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index 35e103f0c2c3..8eaf078606d6 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -69,7 +69,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
> sector_t curr_zone_end, sectors;
> struct md_rdev *smallest, *rdev1, *rdev2, *rdev, **dev;
> struct strip_zone *zone;
> - int cnt;
> + int cnt, nr_devs;
> struct r0conf *conf = kzalloc_obj(*conf);
> unsigned int blksize = 512;
>
> @@ -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;
> +
> + nr_devs = 0;
> rdev_for_each(rdev1, mddev) {
> + nr_devs++;
> pr_debug("md/raid0:%s: looking at %pg\n",
> mdname(mddev),
> rdev1->bdev);
> @@ -144,6 +147,21 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
> }
>
> err = -ENOMEM;
> +
> + if (mddev->raid_disks <= 0) {
> + pr_warn("md/raid0:%s: invalid number of disks %d - aborting!\n",
> + mdname(mddev), mddev->raid_disks);
> + err = -EINVAL;
> + goto abort;
> + }
> +
> + if (nr_devs < mddev->raid_disks) {
> + pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
> + mdname(mddev), nr_devs, 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;
--
Thanks,
Kuai
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] md/raid0: validate device count before allocating devlist
@ 2026-09-06 14:39 Chandradhar Kumar
2026-09-06 17:37 ` [PATCH v2] " Chandradhar Kumar
0 siblings, 1 reply; 3+ messages in thread
From: Chandradhar Kumar @ 2026-09-06 14:39 UTC (permalink / raw)
To: Song Liu, Yu Kuai, linux-raid
Cc: Li Nan, Xiao Ni, linux-kernel, Chandradhar Kumar,
syzbot+a32ff75e417c0f49a8e9
create_strip_zones() allocates conf->devlist based on mddev->raid_disks
before verifying that enough devices are present. Validate the number of
member devices before allocating devlist to reject invalid
configurations early.
The existing validation later in the function already rejects this
condition, but it occurs after the potentially excessive allocation.
Reported-by: syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=a32ff75e417c0f49a8e9
Signed-off-by: Chandradhar Kumar <chandradhar.2003@gmail.com>
---
drivers/md/raid0.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 35e103f0c2c3..586e3411f24c 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -69,7 +69,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
sector_t curr_zone_end, sectors;
struct md_rdev *smallest, *rdev1, *rdev2, *rdev, **dev;
struct strip_zone *zone;
- int cnt;
+ int cnt, nr_devs;
struct r0conf *conf = kzalloc_obj(*conf);
unsigned int blksize = 512;
@@ -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;
+
+ nr_devs = 0;
rdev_for_each(rdev1, mddev) {
+ nr_devs++;
pr_debug("md/raid0:%s: looking at %pg\n",
mdname(mddev),
rdev1->bdev);
@@ -147,6 +150,14 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
conf->strip_zone = kvzalloc_objs(struct strip_zone, conf->nr_strip_zones);
if (!conf->strip_zone)
goto abort;
+
+ if (nr_devs < mddev->raid_disks) {
+ pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
+ mdname(mddev), nr_devs, mddev->raid_disks);
+ err = -EINVAL;
+ goto abort;
+ }
+
conf->devlist = kvzalloc(array3_size(sizeof(struct md_rdev *),
conf->nr_strip_zones,
mddev->raid_disks),
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v2] md/raid0: validate device count before allocating devlist
2026-09-06 14:39 [PATCH] " Chandradhar Kumar
@ 2026-09-06 17:37 ` Chandradhar Kumar
0 siblings, 0 replies; 3+ messages in thread
From: Chandradhar Kumar @ 2026-09-06 17:37 UTC (permalink / raw)
To: song, yukuai, linux-raid
Cc: magiclinan, xiao, linux-kernel, Chandradhar Kumar,
syzbot+a32ff75e417c0f49a8e9
create_strip_zones() allocates conf->devlist based on mddev->raid_disks
before verifying that enough devices are present. Validate the number of
member devices before allocating devlist to reject invalid
configurations early.
The existing validation later in the function already rejects this
condition, but it occurs after the potentially excessive allocation.
Reported-by: syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=a32ff75e417c0f49a8e9
Signed-off-by: Chandradhar Kumar <chandradhar.2003@gmail.com>
v2:
- Reject non-positive raid-disks values, which can bypass the device
count validation and result in an oversized allocation.
---
drivers/md/raid0.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 35e103f0c2c3..8eaf078606d6 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -69,7 +69,7 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
sector_t curr_zone_end, sectors;
struct md_rdev *smallest, *rdev1, *rdev2, *rdev, **dev;
struct strip_zone *zone;
- int cnt;
+ int cnt, nr_devs;
struct r0conf *conf = kzalloc_obj(*conf);
unsigned int blksize = 512;
@@ -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;
+
+ nr_devs = 0;
rdev_for_each(rdev1, mddev) {
+ nr_devs++;
pr_debug("md/raid0:%s: looking at %pg\n",
mdname(mddev),
rdev1->bdev);
@@ -144,6 +147,21 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
}
err = -ENOMEM;
+
+ if (mddev->raid_disks <= 0) {
+ pr_warn("md/raid0:%s: invalid number of disks %d - aborting!\n",
+ mdname(mddev), mddev->raid_disks);
+ err = -EINVAL;
+ goto abort;
+ }
+
+ if (nr_devs < mddev->raid_disks) {
+ pr_warn("md/raid0:%s: too few disks (%d of %d) - aborting!\n",
+ mdname(mddev), nr_devs, 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;
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-07 6:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-06 18:44 [PATCH v2] md/raid0: validate device count before allocating devlist Chandradhar Kumar
2026-09-07 6:49 ` yu kuai
-- strict thread matches above, loose matches on Subject: below --
2026-09-06 14:39 [PATCH] " Chandradhar Kumar
2026-09-06 17:37 ` [PATCH v2] " Chandradhar Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®