From: Chandradhar Kumar <chandradhar.2003@gmail.com>
To: song@kernel.org, yukuai@fygo.io
Cc: magiclinan@didiglobal.com, xiao@kernel.org,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com,
Chandradhar Kumar <chandradhar.2003@gmail.com>
Subject: [PATCH v3] md/raid0: validate device count before allocating devlist
Date: Mon, 7 Sep 2026 18:59:36 +0530 [thread overview]
Message-ID: <20260907132936.6677-1-chandradhar.2003@gmail.com> (raw)
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
next reply other threads:[~2026-09-07 13:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 13:29 Chandradhar Kumar [this message]
2026-09-12 3:50 ` [PATCH v3] md/raid0: validate device count before allocating devlist yu kuai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260907132936.6677-1-chandradhar.2003@gmail.com \
--to=chandradhar.2003@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=song@kernel.org \
--cc=syzbot+a32ff75e417c0f49a8e9@syzkaller.appspotmail.com \
--cc=xiao@kernel.org \
--cc=yukuai@fygo.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.