[PATCH] md: reject inconsistent reshape state during assembly
From: Kyuwon Cho
Date: Thu Dec 03 2026 - 13:26:35 EST
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@xxxxxxxxx/
Signed-off-by: Kyuwon Cho <kyuwoncho18@xxxxxxxxx>
---
The bug was found with an LLM-guided test generator. The original report is at https://lore.kernel.org/linux-raid/179489219553.3099317.5403557298223708081@xxxxxxxxx/. 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 &&