[PATCH v5 0/3] md: enforce MD_SB_DISKS bounds across v0.90 superblock paths
From: Chandradhar Kumar
Date: Tue Nov 17 2026 - 04:21:19 EST
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