Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] md: validate v1 dev_number while loading superblock
@ 2026-12-03 19:50 Kyuwon Cho
  2026-12-03 20:12 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 19:50 UTC (permalink / raw)
  To: Song Liu
  Cc: Yu Kuai, Li Nan, Xiao Ni, sashiko-reviews, linux-raid,
	linux-kernel

super_1_load() copies the v1 dev_number into rdev->desc_nr without checking
that the descriptor exists in dev_roles. A sysfs-configured array can reach
super_1_sync() without super_1_validate() and index beyond the role array.

Reject an out-of-range descriptor before publishing it in the rdev. This
also avoids treating a normalized negative descriptor as a spare and later
indexing dev_roles[-1].

Fixes: 31b65a0d3894 ("[PATCH] md: set desc_nr correctly for version-1 superblocks")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
Changes in v2:
- Reject an invalid dev_number before assigning rdev->desc_nr instead of
  normalizing it after publication, as suggested by the Sashiko review.
- Correct the Fixes tag to the commit that moved desc_nr assignment into
  super_1_load().

v1: https://lore.kernel.org/all/179621082761.2397410.3913367575512805215@skku.edu/

The issue was found by an LLM-guided test generator that we are
developing as a research prototype.

A reproducer is available on request.

 drivers/md/md.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index c71c3b043496..fe97ae811bc8 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1902,8 +1902,10 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
 	    && rdev->new_data_offset < sb_start + (rdev->sb_size/512))
 		return -EINVAL;
 
-	rdev->desc_nr = le32_to_cpu(sb->dev_number);
+	if (le32_to_cpu(sb->dev_number) >= le32_to_cpu(sb->max_dev))
+		return -EINVAL;
 
+	rdev->desc_nr = le32_to_cpu(sb->dev_number);
 	if (!rdev->bb_page) {
 		rdev->bb_page = alloc_page(GFP_KERNEL);
 		if (!rdev->bb_page)
-- 
2.43.0


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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 19:50 [PATCH v2] md: validate v1 dev_number while loading superblock Kyuwon Cho
2026-12-03 20:12 ` sashiko-bot

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