From: Chandradhar Kumar <chandradhar.2003@gmail.com>
To: song@kernel.org, yukuai@fygo.io
Cc: xiao@kernel.org, magiclinan@didiglobal.com,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com,
Chandradhar Kumar <chandradhar.2003@gmail.com>
Subject: [PATCH v5 3/3] md: enforce max_disks and MD_SB_DISKS in raid_disks and slot sysfs stores
Date: Tue, 17 Nov 2026 14:50:53 +0530 [thread overview]
Message-ID: <20261117092053.10884-4-chandradhar.2003@gmail.com> (raw)
In-Reply-To: <20261117092053.10884-1-chandradhar.2003@gmail.com>
Userspace can configure a persistent v0.90 array via sysfs with
mddev->raid_disks > MD_SB_DISKS or rdev->raid_disk >= MD_SB_DISKS when
mddev->max_disks is not yet populated or when writing to the inactive
or reshape sysfs paths.
Enforce the disk and slot bounds in raid_disks_store() and slot_store()
so invalid configurations are rejected upfront with -EINVAL or -ENOSPC:
1. In raid_disks_store(), reject values exceeding INT_MAX to prevent
signed overflow when assigning to mddev->raid_disks, and check
mddev->max_disks and MD_SB_DISKS (for persistent v0.90 arrays)
before branching into active, reshape, or inactive configuration.
2. In slot_store(), reject slot >= mddev->max_disks or slot >=
MD_SB_DISKS (for persistent v0.90 arrays) in both the active
hot-add and inactive configuration branches.
Fixes: 1a33a379e678 ("md: reject v0.90 arrays with too many devices")
Signed-off-by: Chandradhar Kumar <chandradhar.2003@gmail.com>
---
drivers/md/md.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index b09553078353..9fac810edc26 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3387,6 +3387,12 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len)
if (slot >= rdev->mddev->raid_disks &&
slot >= rdev->mddev->raid_disks + rdev->mddev->delta_disks)
return -ENOSPC;
+ if ((rdev->mddev->max_disks &&
+ slot >= rdev->mddev->max_disks) ||
+ (rdev->mddev->persistent &&
+ rdev->mddev->major_version == 0 &&
+ slot >= MD_SB_DISKS))
+ return -ENOSPC;
rdev->raid_disk = slot;
if (test_bit(In_sync, &rdev->flags))
@@ -3408,6 +3414,12 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len)
if (slot >= rdev->mddev->raid_disks &&
slot >= rdev->mddev->raid_disks + rdev->mddev->delta_disks)
return -ENOSPC;
+ if ((rdev->mddev->max_disks &&
+ slot >= rdev->mddev->max_disks) ||
+ (rdev->mddev->persistent &&
+ rdev->mddev->major_version == 0 &&
+ slot >= MD_SB_DISKS))
+ return -ENOSPC;
rdev->raid_disk = slot;
/* assume it is working */
clear_bit(Faulty, &rdev->flags);
@@ -4471,11 +4483,20 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
err = kstrtouint(buf, 10, &n);
if (err < 0)
return err;
+ if (n > INT_MAX)
+ return -EINVAL;
err = mddev_suspend_and_lock(mddev);
if (err)
return err;
noio_flags = memalloc_noio_save();
+ if ((mddev->max_disks && n > mddev->max_disks) ||
+ (mddev->persistent && mddev->major_version == 0 &&
+ n > MD_SB_DISKS)) {
+ err = -EINVAL;
+ goto out_unlock;
+ }
+
if (mddev->pers) {
if (n != mddev->raid_disks)
err = update_raid_disks(mddev, n);
--
2.56.1
prev parent reply other threads:[~2026-11-17 9:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 9:20 [PATCH v5 0/3] md: enforce MD_SB_DISKS bounds across v0.90 superblock paths Chandradhar Kumar
2026-11-17 9:20 ` [PATCH v5 1/3] md: validate v0.90 superblock disk bounds on load and sync Chandradhar Kumar
2026-11-17 9:20 ` [PATCH v5 2/3] md: maintain max_disks for v0.90 arrays in metadata_store and ioctl Chandradhar Kumar
2026-11-17 9:20 ` Chandradhar Kumar [this message]
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=20261117092053.10884-4-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+9e3014263a35700ab49b@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 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®