From: Kyuwon Cho <kyuwoncho18@gmail.com>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>
Cc: Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
NeilBrown <neil@brown.name>,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] md: reject inconsistent reshape state during assembly
Date: Sat, 5 Dec 2026 04:51:20 +0900 [thread overview]
Message-ID: <179637501342.1425433.17124866246346683813@gmail.com> (raw)
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>
---
Changes in v2:
- Validate the raw superblock before committing its geometry to mddev, so a
failed RUN_ARRAY retry cannot skip the check.
- Canonicalize an implicit RAID0 layout to -1 on both sides of the comparison.
- Keep Fixes: ba1b41b6b4e3 because that commit made stale delta_disks expand
slot_store()'s accepted index range. These changes address the Sashiko AI
review:
https://lore.kernel.org/all/sashiko-outbox-248433@kernel.org/
v1: https://lore.kernel.org/all/179631974158.3729010.8619704387637000613@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 | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index c71c3b043496..519695040e6c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3916,6 +3916,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)
+{
+ int level, layout, new_level, new_layout;
+
+ if (mddev->major_version == 0) {
+ mdp_super_t *sb = page_address(rdev->sb_page);
+
+ if (sb->minor_version < 91 ||
+ sb->reshape_position != (sector_t)-1)
+ return true;
+
+ level = sb->level;
+ layout = level == 0 ? -1 : sb->layout;
+ new_level = sb->new_level;
+ new_layout = new_level == 0 ? -1 : sb->new_layout;
+
+ return level == new_level &&
+ layout == new_layout &&
+ sb->chunk_size == sb->new_chunk &&
+ sb->delta_disks == 0;
+ }
+
+ 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;
+ }
+
+ return true;
+}
+
static int analyze_sbs(struct mddev *mddev)
{
struct md_rdev *rdev, *freshest, *tmp;
@@ -3941,6 +3992,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);
next reply other threads:[~2026-12-04 19:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 19:51 Kyuwon Cho [this message]
2026-12-04 20:10 ` [PATCH v2] md: reject inconsistent reshape state during assembly sashiko-bot
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=179637501342.1425433.17124866246346683813@gmail.com \
--to=kyuwoncho18@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=neil@brown.name \
--cc=song@kernel.org \
--cc=xiao@kernel.org \
--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