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 0/3] md: enforce MD_SB_DISKS bounds across v0.90 superblock paths
Date: Tue, 17 Nov 2026 14:50:50 +0530 [thread overview]
Message-ID: <20261117092053.10884-1-chandradhar.2003@gmail.com> (raw)
The legacy v0.90 superblock format (mdp_super_t) embeds a fixed-size
array of MD_SB_DISKS (27) disk descriptors (sb->disks[27]). Currently,
several configuration, metadata load, and sysfs store paths do not
enforce this upper bound, allowing mddev->raid_disks, rdev->raid_disk,
or rdev->desc_nr to exceed MD_SB_DISKS - 1 and trigger an out-of-bounds
array access in super_90_sync():
UBSAN: array-index-out-of-bounds in drivers/md/md.c:1740:29
index 124 is out of range for type 'mdp_disk_t [27]'
To keep each logical change self-contained and easier to review, v5
splits the fix into a 3-patch series:
- Patch 1/3 hardens on-disk v0.90 metadata loading, validation, and
synchronization (super_90_load(), super_90_validate(), and
super_90_sync()), preventing the out-of-bounds access reported by
syzbot.
- Patch 2/3 validates raid_disks and maintains mddev->max_disks when
configuring v0.90 arrays via metadata_store() and md_set_array_info().
- Patch 3/3 enforces max_disks and MD_SB_DISKS bounds across all
branches of raid_disks_store() and slot_store() so out-of-range sysfs
configurations are rejected upfront.
Changes in v5:
- Split the monolithic patch into a 3-patch series.
- Use 64-bit signed arithmetic (s64)mddev->raid_disks - mddev->delta_disks
and reject negative disk or pre-reshape counts in metadata_store() and
md_set_array_info().
Changes in v4:
- Cast sb->delta_disks to s32 before subtracting in super_90_load() so
shrinking reshapes do not zero-extend negative deltas.
- Check pre-reshape disk count against MD_SB_DISKS in metadata_store()
and md_set_array_info().
- Update Fixes tag to commit 1a33a379e678 ("md: reject v0.90 arrays with
too many devices").
Changes in v3:
- In super_90_load(), also validate sb->delta_disks (for minor >= 91)
and active/sync disk raid_disk indices against MD_SB_DISKS.
- Move the rdev->desc_nr bounds check to the top of super_90_validate()
before the mddev->pers == NULL branch indexes sb->disks[], and check
desc->raid_disk < MD_SB_DISKS before assigning rdev->raid_disk.
- Reject n > INT_MAX in raid_disks_store() to prevent signed overflow of
mddev->raid_disks prior to metadata_store().
- Update mddev->max_disks in the info->raid_disks == 0 branch and the
non-persistent branch of md_set_array_info().
Changes in v2:
- Drop early return in super_90_sync() so rdev->sb_size and sb_page are
initialized before sync_sbs() sets rdev->sb_loaded = 1.
- Do not reset rdev2->desc_nr = -1 or zero sb->this_disk on skip; instead
populate sb->this_disk as faulty/removed with rdev->desc_nr.
- Validate mddev->raid_disks and set mddev->max_disks in metadata_store(),
and move the raid_disks_store() check above the reshape/active branches.
Chandradhar Kumar (3):
md: validate v0.90 superblock disk bounds on load and sync
md: maintain max_disks for v0.90 arrays in metadata_store and ioctl
md: enforce max_disks and MD_SB_DISKS in raid_disks and slot sysfs
stores
drivers/md/md.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 86 insertions(+), 3 deletions(-)
--
2.56.1
next 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 Chandradhar Kumar [this message]
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 ` [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-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+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®