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

super_1_load() copies dev_number to rdev->desc_nr without checking it
against the dev_roles array described by max_dev. Assembly normally catches
this later in super_1_validate(), but an array configured through sysfs can
reach super_1_sync() without that validation and index past dev_roles.

Normalize an invalid descriptor number when the superblock is loaded. The
normal rdev binding path will then assign a valid free descriptor number.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.

A crafted v1 component advertises dev_number 65536 with a much smaller
max_dev. Creating an array through the md sysfs interface binds that
component without calling super_1_validate(). Updating its state then
calls super_1_sync(), which writes through dev_roles[rdev->desc_nr].
Loop-device and md sysfs setup require root in the initial namespace.

The decoded trace is:

  BUG: KASAN: slab-out-of-bounds in super_1_sync
  Write of size 2
  super_1_sync (drivers/md/md.c:2353)
  md_update_sb (drivers/md/md.c:2522 drivers/md/md.c:2764
                drivers/md/md.c:2940)
  state_store (kernel/power/main.c:1052)
  rdev_attr_store (drivers/md/md.c:3782)
  kernfs_fop_write_iter (fs/kernfs/file.c:345)

The reproducer was tested on v7.4-rc5. The patch was also rebased onto
md commit c526b7cd32f7.

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

diff --git a/drivers/md/md.c b/drivers/md/md.c
index c71c3b043496..172bc75fbff7 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1903,6 +1903,9 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
 		return -EINVAL;
 
 	rdev->desc_nr = le32_to_cpu(sb->dev_number);
+	if (rdev->desc_nr < 0 ||
+	    rdev->desc_nr >= le32_to_cpu(sb->max_dev))
+		rdev->desc_nr = -1;
 
 	if (!rdev->bb_page) {
 		rdev->bb_page = alloc_page(GFP_KERNEL);
-- 
2.43.0


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

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

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

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