mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shuai Liu <847807867@qq.com>
To: linux-raid@vger.kernel.org
Cc: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com,
	xiao@kernel.org, linux-kernel@vger.kernel.org,
	syzbot+c5969d7e0a934b384fd6@syzkaller.appspotmail.com,
	847807867@qq.com
Subject: [PATCH] md: reject out-of-bounds desc_nr in super_90_validate()
Date: Mon, 16 Nov 2026 16:32:41 +0800	[thread overview]
Message-ID: <tencent_3583131EEE6BD2102C15F21A4DEEB86A6208@qq.com> (raw)
In-Reply-To: <6afa2ce8.920b2b3a.148c65.0040.GAE@google.com>

super_90_validate() indexes the on-disk disk descriptor array with
rdev->desc_nr without any bounds check:

	desc = sb->disks + rdev->desc_nr;
	if (desc->state & (1<<MD_DISK_FAULTY))
		...

mdp_super_t carries only MD_SB_DISKS (27) descriptors of 128 bytes
each starting at offset 512, so any desc_nr outside [0, MD_SB_DISKS)
reads past the end of the 4KB superblock page.

Such an out-of-range desc_nr is reachable in several ways:

1. On a running non-persistent array, ADD_NEW_DISK with the
   MD_DISK_JOURNAL flag reaches add_bound_rdev(), which calls
   validate_super() unconditionally for journal disks.
   bind_rdev_to_array() auto-assigns desc_nr = mddev->raid_disks to
   a new rdev, and its max_disks check is skipped both for journal
   disks and when mddev->max_disks == 0 (the case for non-persistent
   arrays, which never set it).  With raid_disks > MD_SB_DISKS the
   assigned desc_nr points past the descriptor array.

2. During assembly, rdev->desc_nr comes straight from the on-disk
   sb->this_disk.number, which is fully attacker-controlled fuzz
   input.

syzbot hit path 1: a RAID1 array with raid_disks=35 and
not_persistent=1 plus a hot-added journal disk made
super_90_validate() read sb->disks[35].state at byte offset
512 + 35 * 128 + 16 = 5008, i.e. 912 bytes into the page following
the 4096-byte superblock page:

	BUG: KASAN: use-after-free in super_90_validate+0x178b/0x18c0 drivers/md/md.c:1592
	Read of size 4 at addr ffff888073d36390 by task syz-executor291/6009
	 ...
	 super_90_validate+0x178b/0x18c0 drivers/md/md.c:1592
	 add_bound_rdev+0x274/0x390 drivers/md/md.c:3012
	 md_add_new_disk+0xca1/0x1820 drivers/md/md.c:7666
	 md_ioctl+0x2c1d/0x3700 drivers/md/md.c:8525
	 blkdev_ioctl+0x5ad/0x6f0 block/ioctl.c:798

(The KASAN report shows use-after-free or slab-out-of-bounds
depending on what occupies the neighbouring memory.)

super_1_validate() already bounds desc_nr against sb->max_dev; the
0.90 metadata path has no equivalent check.  Reject desc_nr outside
[0, MD_SB_DISKS) with -EINVAL, which covers both the desc->state
reads in super_90_validate() itself and keeps fuzzed on-disk
sb->this_disk.number values from being used as an array index.

Note that super_90_sync() also writes sb->disks[] indexed by
desc_nr; on a persistent array a journal disk can still bypass the
bind_rdev_to_array() max_disks check and reach that write.  Reaching
it additionally requires a crafted on-disk superblock, so it is left
for follow-up discussion.

Verified with the syzbot reproducer under QEMU with KASAN (7.4-rc3
based config): baseline reproduces the use-after-free on every run,
with this patch the reproducer completes with zero KASAN reports
across repeated runs.

Reported-by: syzbot+c5969d7e0a934b384fd6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c5969d7e0a934b384fd6
Signed-off-by: Shuai Liu <847807867@qq.com>
---
 drivers/md/md.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 03e35386a8028..83009b0d84092 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1495,6 +1495,9 @@ static int super_90_validate(struct mddev *mddev, struct md_rdev *freshest, stru
 	mdp_super_t *sb = page_address(rdev->sb_page);
 	__u64 ev1 = md_event(sb);
 
+	if (rdev->desc_nr < 0 || rdev->desc_nr >= MD_SB_DISKS)
+		return -EINVAL;
+
 	rdev->raid_disk = -1;
 	clear_bit(Faulty, &rdev->flags);
 	clear_bit(In_sync, &rdev->flags);
-- 
2.43.0


      reply	other threads:[~2026-11-16  8:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 22:06 [syzbot] [raid?] KASAN: slab-out-of-bounds Read in super_90_validate syzbot
2026-11-16  8:32 ` Shuai Liu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_3583131EEE6BD2102C15F21A4DEEB86A6208@qq.com \
    --to=847807867@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=song@kernel.org \
    --cc=syzbot+c5969d7e0a934b384fd6@syzkaller.appspotmail.com \
    --cc=xiao@kernel.org \
    --cc=yukuai@fygo.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®