md: drop a never-started reshape request when stopping the array
syzbot
syzbotWriting raid_disks, layout, or chunk_size on a running array records a reshape request in struct mddev without starting the reshape until sync_action is set to "reshape". Because super_90_sync() and super_1_sync() only write reshape metadata to the superblock when reshape_position != MaxSector, a never-started reshape exists purely in memory. Dropping the request when the array is stopped matches the state that would be loaded on disk reassembly.
A minimal reproduction sequence is:
echo 4 > /sys/block/md0/md/raid_disks
echo inactive > /sys/block/md0/md/array_state
echo active > /sys/block/md0/md/array_state
Modifying layout or chunk_size behaves similarly. When restarting the array, raid5_run() previously assumed no reshape was taking place because reshape_position was MaxSector and triggered a kernel BUG due to delta_disks != 0:
kernel BUG at drivers/md/raid5.c:8117!
Oops: invalid opcode: 0000 [#1] SMP RIP: 0010:raid5_run+0x2550/0x2560 drivers/md/raid5.c:8117 Call Trace: <TASK> md_run+0xc3d/0x1cd0 drivers/md/md.c:6779 do_md_run+0x35/0x720 drivers/md/md.c:6880 array_state_store+0x958/0xe90 md_attr_store+0x3b7/0x640 drivers/md/md.c:6158 kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345 vfs_write+0x612/0xba0 fs/read_write.c:687 ksys_write+0x150/0x270 fs/read_write.c:739 do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
Commit 0669c7dbd1d3 replaced the BUG_ON in raid5_run() with an -EINVAL check, but the underlying issue remained: raid5 fails to restart with -EINVAL, and raid10 silently returns incorrect data due to unchecked new_layout and new_chunk_sectors in setup_conf().
Drop the never-started reshape request in __md_stop() if no reshape is currently running (mddev->reshape_position == MaxSector). Reset delta_disks and reshape_backwards to 0, restore new_level, new_layout, and new_chunk_sectors to level, layout, and chunk_sectors, and reset each rdev's new_data_offset to data_offset. If a reshape is actively in progress (mddev->reshape_position != MaxSector), the parameters are preserved so the reshape can resume when the array is restarted.
To: <[email protected]>
To: "Song Liu" <[email protected]>
To: "Yu Kuai" <[email protected]>
To: "NeilBrown" <[email protected]>
Cc: <[email protected]>
Cc: "Li Nan" <[email protected]>
Cc: "Xiao Ni" <[email protected]>
---
v2:
- Reset rdev->new_data_offset to rdev->data_offset for all member devices.
- Add an explanatory comment in __md_stop().
- Update commit subject and description per reviewer feedback.
v1:
https://lore.kernel.org/all/[email protected]/T/
---
drivers/md/md.c +16 -0
@@ -7084,6 +7084,7 @@ static void mddev_detach(struct mddev *mddev)static void __md_stop (struct mddev *mddev) {struct md_personality *pers = mddev->pers; +struct md_rdev *rdev;mddev_detach (mddev);md_bitmap_destroy (mddev);
@@ -7095,6 +7096,21 @@ static void __md_stop(struct mddev *mddev) mddev->private =NULL ;put_pers (pers);clear_bit (MD_RECOVERY_FROZEN , &mddev->recovery); + +/* +* A reshape requested on a running array exists only in memory before +* sync_action=reshape and should be dropped with the personality, while +* a started reshape (reshape_position != MaxSector) is preserved. +*/ +if (mddev->reshape_position == MaxSector) { + mddev->delta_disks =0 ; + mddev->reshape_backwards =0 ; + mddev->new_level = mddev->level; + mddev->new_layout = mddev->layout; + mddev->new_chunk_sectors = mddev->chunk_sectors; +rdev_for_each (rdev, mddev) + rdev->new_data_offset = rdev->data_offset; + } }void md_stop (struct mddev *mddev)
base-commit: df2908090cda368b01ff43709f51890076c56157
Signature · 9 lines
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to Sign-off the patch as a human author
and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at [email protected].Uladzislau Zhauniarovich
Tested-byThe v2 code is correct. Please keep the diff exactly as it is, including where struct md_rdev *rdev is declared and the shorter comment.
I tested v2 in QEMU with KASAN on a v7.2-rc5 based tree with 0669c7dbd1d3 applied:
- The reproducer: 2/2 clean. The array starts again with its old geometry (3/3 devices).
- The variants are all clean, and the array comes back each time:
raid_disks +1 without frozen, a pending layout change, a pending chunk_size change, shrink by 2 (data md5 unchanged), and a restart via readonly.
- raid10 near2 with a pending offset2 layout: after inactive -> active the data md5 is unchanged.
- new_level written while the array is inactive, and a crafted superblock with RESHAPE_ACTIVE and reshape_position ~0: both get -EINVAL from 0669c7dbd1d3, as expected.
- A grow from 3 to 4 disks completes with the data intact.
- A reshape parked at reshape_position 49152, then inactive -> active, resumes at 49152 and finishes with the data intact.
Please send a v3 that changes only the commit message and the recipients:
1) Fix the commit reference. checkpatch reports an ERROR for "Commit 0669c7dbd1d3 replaced ...". Write it as:
Commit 0669c7dbd1d3 ("md/raid5: don't BUG() on an inconsistent reshape state from the superblock") replaced the BUG_ON in raid5_run() with an -EINVAL check, ...
2) Replace the stack trace with the one from the syzbot report. The current one is the v1 trace, and array_state_store has no file:line in it:
kernel BUG at drivers/md/raid5.c:8117!
RIP: 0010:raid5_run+0x11a7/0x1670 drivers/md/raid5.c:8117
Call Trace:
md_run+0xc2f/0x2510 drivers/md/md.c:6779
do_md_run+0x36/0x660 drivers/md/md.c:6880
array_state_store+0x9c5/0xcf0 drivers/md/md.c:47653) Add the starting state as the first line of the reproduction sequence:
# raid5 running on 3 devices
echo 4 > /sys/block/md0/md/raid_disks
echo inactive > /sys/block/md0/md/array_state
echo active > /sys/block/md0/md/array_state4) Add this tag after the Fixes: line:
0669c7dbd1d3 has a Fixes: tag and will be backported. Without this patch, stable arrays that hit this sequence will then fail to restart.
5) Add Yogesh Gaur <[email protected]>, the author of 0669c7dbd1d3, to Cc.
Keep everything else as it is: the subject, Fixes:, Reported-by:,
Closes: and the rest of the text. v3 should have the same diff as v2.
Quoted 107 lines · syzbot
Writing
raid_disks, layout, orchunk_sizeon a running array records a reshape request in struct mddev without starting the reshape untilsync_actionis set to "reshape". Becausesuper_90_sync()andsuper_1_sync()only write reshape metadata to the superblock whenreshape_position!= MaxSector, a never-started reshape exists purely in memory. Dropping the request when the array is stopped matches the state that would be loaded on disk reassembly.A minimal reproduction sequence is:
echo 4 >
/sys/block/md0/md/raid_disks
echo inactive >/sys/block/md0/md/array_state
echo active >/sys/block/md0/md/array_stateModifying layout or
chunk_sizebehaves similarly. When restarting the array,raid5_run()previously assumed no reshape was taking place becausereshape_positionwas MaxSector and triggered a kernel BUG due todelta_disks!= 0:kernel BUG at
drivers/md/raid5.c:8117!Oops: invalid opcode: 0000 [#1] SMP RIP: 0010:raid5_run+0x2550/0x2560 drivers/md/raid5.c:8117 Call Trace: <TASK> md_run+0xc3d/0x1cd0 drivers/md/md.c:6779 do_md_run+0x35/0x720 drivers/md/md.c:6880 array_state_store+0x958/0xe90 md_attr_store+0x3b7/0x640 drivers/md/md.c:6158 kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345 vfs_write+0x612/0xba0 fs/read_write.c:687 ksys_write+0x150/0x270 fs/read_write.c:739 do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>Commit
0669c7dbd1d3replaced theBUG_ONinraid5_run()with an-EINVALcheck, but the underlying issue remained: raid5 fails to restart with-EINVAL, and raid10 silently returns incorrect data due to uncheckednew_layoutandnew_chunk_sectorsinsetup_conf().Drop the never-started reshape request in
__md_stop()if no reshape is currently running (mddev->reshape_position== MaxSector). Resetdelta_disksandreshape_backwardsto 0, restorenew_level,new_layout, andnew_chunk_sectorsto level, layout, andchunk_sectors, and reset each rdev'snew_data_offsettodata_offset. If a reshape is actively in progress (mddev->reshape_position!= MaxSector), the parameters are preserved so the reshape can resume when the array is restarted.Fixes 9e653b6342c9 ("[PATCH] md: Set/get state of array via sysfs")Assisted-by Gemini:gemini-4-argon Gemini:gemini-3.8-flash syzbotReported-by [email protected]To: <[email protected]>
To: "Song Liu" <[email protected]>
To: "Yu Kuai" <[email protected]>
To: "NeilBrown" <[email protected]>
Cc: <[email protected]>
Cc: "Li Nan" <[email protected]>
Cc: "Xiao Ni" <[email protected]>---
v2:
- Resetrdev->new_data_offsettordev->data_offsetfor all member devices.
- Add an explanatory comment in__md_stop().
- Update commit subject and description per reviewer feedback.v1:
https://lore.kernel.org/all/[email protected]/T/
---drivers/md/md.c +16
-0@@ -7084,6 +7084,7 @@ static void mddev_detach(struct mddev *mddev)static void __md_stop (struct mddev *mddev) {struct md_personality *pers = mddev->pers; +struct md_rdev *rdev;mddev_detach (mddev);md_bitmap_destroy (mddev);@@ -7095,6 +7096,21 @@ static void __md_stop(struct mddev *mddev) mddev->private =NULL ;put_pers (pers);clear_bit (MD_RECOVERY_FROZEN , &mddev->recovery); + +/* +* A reshape requested on a running array exists only in memory before +* sync_action=reshape and should be dropped with the personality, while +* a started reshape (reshape_position != MaxSector) is preserved. +*/ +if (mddev->reshape_position == MaxSector) { + mddev->delta_disks =0 ; + mddev->reshape_backwards =0 ; + mddev->new_level = mddev->level; + mddev->new_layout = mddev->layout; + mddev->new_chunk_sectors = mddev->chunk_sectors; +rdev_for_each (rdev, mddev) + rdev->new_data_offset = rdev->data_offset; + } }void md_stop (struct mddev *mddev)base-commit:
df2908090cda368b01ff43709f51890076c56157
syzbot
syzbotCould not add tag 'Cc: [email protected]': only the following tags are supported: Reviewed-by, Acked-by, Tested-by, Reported-by, Suggested-by.
Quoted 3 lines
4) Add this tag after the Fixes: line:
Could not add tag 'Cc: [email protected]': only the following tags are supported: Reviewed-by, Acked-by, Tested-by, Reported-by, Suggested-by.
Added [email protected] to Cc.
Signature · 3 lines
This reply was generated by an AI model. See https://goo.gle/syzbot-ai-patches for information about AI-generated patches. syzbot engineers can be reached at [email protected].