* [PATCH] md: reject inconsistent reshape state during assembly
@ 2026-12-03 18:26 Kyuwon Cho
2026-12-03 18:52 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 18:26 UTC (permalink / raw)
To: Song Liu, Yu Kuai; +Cc: Li Nan, Xiao Ni, NeilBrown, linux-raid, linux-kernel
slot_store() permits a slot below raid_disks + delta_disks while a
reshape prepares additional slots. The v0.90 and v1.x validators can
copy a nonzero delta_disks from a superblock whose reshape_position is
MaxSector. The stale delta lets slot_store() pass an out-of-range slot
to a personality whose table was allocated for raid_disks only.
KASAN reports:
BUG: KASAN: slab-out-of-bounds in raid10_add_disk (drivers/md/raid10.c:2106)
Call Trace:
raid10_add_disk (drivers/md/raid10.c:2106)
slot_store (drivers/md/md.c:3370)
rdev_attr_store (drivers/md/md.c:3788)
Reject the array in analyze_sbs() when no reshape is in progress but
any reshape geometry differs. This catches both metadata formats in
their common assembly path, before a personality allocates its runtime
geometry.
Fixes: ba1b41b6b4e3 ("md: range check slot number when manually adding a spare.")
Closes: https://lore.kernel.org/linux-raid/179489219553.3099317.5403557298223708081@gmail.com/
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
The bug was found with an LLM-guided test generator. The original report is at https://lore.kernel.org/linux-raid/179489219553.3099317.5403557298223708081@gmail.com/. A reproducer is available on request.
---
drivers/md/md.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index c71c3b043496..1cf2cfdd8643 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3943,6 +3943,14 @@ static int analyze_sbs(struct mddev *mddev)
super_types[mddev->major_version].
validate_super(mddev, NULL/*freshest*/, freshest);
+ if (mddev->reshape_position == MaxSector &&
+ (mddev->level != mddev->new_level ||
+ mddev->layout != mddev->new_layout ||
+ mddev->chunk_sectors != mddev->new_chunk_sectors ||
+ mddev->delta_disks != 0)) {
+ pr_warn("md: %s: inconsistent reshape state\n", mdname(mddev));
+ return -EINVAL;
+ }
rdev_for_each_safe(rdev, tmp, mddev) {
if (mddev->max_disks &&
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] md: reject inconsistent reshape state during assembly
2026-12-03 18:26 [PATCH] md: reject inconsistent reshape state during assembly Kyuwon Cho
@ 2026-12-03 18:52 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 18:52 UTC (permalink / raw)
To: Kyuwon Cho; +Cc: linux-raid, yukuai
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] md: analyze_sbs() rejects valid RAID0 arrays after layout is
set to -1
- [High] md: analyze_sbs() leaves mddev dirty on error, letting retry
bypass check
- [Low] md: Fixes trailer cites ba1b41b6b4e3 instead of f67055780caa
--
commit 1147b5c6a5554cf79c98716d0222c0847e7320b2
Author: Kyuwon Cho <kyuwoncho18@gmail.com>
> md: reject inconsistent reshape state during assembly
>
> slot_store() permits a slot below raid_disks + delta_disks while a
> reshape prepares additional slots. The v0.90 and v1.x validators can
> copy a nonzero delta_disks from a superblock whose reshape_position is
> MaxSector. The stale delta lets slot_store() pass an out-of-range slot
> to a personality whose table was allocated for raid_disks only.
>
> KASAN reports:
>
> BUG: KASAN: slab-out-of-bounds in raid10_add_disk (drivers/md/raid10.c:2106)
> Call Trace:
> raid10_add_disk (drivers/md/raid10.c:2106)
> slot_store (drivers/md/md.c:3370)
> rdev_attr_store (drivers/md/md.c:3788)
>
> Reject the array in analyze_sbs() when no reshape is in progress but
> any reshape geometry differs. This catches both metadata formats in
> their common assembly path, before a personality allocates its runtime
> geometry.
>
> Fixes: ba1b41b6b4e3 ("md: range check slot number when manually adding a spare.")
> Closes: https://lore.kernel.org/linux-raid/179489219553.3099317.5403557298223708081@gmail.com/
> Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
[Severity: Low]
Should the Fixes tag cite commit f67055780caa ("[PATCH] md: Checkpoint and
allow restart of raid5 reshape") instead?
Commit ba1b41b6b4e3 ("md: range check slot number when manually adding a
spare.") only added an upper bound check in slot_store(), whereas the
unvalidated copying of reshape fields in super_90_validate() and
super_1_validate() was introduced by the earlier commit.
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 47da9edc1c606..b4ba5c8f1bf6d 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -3948,6 +3948,14 @@ static int analyze_sbs(struct mddev *mddev)
>
> super_types[mddev->major_version].
> validate_super(mddev, NULL/*freshest*/, freshest);
> + if (mddev->reshape_position == MaxSector &&
> + (mddev->level != mddev->new_level ||
> + mddev->layout != mddev->new_layout ||
> + mddev->chunk_sectors != mddev->new_chunk_sectors ||
> + mddev->delta_disks != 0)) {
[Severity: High]
Does this regression reject valid RAID0 arrays during assembly?
In super_90_validate(), the non-reshape branch copies mddev->layout into
mddev->new_layout and then overrides mddev->layout to -1 without updating
mddev->new_layout:
drivers/md/md.c:super_90_validate() {
...
mddev->new_layout = mddev->layout;
mddev->new_chunk_sectors = mddev->chunk_sectors;
}
if (mddev->level == 0)
mddev->layout = -1;
...
}
super_1_validate() does the same when MD_FEATURE_RAID0_LAYOUT is not set.
For a normal RAID0 superblock with layout 0, mddev->layout (-1) then
differs from mddev->new_layout (0), causing analyze_sbs() to fail with
-EINVAL.
> + pr_warn("md: %s: inconsistent reshape state\n", mdname(mddev));
> + return -EINVAL;
> + }
[Severity: High]
Can a second RUN_ARRAY ioctl bypass this check because validate_super()
already populated mddev->raid_disks?
Returning -EINVAL here leaves mddev->raid_disks and mddev->delta_disks set
to the values loaded from the superblock, and neither md_run() nor
do_md_run() resets mddev on error.
On a retry, md_run() sees mddev->raid_disks != 0 and skips analyze_sbs(),
starting the array with the rejected delta_disks. slot_store() can then
still trigger the slab-out-of-bounds access in raid10_add_disk().
Resetting mddev on this error path, or validating the superblock before
mutating mddev, would prevent the retry bypass.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179631974158.3729010.8619704387637000613@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 18:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 18:26 [PATCH] md: reject inconsistent reshape state during assembly Kyuwon Cho
2026-12-03 18:52 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox