From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwoncho18@gmail.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH v2] md: reject inconsistent reshape state during assembly
Date: Fri, 04 Dec 2026 20:10:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-250602@kernel.org> (raw)
In-Reply-To: <179637501342.1425433.17124866246346683813@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] md: v1.x raid_disks == 0 bypasses
inactive_reshape_is_consistent()
- [Low] md: inactive_reshape_is_consistent() misses v1.x flags and RAID0
new_layout
- [Low] md: Fixes trailer cites ba1b41b6b4e3 instead of f67055780caa
--
commit 500726eaee6390956b12674623d4a55c32568a00
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)
>
> Validate the freshest superblock's raw reshape tuple before
> validate_super() commits it to mddev. This makes a failed RUN_ARRAY retry
> metadata again. Treat an implicit RAID0 layout as the canonical -1 on both
> sides of the comparison so ordinary RAID0 arrays remain valid.
>
> 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]
Does the Fixes tag point to the right commit?
Commit ba1b41b6b4e3 ("md: range check slot number when manually adding a
spare.") added the upper bound in slot_store()'s active-array path rather
than widening it. Unvalidated v0.91/v1.x reshape loading came from
f67055780caa ("[PATCH] md: Checkpoint and allow restart of raid5 reshape"):
Fixes: f67055780caa ("[PATCH] md: Checkpoint and allow restart of raid5 reshape")
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 47da9edc1c606..c1e64a2aa15a8 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -3921,6 +3921,57 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
> * Check a full RAID array for plausibility
> */
>
> +static bool inactive_reshape_is_consistent(struct mddev *mddev,
> + struct md_rdev *rdev)
> +{
[ ... ]
> + if (mddev->major_version == 1) {
> + struct mdp_superblock_1 *sb = page_address(rdev->sb_page);
> + u32 features = le32_to_cpu(sb->feature_map);
> +
> + if (!(features & MD_FEATURE_RESHAPE_ACTIVE) ||
> + le64_to_cpu(sb->reshape_position) != (sector_t)-1)
> + return true;
> +
> + level = le32_to_cpu(sb->level);
> + layout = le32_to_cpu(sb->layout);
> + new_level = le32_to_cpu(sb->new_level);
> + new_layout = le32_to_cpu(sb->new_layout);
> + if (!(features & MD_FEATURE_RAID0_LAYOUT)) {
> + if (level == 0)
> + layout = -1;
> + if (new_level == 0)
> + new_layout = -1;
> + }
> +
> + return level == new_level &&
> + layout == new_layout &&
> + sb->chunksize == sb->new_chunk &&
> + sb->delta_disks == 0;
> + }
[Severity: Low]
Can a v1.x superblock with MD_FEATURE_RESHAPE_ACTIVE and reshape_position
== MaxSector still leave inconsistent reshape state in mddev or rdev?
This check misses MD_FEATURE_RESHAPE_BACKWARDS and MD_FEATURE_NEW_OFFSET
with nonzero sb->new_offset. super_1_validate() then sets
mddev->reshape_backwards = 1, and super_1_load() shifts
rdev->new_data_offset, breaking later checks in update_raid_disks().
For implicit-layout RAID0 on v0.91 or v1.x without MD_FEATURE_RAID0_LAYOUT,
canonicalizing new_layout to -1 accepts any sb->new_layout. However,
super_90_validate() and super_1_validate() copy raw sb->new_layout into
mddev->new_layout while resetting only mddev->layout to -1.
[ ... ]
> @@ -3946,6 +3997,11 @@ static int analyze_sbs(struct mddev *mddev)
> return -EINVAL;
> }
>
> + if (!inactive_reshape_is_consistent(mddev, freshest)) {
> + pr_warn("md: %s: inconsistent reshape state\n", mdname(mddev));
> + return -EINVAL;
> + }
> +
> super_types[mddev->major_version].
> validate_super(mddev, NULL/*freshest*/, freshest);
[Severity: Medium]
Can a second v1.x member disk bypass inactive_reshape_is_consistent() when
freshest has sb->raid_disks == 0?
Unlike super_90_load(), super_1_load() does not reject sb->raid_disks == 0
and only compares set_uuid, level, layout, and chunksize across members.
If freshest has raid_disks == 0 without MD_FEATURE_RESHAPE_ACTIVE,
super_1_validate() leaves mddev->raid_disks == 0.
The rdev_for_each_safe loop then passes the next rdev to super_1_validate(),
which re-enters its mddev->raid_disks == 0 branch and commits that disk's
unchecked reshape_position == MaxSector and nonzero delta_disks, allowing
slot_store() to trigger the same slab-out-of-bounds in raid10_add_disk().
Hardcoding mddev->major_version checks in analyze_sbs() also bypasses
super_types[]. Moving the check into super_90_validate() and
super_1_validate() (and rejecting sb->raid_disks == 0 in super_1_load())
would fix both.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179637501342.1425433.17124866246346683813@gmail.com?part=1
prev parent reply other threads:[~2026-12-04 20:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:51 [PATCH v2] md: reject inconsistent reshape state during assembly Kyuwon Cho
2026-12-04 20:10 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-250602@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kyuwoncho18@gmail.com \
--cc=linux-raid@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yukuai@fygo.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox