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 2/3] md: maintain max_disks for v0.90 arrays in metadata_store and ioctl
Date: Tue, 17 Nov 2026 14:50:52 +0530 [thread overview]
Message-ID: <20261117092053.10884-3-chandradhar.2003@gmail.com> (raw)
In-Reply-To: <20261117092053.10884-1-chandradhar.2003@gmail.com>
When a v0.90 array is assembled from on-disk superblocks,
super_90_validate() sets mddev->max_disks = MD_SB_DISKS (27). However,
when an array is configured via sysfs (metadata_store) or the
SET_ARRAY_INFO ioctl (md_set_array_info), mddev->max_disks is not
consistently updated across metadata transitions, and existing or
requested disk counts are not validated against MD_SB_DISKS.
Fix both configuration paths:
1. In metadata_store(), when switching to v0.90 metadata (major == 0),
verify that mddev->raid_disks and the pre-reshape disk count
((s64)mddev->raid_disks - mddev->delta_disks) are within
[0, MD_SB_DISKS], and set mddev->max_disks = MD_SB_DISKS (or reset
it to 0 for non-v0.90 / external / non-persistent metadata).
2. In md_set_array_info(), reject negative or > MD_SB_DISKS raid_disks
values for persistent v0.90 arrays, validate existing raid_disks and
pre-reshape counts in the info->raid_disks == 0 branch, and update
mddev->max_disks across both persistent and non-persistent 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 | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 6baf209703c8..b09553078353 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5063,6 +5063,7 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len)
mddev->external = 0;
mddev->major_version = 0;
mddev->minor_version = 90;
+ mddev->max_disks = 0;
goto out_unlock;
}
if (strncmp(buf, "external:", 9) == 0) {
@@ -5077,6 +5078,7 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len)
mddev->external = 1;
mddev->major_version = 0;
mddev->minor_version = 90;
+ mddev->max_disks = 0;
goto out_unlock;
}
major = simple_strtoul(buf, &e, 10);
@@ -5090,10 +5092,17 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len)
err = -ENOENT;
if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL)
goto out_unlock;
+ err = -EINVAL;
+ if (major == 0 &&
+ (mddev->raid_disks < 0 || mddev->raid_disks > MD_SB_DISKS ||
+ (s64)mddev->raid_disks - mddev->delta_disks < 0 ||
+ (s64)mddev->raid_disks - mddev->delta_disks > MD_SB_DISKS))
+ goto out_unlock;
mddev->major_version = major;
mddev->minor_version = minor;
mddev->persistent = 1;
mddev->external = 0;
+ mddev->max_disks = (major == 0) ? MD_SB_DISKS : 0;
err = 0;
out_unlock:
mddev_unlock(mddev);
@@ -7975,16 +7984,33 @@ int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
info->major_version);
return -EINVAL;
}
+ if (!info->not_persistent && info->major_version == 0 &&
+ (mddev->raid_disks < 0 ||
+ mddev->raid_disks > MD_SB_DISKS ||
+ (s64)mddev->raid_disks - mddev->delta_disks < 0 ||
+ (s64)mddev->raid_disks - mddev->delta_disks > MD_SB_DISKS))
+ return -EINVAL;
mddev->major_version = info->major_version;
mddev->minor_version = info->minor_version;
mddev->patch_version = info->patch_version;
mddev->persistent = !info->not_persistent;
+ mddev->max_disks = (mddev->persistent &&
+ info->major_version == 0) ?
+ MD_SB_DISKS : 0;
/* ensure mddev_put doesn't delete this now that there
* is some minimal configuration.
*/
mddev->ctime = ktime_get_real_seconds();
return 0;
}
+
+ if (info->raid_disks < 0 ||
+ (!info->not_persistent && info->raid_disks > MD_SB_DISKS)) {
+ pr_warn("md: %s: invalid raid_disks %d for v0.90 superblock\n",
+ mdname(mddev), info->raid_disks);
+ return -EINVAL;
+ }
+
mddev->major_version = MD_MAJOR_VERSION;
mddev->minor_version = MD_MINOR_VERSION;
mddev->patch_version = MD_PATCHLEVEL_VERSION;
@@ -8014,6 +8040,8 @@ int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
mddev->max_disks = MD_SB_DISKS;
mddev->flags = 0;
mddev->sb_flags = 0;
+ } else {
+ mddev->max_disks = 0;
}
set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
--
2.56.1
next 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 ` Chandradhar Kumar [this message]
2026-11-17 9:20 ` [PATCH v5 3/3] md: enforce max_disks and MD_SB_DISKS in raid_disks and slot sysfs stores Chandradhar Kumar
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-3-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®