All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] md: reject inconsistent reshape state during assembly
@ 2026-12-06  4:46 Kyuwon Cho
  2026-12-06  5:03 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-06  4:46 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)

Validate each metadata format's raw reshape state while loading the
superblock, before it can be copied into rdev or mddev. Reject zero-disk
v1.x metadata and inactive reshape state that carries changed geometry,
direction, or data-offset fields.

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 v3:
- Validate inactive reshape state in each format's load path, reject zero
  raid_disks and stale NEW_OFFSET/RESHAPE_BACKWARDS flags in v1.x, and
  compare the raw new_layout that super_1_validate() copies.
- Keep Fixes: ba1b41b6b4e3: the suggested f67055780caa introduced reshape
  loading, but ba1b41b6b4e3 made stale delta_disks admit the out-of-range
  slot involved in this OOB. These changes address the Sashiko AI review:
  https://lore.kernel.org/all/sashiko-outbox-250602@kernel.org/

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/

v2: https://lore.kernel.org/all/179637501342.1425433.17124866246346683813@gmail.com/
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 | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index c71c3b043496..076992ec8fc5 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1415,6 +1415,13 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
 		goto abort;
 	}
 
+	if (sb->minor_version >= 91 && sb->reshape_position == MaxSector &&
+	    (sb->delta_disks != 0 || sb->new_level != sb->level ||
+	     sb->new_layout != sb->layout || sb->new_chunk != sb->chunk_size)) {
+		pr_warn("md: inconsistent reshape state on %pg\n", rdev->bdev);
+		goto abort;
+	}
+
 	rdev->preferred_minor = sb->md_minor;
 	rdev->data_offset = 0;
 	rdev->new_data_offset = 0;
@@ -1817,6 +1824,7 @@ static __le32 calc_sb_1_csum(struct mdp_superblock_1 *sb)
 static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_version)
 {
 	struct mdp_superblock_1 *sb;
+	u32 features;
 	int ret;
 	sector_t sb_start;
 	sector_t sectors;
@@ -1867,6 +1875,21 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
 			rdev->bdev);
 		return -EINVAL;
 	}
+
+	features = le32_to_cpu(sb->feature_map);
+	if (!le32_to_cpu(sb->raid_disks))
+		return -EINVAL;
+
+	if ((features & MD_FEATURE_RESHAPE_ACTIVE) &&
+	    le64_to_cpu(sb->reshape_position) == MaxSector &&
+	    (le32_to_cpu(sb->delta_disks) != 0 ||
+	     sb->new_level != sb->level || sb->new_layout != sb->layout ||
+	     sb->new_chunk != sb->chunksize ||
+	     (features & (MD_FEATURE_NEW_OFFSET |
+			  MD_FEATURE_RESHAPE_BACKWARDS)))) {
+		pr_warn("md: inconsistent reshape state on %pg\n", rdev->bdev);
+		return -EINVAL;
+	}
 	if (le64_to_cpu(sb->data_size) < 10) {
 		pr_warn("md: data_size too small on %pg\n",
 			rdev->bdev);
@@ -3915,7 +3938,6 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
 /*
  * Check a full RAID array for plausibility
  */
-
 static int analyze_sbs(struct mddev *mddev)
 {
 	struct md_rdev *rdev, *freshest, *tmp;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] md: reject inconsistent reshape state during assembly
  2026-12-06  4:46 [PATCH v3] md: reject inconsistent reshape state during assembly Kyuwon Cho
@ 2026-12-06  5:03 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-06  5:03 UTC (permalink / raw)
  To: Kyuwon Cho; +Cc: linux-raid, yukuai

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] md: Fixes trailer cites ba1b41b6b4e3 instead of f67055780caa
--

commit d43e112cbe49427a0afdd161f5effdf4bbe6470e
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 each metadata format's raw reshape state while loading the
> superblock, before it can be copied into rdev or mddev. Reject zero-disk
> v1.x metadata and inactive reshape state that carries changed geometry,
> direction, or data-offset fields.
>
> 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 f67055780caa ("[PATCH] md: Checkpoint and allow
restart of raid5 reshape") instead of ba1b41b6b4e3 ("md: range check slot
number when manually adding a spare.")?

Before that commit, the active-array branch of slot_store() calling
pers->hot_add_disk() -> raid10_add_disk() had no upper-bound check on slot
at all.  It narrowed the active-array range and only relaxed the check in
the inactive-array branch, which does not call hot_add_disk().

This patch does not touch slot_store(); it validates inactive reshape
metadata in super_90_load() and super_1_load() before super_90_validate()
and super_1_validate() copy it, which is behavior introduced by
f67055780caa ("[PATCH] md: Checkpoint and allow restart of raid5 reshape").

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179643369147.1996725.14454060339934285854@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-06  5:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  4:46 [PATCH v3] md: reject inconsistent reshape state during assembly Kyuwon Cho
2026-12-06  5:03 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.