mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] md: reject inconsistent reshape state during assembly
@ 2026-12-03 18:26 Kyuwon Cho
  0 siblings, 0 replies; only message 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	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 18:26 UTC | newest]

Thread overview: (only message) (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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®