md: enforce MD_SB_DISKS bounds across v0.90 superblock paths
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest3 patches 0 repliesNew
- v41 patch 0 repliesSuperseded
- v31 patch 0 repliesSuperseded
Earlier versions · 2
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v2 | 1 patch | 0 replies | Superseded | |
| v1 | 1 patch | 0 replies | Superseded |
Changes in v5 from the cover letter
- 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().
Patches in v5 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | md: validate v0.90 superblock disk bounds on load and syncdrivers/ | +37 | 0 replies | |
| 2/3 | md: maintain max_disks for v0.90 arrays in metadata_store and ioctldrivers/ | +28 | 0 replies | |
| 3/3 | md: enforce max_disks and MD_SB_DISKS in raid_disks and slot sysfs storesdrivers/ | +21 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.
Cover letter [PATCH v5 0/3] md: enforce MD_SB_DISKS bounds across v0.90 superblock paths
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(-)
Signature · 1 line
2.56.1