Linux RAID subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwoncho18@gmail.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH] md: reject inconsistent reshape state during assembly
Date: Thu, 03 Dec 2026 18:52:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-248433@kernel.org> (raw)
In-Reply-To: <179631974158.3729010.8619704387637000613@gmail.com>

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

      reply	other threads:[~2026-12-03 18:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 18:26 [PATCH] md: reject inconsistent reshape state during assembly Kyuwon Cho
2026-12-03 18:52 ` 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-248433@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