From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796415002; b=fWDvomwA1nUULnh3+ZleVZh7ZxDrYPpBBQTnHTL6CmzmlMq5wNrlTmP4Oc2N3TwsSB0E i1WvdxRQ8XtTLza/5+OFxcCnfVigi76J808y+AVSXzS+NyDA4D9amlheopmX1orZq2/nT lk8x9kUHYsuc35dZUvEmCuqUO4mM+ajT4ZxZe/OhonVm5tssMI+okv41BPAxwq/o69jNe QnOIuOiDg4JPu1FTYfLVDaowcL3+eEMX8bY2TRrWhhPlTOze5qPdslnuf44UgR324/Z6h fTOrN4qPcnKENZmu/XWQ/XDT86bqq4U1qfGXgjNbFNEqvuCNpNSKw3XjP1HXfzvknHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796415002; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8Q5kN8S1rpuwnntN7A1+8CNqhmMuzAStIq7meNL19Ag=; b=gPXmITEJGg2ZMFgFUoQpmsvy3M0I8pFrwLhxbS9cd4qZtMjusnzX+HCIRYQURKjqc6/A C0MeRgLSu4qHVNOB5B9aZg1qaxQ2QCFcqP/MFfBfKCQlMAoO1ObfZHU051ALKcNkWF6+2 c4fCNTK/8k22sDoeOcF92jF0cEcYXdbCRPSVJAmF2ki4IoMDASP1N4gUO9ZbTheHL6g3D WzwgTmaDs9oa8EgMXgr3I5URB73ulsjeQ+VkMhlu2z4ks22HirWqC1ZYDDZotln7+DKoq FE35XysmjuM0eg6Ho9kqKebTSn6GUvfSDnObm7pxGM1npupfJVwFpaDKAy14EwNS3bQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OZ0XsZWH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01FC6606A336 for ; Fri, 4 Dec 2026 20:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OZ0XsZWH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CDF71F0093B; Fri, 4 Dec 2026 20:10:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796415001; bh=8Q5kN8S1rpuwnntN7A1+8CNqhmMuzAStIq7meNL19Ag=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=OZ0XsZWHhF6XiE1qmiY92rbYFJfJqSxB3NF1rrTT+Vz5RHHGCUqhS5U8wKzoqXurz kRf4Gjwrz/lmE4hNE+kPY+gYsbn+ut05msOcg4DVmb81iOuZgJYkX5oSZYoHsn/a8+ kcloPzBogFxu1N499ufxkqbH+2vt5pXB+KnOPdRYpEPgj9sh8VsJ2D/VlP8Js2hi7I F85TzFG8fjBwojYHHJGgyJf6WedeA4Tm0EoUZ6V8/YDBG4ofzf4LOkQ+4cKQ+AgV2h HpyKE5OWe3+xhOOGjQ/ld+wYJQ3VLIBp5srJblrptcMHpC57SZomFdLxHDmDeEXzpI bHHgix+1LskUQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] md: reject inconsistent reshape state during assembly Reply-To: sashiko-reviews@lists.linux.dev To: "Kyuwon Cho" Cc: linux-raid@vger.kernel.org, yukuai@fygo.io In-Reply-To: <179637501342.1425433.17124866246346683813@gmail.com> References: <179637501342.1425433.17124866246346683813@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:10:01 +0000 X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] md: v1.x raid_disks =3D=3D 0 bypasses inactive_reshape_is_consistent() - [Low] md: inactive_reshape_is_consistent() misses v1.x flags and RAID0 new_layout - [Low] md: Fixes trailer cites ba1b41b6b4e3 instead of f67055780caa -- commit 500726eaee6390956b12674623d4a55c32568a00 Author: Kyuwon Cho > 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 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.540355729= 8223708081@gmail.com/ > Signed-off-by: Kyuwon Cho [Severity: Low] Does the Fixes tag point to the right commit? Commit ba1b41b6b4e3 ("md: range check slot number when manually adding a spare.") added the upper bound in slot_store()'s active-array path rather than widening it. Unvalidated v0.91/v1.x reshape loading came from f67055780caa ("[PATCH] md: Checkpoint and allow restart of raid5 reshape"): Fixes: f67055780caa ("[PATCH] md: Checkpoint and allow restart of raid5 r= eshape") > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 47da9edc1c606..c1e64a2aa15a8 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -3921,6 +3921,57 @@ static struct md_rdev *md_import_device(dev_t newd= ev, int super_format, int supe > * Check a full RAID array for plausibility > */ > =20 > +static bool inactive_reshape_is_consistent(struct mddev *mddev, > + struct md_rdev *rdev) > +{ [ ... ] > + if (mddev->major_version =3D=3D 1) { > + struct mdp_superblock_1 *sb =3D page_address(rdev->sb_page); > + u32 features =3D le32_to_cpu(sb->feature_map); > + > + if (!(features & MD_FEATURE_RESHAPE_ACTIVE) || > + le64_to_cpu(sb->reshape_position) !=3D (sector_t)-1) > + return true; > + > + level =3D le32_to_cpu(sb->level); > + layout =3D le32_to_cpu(sb->layout); > + new_level =3D le32_to_cpu(sb->new_level); > + new_layout =3D le32_to_cpu(sb->new_layout); > + if (!(features & MD_FEATURE_RAID0_LAYOUT)) { > + if (level =3D=3D 0) > + layout =3D -1; > + if (new_level =3D=3D 0) > + new_layout =3D -1; > + } > + > + return level =3D=3D new_level && > + layout =3D=3D new_layout && > + sb->chunksize =3D=3D sb->new_chunk && > + sb->delta_disks =3D=3D 0; > + } [Severity: Low] Can a v1.x superblock with MD_FEATURE_RESHAPE_ACTIVE and reshape_position =3D=3D MaxSector still leave inconsistent reshape state in mddev or rdev? This check misses MD_FEATURE_RESHAPE_BACKWARDS and MD_FEATURE_NEW_OFFSET with nonzero sb->new_offset. super_1_validate() then sets mddev->reshape_backwards =3D 1, and super_1_load() shifts rdev->new_data_offset, breaking later checks in update_raid_disks(). For implicit-layout RAID0 on v0.91 or v1.x without MD_FEATURE_RAID0_LAYOUT, canonicalizing new_layout to -1 accepts any sb->new_layout. However, super_90_validate() and super_1_validate() copy raw sb->new_layout into mddev->new_layout while resetting only mddev->layout to -1. [ ... ] > @@ -3946,6 +3997,11 @@ static int analyze_sbs(struct mddev *mddev) > return -EINVAL; > } > =20 > + 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); [Severity: Medium] Can a second v1.x member disk bypass inactive_reshape_is_consistent() when freshest has sb->raid_disks =3D=3D 0? Unlike super_90_load(), super_1_load() does not reject sb->raid_disks =3D= =3D 0 and only compares set_uuid, level, layout, and chunksize across members. If freshest has raid_disks =3D=3D 0 without MD_FEATURE_RESHAPE_ACTIVE, super_1_validate() leaves mddev->raid_disks =3D=3D 0. The rdev_for_each_safe loop then passes the next rdev to super_1_validate(), which re-enters its mddev->raid_disks =3D=3D 0 branch and commits that disk= 's unchecked reshape_position =3D=3D MaxSector and nonzero delta_disks, allowi= ng slot_store() to trigger the same slab-out-of-bounds in raid10_add_disk(). Hardcoding mddev->major_version checks in analyze_sbs() also bypasses super_types[]. Moving the check into super_90_validate() and super_1_validate() (and rejecting sb->raid_disks =3D=3D 0 in super_1_load()) would fix both. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179637501342.142543= 3.17124866246346683813@gmail.com?part=3D1