md: skip superblock validation for nonpersistent arrays
PATCH 1/1 md: skip superblock validation for nonpersistent arrays
Hi,
syzbot reported a KASAN slab-out-of-bounds read in super_90_validate() when adding a journal device to a nonpersistent 0.90-style RAID1 array.
The reproducer creates a nonpersistent RAID1 array with 35 raid slots and then hot-adds a journal device. Nonpersistent arrays do not load an on-disk superblock for the new device, but add_bound_rdev() still calls validate_super() in the journal path.
For 0.90 metadata, super_90_validate() indexes sb->disks using rdev->desc_nr. With 35 raid slots, this index can exceed the 27 descriptors available in the 0.90 superblock, resulting in an out-of-bounds read even though there is no persistent superblock to validate.
Skip validate_super() for nonpersistent arrays, while retaining hot_add_disk() for both persistent and nonpersistent arrays.
Testing:
- The original syzbot C reproducer triggered KASAN in the baseline kernel in 4 of 5 clean runs.
- The patched kernel completed the same reproducer successfully in 3 of 3 runs without KASAN, BUG, Oops, or kernel panic.
- Both baseline and patched kernels were built with KASAN, CONFIG_MD_RAID0, CONFIG_MD_RAID1, CONFIG_MD_RAID10, CONFIG_MD_RAID456, CONFIG_MD_LINEAR, and DEBUG_LIST enabled.
- mdadm tests 00raid1, 02r1add, 20raid5journal, and 24raid456deadlock passed with the patched kernel.
- A baseline-versus-patched run of the remaining targeted mdadm tests produced identical results: 4 passed, 10 failed, and 1 skipped on each kernel. The common failures are in persistent 0.90 byte-order handling and external DDF tests; no KASAN, Oops, BUG, or panic was observed.
- 24raid10deadlock passed with CONFIG_FAULT_INJECTION, CONFIG_FAIL_MAKE_REQUEST, and CONFIG_FAULT_INJECTION_DEBUG_FS enabled.
--- drivers/md/md.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/md/md.c +3 -2
@@ -2992,8 +2992,9 @@ static int add_bound_rdev(struct md_rdev *rdev)* then added disks for geometry changes, * and should be added immediately. */ - super_types[mddev->major_version]. -validate_super (mddev,NULL /*freshest*/ , rdev); +/* Nonpersistent arrays have no on-disk superblock to validate. */ +if (mddev->persistent) + super_types[mddev->major_version].validate_super (mddev,NULL , rdev); err = mddev->pers->hot_add_disk (mddev, rdev);if (err) {md_kick_rdev_from_array (rdev);
Signature · 1 line
2.43.0