* Re: [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync
2026-09-13 13:09 [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
@ 2026-09-13 17:34 ` syzbot
2026-09-13 23:37 ` [PATCH] md: add max_disks bound check in older version Aaditya Kansal
2026-09-13 23:44 ` Aaditya Kansal
2026-09-14 3:52 ` Forwarded: [PATCH] md: validate raid_disks against MD_SB_DISKS in super_90_load syzbot
` (5 subsequent siblings)
6 siblings, 2 replies; 20+ messages in thread
From: syzbot @ 2026-09-13 17:34 UTC (permalink / raw)
To: linux-kernel, linux-raid, magiclinan, song, syzkaller-bugs, xiao,
yukuai, yukuai
syzbot has found a reproducer for the following issue on:
HEAD commit: 2f0c1cf72f46 Merge tag 's390-7.3-3' of git://git.kernel.or..
git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=14afd5f9580000
kernel config: https://syzkaller.appspot.com/x/.config?x=8c5c3949d762a91f
dashboard link: https://syzkaller.appspot.com/bug?extid=9e3014263a35700ab49b
compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=12afd5f9580000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
------------[ cut here ]------------
UBSAN: array-index-out-of-bounds in drivers/md/md.c:1697:17
index 124 is out of range for type 'mdp_disk_t [27]'
CPU: 1 UID: 0 PID: 6018 Comm: syz-executor186 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
ubsan_epilogue+0xa/0x30 lib/ubsan.c:233
__ubsan_handle_out_of_bounds+0xcc/0xf0 lib/ubsan.c:455
super_90_sync+0x1eed/0x1ff0 drivers/md/md.c:1697
sync_super drivers/md/md.c:2505 [inline]
sync_sbs drivers/md/md.c:2747 [inline]
md_update_sb+0xbba/0x2840 drivers/md/md.c:2923
state_store+0x31e/0x1340 drivers/md/md.c:3245
rdev_attr_store+0x1d9/0x560 drivers/md/md.c:3768
sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145
kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x6af/0x1050 fs/read_write.c:687
ksys_write+0x12a/0x250 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f84634ad6f7
Code: 48 89 fa 4c 89 df e8 98 1d 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007fff04c70ef0 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00005555934c5400 RCX: 00007f84634ad6f7
RDX: 0000000000000008 RSI: 00007f84634e9c12 RDI: 0000000000000003
RBP: 00007f84634e9c12 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 00007fff04c70fc0
R13: 00007f84634e9b5f R14: 00007fff04c710d0 R15: 0000000000000002
</TASK>
---[ end trace ]---
---
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
^ permalink raw reply [flat|nested] 20+ messages in thread* [PATCH] md: add max_disks bound check in older version
2026-09-13 17:34 ` syzbot
@ 2026-09-13 23:37 ` Aaditya Kansal
2026-09-13 23:37 ` syzbot
2026-09-13 23:51 ` sashiko-bot
2026-09-13 23:44 ` Aaditya Kansal
1 sibling, 2 replies; 20+ messages in thread
From: Aaditya Kansal @ 2026-09-13 23:37 UTC (permalink / raw)
To: syzbot+9e3014263a35700ab49b; +Cc: linux-raid, Aaditya Kansal
#syz test
syzbot reported array-index-out-of-bounds in super_90_sync()
UBSAN: array-index-out-of-bounds in drivers/md/md.c:1697:17
index 124 is out of range for type 'mdp_disk_t [27]'
CPU: 1 UID: 0 PID: 10197 Comm: syz.3.1362 Tainted: G L
syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine,
BIOS Google 08/05/2026
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
ubsan_epilogue+0xa/0x30 lib/ubsan.c:233
__ubsan_handle_out_of_bounds+0xcc/0xf0 lib/ubsan.c:455
super_90_sync+0x1eed/0x1ff0 drivers/md/md.c:1697
...
super_90_sync() exists for older version 0.90, which supports up to 27
maximum disks (MD_SB_DISKS). This function doesn't contain any bound checks for
raid disks. The repro wrote higher value (124) in raid_disks sysfs attribute
to trigger this bug.
Add bound checks in super_90_sync() to prevent index-out-of-bounds error. This
bound check hardens super_90_sync() function, such that it can catch max disk
index-out-of-bounds coming from any path, including raid_disks
attribute.
Signed-off-by: Aaditya Kansal <aadityakansal390@gmail.com>
---
drivers/md/md.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63cb3..f5fce41637f1 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1693,6 +1693,12 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
desc_nr = rdev2->raid_disk;
else
desc_nr = next_spare++;
+
+ if (desc_nr >= MD_SB_DISKS) {
+ pr_warn("md: raid_disks = %d exceeds max_disks = %d for version 0.90\n",
+ desc_nr, MD_SB_DISKS);
+ continue;
+ }
rdev2->desc_nr = desc_nr;
d = &sb->disks[rdev2->desc_nr];
nr_disks++;
@@ -1722,7 +1728,7 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
d->state |= (1<<MD_DISK_FAILFAST);
}
/* now set the "removed" and "faulty" bits on any missing devices */
- for (i=0 ; i < mddev->raid_disks ; i++) {
+ for (i = 0; i < mddev->raid_disks && i < MD_SB_DISKS; i++) {
mdp_disk_t *d = &sb->disks[i];
if (d->state == 0 && d->number == 0) {
d->number = i;
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH] md: add max_disks bound check in older version
2026-09-13 23:37 ` [PATCH] md: add max_disks bound check in older version Aaditya Kansal
@ 2026-09-13 23:37 ` syzbot
2026-09-13 23:51 ` sashiko-bot
1 sibling, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-13 23:37 UTC (permalink / raw)
To: aadityakansal390
Cc: aadityakansal390, linux-raid, linux-kernel, syzkaller-bugs
> #syz test
"" does not look like a valid git branch or commit.
>
> syzbot reported array-index-out-of-bounds in super_90_sync()
> UBSAN: array-index-out-of-bounds in drivers/md/md.c:1697:17
> index 124 is out of range for type 'mdp_disk_t [27]'
> CPU: 1 UID: 0 PID: 10197 Comm: syz.3.1362 Tainted: G L
> syzkaller #0 PREEMPT(full)
> Tainted: [L]=SOFTLOCKUP
> Hardware name: Google Google Compute Engine/Google Compute Engine,
> BIOS Google 08/05/2026
> Call Trace:
> <TASK>
> __dump_stack lib/dump_stack.c:94 [inline]
> dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
> ubsan_epilogue+0xa/0x30 lib/ubsan.c:233
> __ubsan_handle_out_of_bounds+0xcc/0xf0 lib/ubsan.c:455
> super_90_sync+0x1eed/0x1ff0 drivers/md/md.c:1697
> ...
>
> super_90_sync() exists for older version 0.90, which supports up to 27
> maximum disks (MD_SB_DISKS). This function doesn't contain any bound checks for
> raid disks. The repro wrote higher value (124) in raid_disks sysfs attribute
> to trigger this bug.
>
> Add bound checks in super_90_sync() to prevent index-out-of-bounds error. This
> bound check hardens super_90_sync() function, such that it can catch max disk
> index-out-of-bounds coming from any path, including raid_disks
> attribute.
>
> Signed-off-by: Aaditya Kansal <aadityakansal390@gmail.com>
> ---
> drivers/md/md.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 680b34a63cb3..f5fce41637f1 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1693,6 +1693,12 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
> desc_nr = rdev2->raid_disk;
> else
> desc_nr = next_spare++;
> +
> + if (desc_nr >= MD_SB_DISKS) {
> + pr_warn("md: raid_disks = %d exceeds max_disks = %d for version 0.90\n",
> + desc_nr, MD_SB_DISKS);
> + continue;
> + }
> rdev2->desc_nr = desc_nr;
> d = &sb->disks[rdev2->desc_nr];
> nr_disks++;
> @@ -1722,7 +1728,7 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
> d->state |= (1<<MD_DISK_FAILFAST);
> }
> /* now set the "removed" and "faulty" bits on any missing devices */
> - for (i=0 ; i < mddev->raid_disks ; i++) {
> + for (i = 0; i < mddev->raid_disks && i < MD_SB_DISKS; i++) {
> mdp_disk_t *d = &sb->disks[i];
> if (d->state == 0 && d->number == 0) {
> d->number = i;
> --
> 2.55.0
>
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH] md: add max_disks bound check in older version
2026-09-13 23:37 ` [PATCH] md: add max_disks bound check in older version Aaditya Kansal
2026-09-13 23:37 ` syzbot
@ 2026-09-13 23:51 ` sashiko-bot
1 sibling, 0 replies; 20+ messages in thread
From: sashiko-bot @ 2026-09-13 23:51 UTC (permalink / raw)
To: Aaditya Kansal; +Cc: yukuai, linux-raid
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The patch prevents an out-of-bounds write in `super_90_sync()` by adding a bounds check, but leaves an out-of-bounds read unhandled at the end of the function, which can be exploited as a kernel information leak.
- [High] A maliciously crafted version 0.90 superblock on disk can trigger an out-of-bounds read in `super_90_validate()` due to completely missing bounds validation of `this_disk.number` when the superblock is loaded.
--
commit bca793f34834f5048d928e016591b4ea5cf035dc
Author: Aaditya Kansal <aadityakansal390@gmail.com>
md: add max_disks bound check in older version
This commit adds bounds checking for raid_disks in super_90_sync() to prevent
an array-index-out-of-bounds access. It addresses a syzbot report where
a high value written to the raid_disks sysfs attribute triggered the bug.
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1693,6 +1693,12 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
> desc_nr = rdev2->raid_disk;
> else
> desc_nr = next_spare++;
> +
> + if (desc_nr >= MD_SB_DISKS) {
> + pr_warn("md: raid_disks = %d exceeds max_disks = %d for version 0.90\n",
> + desc_nr, MD_SB_DISKS);
> + continue;
> + }
[Severity: Critical]
This isn't a bug introduced by this patch, but could this continue statement
leave rdev->desc_nr unvalidated, leading to an out-of-bounds read later?
If an attacker provides a malicious block device with a version 0.90
superblock containing a large this_disk.number, super_90_load() assigns
this to rdev->desc_nr. Later, when md_update_sb() calls super_90_sync(),
the newly added bounds check skips updating rdev2->desc_nr because of the
continue statement.
At the end of super_90_sync(), the unvalidated rdev->desc_nr is then
unconditionally used to index into the array:
drivers/md/md.c:super_90_sync() {
...
sb->this_disk = sb->disks[rdev->desc_nr];
sb->sb_csum = calc_sb_csum(sb);
}
This copies 128 bytes from memory far past the 4KB superblock page into
sb->this_disk. The updated superblock is then written back to disk, which
can persistently leak out-of-bounds kernel memory to the attacker.
Alternatively, if raid_disks is manipulated via sysfs for a new disk,
rdev->desc_nr could remain -1, triggering a UBSAN out-of-bounds read.
[Severity: High]
This is a pre-existing issue, but does super_90_load() completely miss
bounds validation of this_disk.number when the superblock is loaded?
drivers/md/md.c:super_90_load() {
...
rdev->desc_nr = sb->this_disk.number;
...
}
When a block device with a crafted version 0.90 superblock is discovered
and assembled, super_90_load() blindly assigns this field without ensuring
it is less than MD_SB_DISKS. Subsequently, super_90_validate() computes
and dereferences an out-of-bounds pointer:
drivers/md/md.c:super_90_validate() {
...
if (sb->disks[rdev->desc_nr].state & (
(1<<MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE)))
...
desc = sb->disks + rdev->desc_nr;
if (desc->state & (1<<MD_DISK_FAULTY))
...
}
For large values, this dereferences a pointer significantly past the
allocated 4KB superblock page, hitting unmapped memory and causing a kernel
panic. Can bounds validation be added to super_90_load() to prevent this
denial-of-service vector?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260913233717.464321-1-aadityakansal390@gmail.com?part=1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH] md: add max_disks bound check in older version
2026-09-13 17:34 ` syzbot
2026-09-13 23:37 ` [PATCH] md: add max_disks bound check in older version Aaditya Kansal
@ 2026-09-13 23:44 ` Aaditya Kansal
2026-09-13 23:46 ` syzbot
2026-09-14 0:02 ` sashiko-bot
1 sibling, 2 replies; 20+ messages in thread
From: Aaditya Kansal @ 2026-09-13 23:44 UTC (permalink / raw)
To: syzbot+9e3014263a35700ab49b; +Cc: linux-raid, Aaditya Kansal
#syz test
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63cb3..f5fce41637f1 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1693,6 +1693,12 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
desc_nr = rdev2->raid_disk;
else
desc_nr = next_spare++;
+
+ if (desc_nr >= MD_SB_DISKS) {
+ pr_warn("md: raid_disks = %d exceeds max_disks = %d for version 0.90\n",
+ desc_nr, MD_SB_DISKS);
+ continue;
+ }
rdev2->desc_nr = desc_nr;
d = &sb->disks[rdev2->desc_nr];
nr_disks++;
@@ -1722,7 +1728,7 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
d->state |= (1<<MD_DISK_FAILFAST);
}
/* now set the "removed" and "faulty" bits on any missing devices */
- for (i=0 ; i < mddev->raid_disks ; i++) {
+ for (i = 0; i < mddev->raid_disks && i < MD_SB_DISKS; i++) {
mdp_disk_t *d = &sb->disks[i];
if (d->state == 0 && d->number == 0) {
d->number = i;
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH] md: add max_disks bound check in older version
2026-09-13 23:44 ` Aaditya Kansal
@ 2026-09-13 23:46 ` syzbot
2026-09-14 0:02 ` sashiko-bot
1 sibling, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-13 23:46 UTC (permalink / raw)
To: aadityakansal390
Cc: aadityakansal390, linux-raid, linux-kernel, syzkaller-bugs
> #syz test
"" does not look like a valid git branch or commit.
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 680b34a63cb3..f5fce41637f1 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1693,6 +1693,12 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
> desc_nr = rdev2->raid_disk;
> else
> desc_nr = next_spare++;
> +
> + if (desc_nr >= MD_SB_DISKS) {
> + pr_warn("md: raid_disks = %d exceeds max_disks = %d for version 0.90\n",
> + desc_nr, MD_SB_DISKS);
> + continue;
> + }
> rdev2->desc_nr = desc_nr;
> d = &sb->disks[rdev2->desc_nr];
> nr_disks++;
> @@ -1722,7 +1728,7 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
> d->state |= (1<<MD_DISK_FAILFAST);
> }
> /* now set the "removed" and "faulty" bits on any missing devices */
> - for (i=0 ; i < mddev->raid_disks ; i++) {
> + for (i = 0; i < mddev->raid_disks && i < MD_SB_DISKS; i++) {
> mdp_disk_t *d = &sb->disks[i];
> if (d->state == 0 && d->number == 0) {
> d->number = i;
> --
> 2.55.0
>
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH] md: add max_disks bound check in older version
2026-09-13 23:44 ` Aaditya Kansal
2026-09-13 23:46 ` syzbot
@ 2026-09-14 0:02 ` sashiko-bot
1 sibling, 0 replies; 20+ messages in thread
From: sashiko-bot @ 2026-09-14 0:02 UTC (permalink / raw)
To: Aaditya Kansal; +Cc: linux-raid, yukuai
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Skipping disk descriptor assignment via `continue` leaves `rdev->desc_nr` unhandled, causing out-of-bounds array reads or silent metadata corruption when assigning `sb->this_disk`.
--
commit c2add8f93f69d601b2a3935bff10c239b5018489
Author: Aaditya Kansal <aadityakansal390@gmail.com>
md: add max_disks bound check in older version
This commit adds a bounds check to prevent raid_disks from exceeding
the maximum allowed disks for version 0.90 superblocks. It prints a warning
and skips processing for devices that exceed this limit.
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 680b34a63cb3d..f5fce41637f12 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1693,6 +1693,12 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
> desc_nr = rdev2->raid_disk;
> else
> desc_nr = next_spare++;
> +
> + if (desc_nr >= MD_SB_DISKS) {
> + pr_warn("md: raid_disks = %d exceeds max_disks = %d for version 0.90\n",
> + desc_nr, MD_SB_DISKS);
> + continue;
> + }
[Severity: High]
Does skipping the disk descriptor assignment here leave the descriptor number
unhandled?
If an array has enough devices such that a newly added spare reaches
MD_SB_DISKS, this continue statement skips setting the descriptor number.
Since new devices are initialized with a value of -1, it remains -1.
After the loop, the descriptor is used unconditionally:
drivers/md/md.c:super_90_sync() {
...
sb->this_disk = sb->disks[rdev->desc_nr];
sb->sb_csum = calc_sb_csum(sb);
}
Can this lead to an out-of-bounds array read if rdev->desc_nr is negative or
invalid?
This is a pre-existing issue, but super_90_validate() blindly uses the
descriptor number read from the on-disk superblock to index the disks array:
drivers/md/md.c:super_90_validate() {
...
if (sb->disks[rdev->desc_nr].state & (
...
}
If the bounds are not strictly enforced, could a crafted disk image trigger
an out-of-bounds read there as well?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260913234627.465492-1-aadityakansal390@gmail.com?part=1
^ permalink raw reply [flat|nested] 20+ messages in thread
* Forwarded: [PATCH] md: validate raid_disks against MD_SB_DISKS in super_90_load
2026-09-13 13:09 [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
2026-09-13 17:34 ` syzbot
@ 2026-09-14 3:52 ` syzbot
2026-09-14 4:22 ` Forwarded: [PATCH] md: fix out-of-bounds access to superblock disk array syzbot
` (4 subsequent siblings)
6 siblings, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-14 3:52 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] md: validate raid_disks against MD_SB_DISKS in super_90_load
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
The v0.90 superblock format can only describe MD_SB_DISKS (27) member
disks, but super_90_load() only checks that sb->raid_disks is
positive, not that it fits within this limit.
A crafted/corrupt superblock with an oversized raid_disks value is
accepted and copied into mddev->raid_disks. When the superblock is
later rewritten (e.g. via a write to the rdev 'state' sysfs
attribute), super_90_sync() uses this value to index sb->disks[],
causing an out-of-bounds array access:
UBSAN: array-index-out-of-bounds in drivers/md/md.c:1697:17
index 124 is out of range for type 'mdp_disk_t [27]'
Reject superblocks whose raid_disks value cannot be represented by
the v0.90 format at load time, before it is trusted anywhere else.
Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9e3014263a35700ab49b
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
drivers/md/md.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63cb3..c65da77677bc 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1393,7 +1393,8 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
goto abort;
}
- if (sb->raid_disks <= 0)
+ if (sb->raid_disks <= 0 ||
+ sb->raid_disks > MD_SB_DISKS)
goto abort;
if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
--
2.34.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Forwarded: [PATCH] md: fix out-of-bounds access to superblock disk array
2026-09-13 13:09 [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
2026-09-13 17:34 ` syzbot
2026-09-14 3:52 ` Forwarded: [PATCH] md: validate raid_disks against MD_SB_DISKS in super_90_load syzbot
@ 2026-09-14 4:22 ` syzbot
2026-09-14 7:44 ` Forwarded: [PATCH] configfs: unhash dentry before dropping the item syzbot
` (3 subsequent siblings)
6 siblings, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-14 4:22 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] md: fix out-of-bounds access to superblock disk array
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
The v0.90 superblock format can only describe MD_SB_DISKS (27) member
disks, but several places did not enforce this limit, allowing an
out-of-bounds access to sb->disks[]:
1. super_90_load() only checked that sb->raid_disks was positive,
not that it fit within MD_SB_DISKS. A crafted superblock with an
oversized raid_disks value was accepted into mddev->raid_disks.
2. super_90_sync() computed desc_nr from rdev2->raid_disk or a
running spare counter without checking it stayed within bounds
before indexing sb->disks[desc_nr].
3. super_90_sync() also indexed sb->disks[rdev->desc_nr] for
sb->this_disk without any bounds check.
4. The "missing devices" loop in super_90_sync() iterated up to
mddev->raid_disks with no per-iteration bound on sb->disks[].
Any of these could be reached with a bad raid_disks/desc_nr value
and cause an out-of-bounds array access:
UBSAN: array-index-out-of-bounds in drivers/md/md.c:1697:17
index 124 is out of range for type 'mdp_disk_t [27]'
Validate raid_disks at load time, and add bounds checks at each
point sb->disks[] is indexed as defense in depth.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9e3014263a35700ab49b
Assisted-by: Claude
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
drivers/md/md.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63cb3..f950e6fd144c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1393,7 +1393,8 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
goto abort;
}
- if (sb->raid_disks <= 0)
+ if (sb->raid_disks <= 0 ||
+ sb->raid_disks > MD_SB_DISKS)
goto abort;
if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
@@ -1693,6 +1694,13 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
desc_nr = rdev2->raid_disk;
else
desc_nr = next_spare++;
+
+ if (desc_nr < 0 || desc_nr >= MD_SB_DISKS) {
+ pr_warn("md: %s: desc_nr %d out of range for rdev %pg, skipping\n",
+ mdname(mddev), desc_nr, rdev2->bdev);
+ continue;
+ }
+
rdev2->desc_nr = desc_nr;
d = &sb->disks[rdev2->desc_nr];
nr_disks++;
@@ -1722,7 +1730,7 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
d->state |= (1<<MD_DISK_FAILFAST);
}
/* now set the "removed" and "faulty" bits on any missing devices */
- for (i=0 ; i < mddev->raid_disks ; i++) {
+ for (i=0 ; i < mddev->raid_disks && i < MD_SB_DISKS ; i++) {
mdp_disk_t *d = &sb->disks[i];
if (d->state == 0 && d->number == 0) {
d->number = i;
@@ -1737,8 +1745,11 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
sb->working_disks = working;
sb->failed_disks = failed;
sb->spare_disks = spare;
-
- sb->this_disk = sb->disks[rdev->desc_nr];
+ if (rdev->desc_nr >= 0 && rdev->desc_nr < MD_SB_DISKS)
+ sb->this_disk = sb->disks[rdev->desc_nr];
+ else
+ pr_warn("md: %s: rdev desc_nr %d out of range, this_disk not set\n",
+ mdname(mddev), rdev->desc_nr);
sb->sb_csum = calc_sb_csum(sb);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Forwarded: [PATCH] configfs: unhash dentry before dropping the item
2026-09-13 13:09 [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
` (2 preceding siblings ...)
2026-09-14 4:22 ` Forwarded: [PATCH] md: fix out-of-bounds access to superblock disk array syzbot
@ 2026-09-14 7:44 ` syzbot
2026-09-14 12:28 ` Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
` (2 subsequent siblings)
6 siblings, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-14 7:44 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] configfs: unhash dentry before dropping the item
Author: jchuang26@m.fudan.edu.cn
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63..bcc32b83c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1393,7 +1393,11 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
goto abort;
}
- if (sb->raid_disks <= 0)
+ /*
+ * sb->disks[] has only MD_SB_DISKS entries. A larger raid_disks
+ * count would later make super_90_sync() index past that array.
+ */
+ if (sb->raid_disks <= 0 || sb->raid_disks > MD_SB_DISKS)
goto abort;
if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
@@ -1607,6 +1611,18 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
struct md_rdev *rdev2;
int next_spare = mddev->raid_disks;
+ /*
+ * A 0.90 superblock has a fixed-size mdp_disk_t array and uses
+ * raid_disks as both a loop bound and the first spare disk slot.
+ * Never index sb->disks[] if an invalid raid_disks value reached
+ * us through any configuration path.
+ */
+ if (mddev->raid_disks < 0 || mddev->raid_disks > MD_SB_DISKS) {
+ pr_warn("md: %s: invalid raid_disks %d for 0.90 metadata\n",
+ mdname(mddev), mddev->raid_disks);
+ return;
+ }
+
/* make rdev->sb match mddev data..
*
* 1/ zero out disks
@@ -4448,8 +4464,19 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
mddev->delta_disks = n - olddisks;
mddev->raid_disks = n;
mddev->reshape_backwards = (mddev->delta_disks < 0);
- } else
- mddev->raid_disks = n;
+ } else {
+ /*
+ * 0.90 metadata only has room for MD_SB_DISKS descriptors.
+ * Larger values would make super_90_sync() index beyond
+ * sb->disks[].
+ */
+ if ((mddev->persistent && mddev->major_version == 0 &&
+ n > MD_SB_DISKS) ||
+ (mddev->max_disks && n > mddev->max_disks))
+ err = -EINVAL;
+ else
+ mddev->raid_disks = n;
+ }
out_unlock:
memalloc_noio_restore(noio_flags);
mddev_unlock_and_resume(mddev);
@@ -7926,6 +7953,18 @@ int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
mddev->ctime = ktime_get_real_seconds();
return 0;
}
+
+ /*
+ * Persistent 0.90 metadata stores disks in sb->disks[MD_SB_DISKS].
+ * A larger raid_disks count would make super_90_sync() index past
+ * that array; non-persistent arrays have no such on-disk limit.
+ */
+ if (info->raid_disks < 0 ||
+ (!info->not_persistent && info->raid_disks > MD_SB_DISKS)) {
+ pr_warn("md: invalid raid_disks %d\n", info->raid_disks);
+ return -EINVAL;
+ }
+
mddev->major_version = MD_MAJOR_VERSION;
mddev->minor_version = MD_MINOR_VERSION;
mddev->patch_version = MD_PATCHLEVEL_VERSION;
^ permalink raw reply related [flat|nested] 20+ messages in thread* Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync
2026-09-13 13:09 [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
` (3 preceding siblings ...)
2026-09-14 7:44 ` Forwarded: [PATCH] configfs: unhash dentry before dropping the item syzbot
@ 2026-09-14 12:28 ` syzbot
2026-09-15 1:39 ` syzbot
2026-09-17 1:28 ` syzbot
6 siblings, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-14 12:28 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync
Author: jchuang26@m.fudan.edu.cn
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2f0c1cf72f4682178506f513bbf015e591b1aa4a
Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63..1f84f2034 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1393,7 +1393,12 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
goto abort;
}
- if (sb->raid_disks <= 0)
+ /*
+ * The 0.90 superblock only has room for MD_SB_DISKS disk
+ * descriptors; a larger raid_disks would later make
+ * super_90_sync() index beyond the end of sb->disks[].
+ */
+ if (sb->raid_disks <= 0 || sb->raid_disks > MD_SB_DISKS)
goto abort;
if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
@@ -7926,6 +7931,16 @@ int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
mddev->ctime = ktime_get_real_seconds();
return 0;
}
+ /*
+ * A persistent (0.90) superblock can only describe MD_SB_DISKS
+ * devices. Reject negative or oversized raid_disks here so that
+ * super_90_sync() cannot index outside sb->disks[].
+ * Non-persistent arrays never write a superblock, so they are not
+ * limited by this on-disk format.
+ */
+ if (info->raid_disks < 0 ||
+ (!info->not_persistent && info->raid_disks > MD_SB_DISKS))
+ return -EINVAL;
mddev->major_version = MD_MAJOR_VERSION;
mddev->minor_version = MD_MINOR_VERSION;
mddev->patch_version = MD_PATCHLEVEL_VERSION;
^ permalink raw reply related [flat|nested] 20+ messages in thread* Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync
2026-09-13 13:09 [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
` (4 preceding siblings ...)
2026-09-14 12:28 ` Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
@ 2026-09-15 1:39 ` syzbot
2026-09-17 1:28 ` syzbot
6 siblings, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-15 1:39 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync
Author: jchuang26@m.fudan.edu.cn
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63..1f84f2034 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1393,7 +1393,12 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
goto abort;
}
- if (sb->raid_disks <= 0)
+ /*
+ * The 0.90 superblock only has room for MD_SB_DISKS disk
+ * descriptors; a larger raid_disks would later make
+ * super_90_sync() index beyond the end of sb->disks[].
+ */
+ if (sb->raid_disks <= 0 || sb->raid_disks > MD_SB_DISKS)
goto abort;
if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
@@ -7926,6 +7931,16 @@ int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
mddev->ctime = ktime_get_real_seconds();
return 0;
}
+ /*
+ * A persistent (0.90) superblock can only describe MD_SB_DISKS
+ * devices. Reject negative or oversized raid_disks here so that
+ * super_90_sync() cannot index outside sb->disks[].
+ * Non-persistent arrays never write a superblock, so they are not
+ * limited by this on-disk format.
+ */
+ if (info->raid_disks < 0 ||
+ (!info->not_persistent && info->raid_disks > MD_SB_DISKS))
+ return -EINVAL;
mddev->major_version = MD_MAJOR_VERSION;
mddev->minor_version = MD_MINOR_VERSION;
mddev->patch_version = MD_PATCHLEVEL_VERSION;
^ permalink raw reply related [flat|nested] 20+ messages in thread* Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync
2026-09-13 13:09 [syzbot] [raid?] UBSAN: array-index-out-of-bounds in super_90_sync syzbot
` (5 preceding siblings ...)
2026-09-15 1:39 ` syzbot
@ 2026-09-17 1:28 ` syzbot
6 siblings, 0 replies; 20+ messages in thread
From: syzbot @ 2026-09-17 1:28 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] UBSAN: array-index-out-of-bounds in super_90_sync
Author: jchuang26@m.fudan.edu.cn
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63..45fcf79b2 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1393,7 +1393,12 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
goto abort;
}
- if (sb->raid_disks <= 0)
+ /*
+ * A 0.90 superblock has only MD_SB_DISKS descriptors, and
+ * super_90_sync() uses raid_disks as the first free spare slot.
+ * Reject geometries which cannot be represented safely.
+ */
+ if (sb->raid_disks <= 0 || sb->raid_disks >= MD_SB_DISKS)
goto abort;
if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
@@ -1408,6 +1413,9 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
rdev->badblocks.shift = -1;
rdev->desc_nr = sb->this_disk.number;
+ /* desc_nr is used as an index into sb->disks[] below and later. */
+ if (rdev->desc_nr < 0 || rdev->desc_nr >= MD_SB_DISKS)
+ goto abort;
/* not spare disk */
if (rdev->desc_nr >= 0 && rdev->desc_nr < MD_SB_DISKS &&
@@ -1487,6 +1495,13 @@ static int super_90_validate(struct mddev *mddev, struct md_rdev *freshest, stru
clear_bit(Bitmap_sync, &rdev->flags);
clear_bit(WriteMostly, &rdev->flags);
+ /* rdev->desc_nr is used to index sb->disks[] below. */
+ if (rdev->desc_nr < 0 || rdev->desc_nr >= MD_SB_DISKS) {
+ pr_warn("md: invalid disk number %d on %pg\n",
+ rdev->desc_nr, rdev->bdev);
+ return -EINVAL;
+ }
+
if (mddev->raid_disks == 0) {
mddev->major_version = 0;
mddev->minor_version = sb->minor_version;
@@ -1575,6 +1590,14 @@ static int super_90_validate(struct mddev *mddev, struct md_rdev *freshest, stru
desc = sb->disks + rdev->desc_nr;
+ /* An active descriptor must not point past sb->disks[]. */
+ if ((desc->state & ((1<<MD_DISK_SYNC) | (1<<MD_DISK_ACTIVE))) &&
+ desc->raid_disk >= MD_SB_DISKS) {
+ pr_warn("md: invalid raid_disk %u on %pg\n",
+ desc->raid_disk, rdev->bdev);
+ return -EINVAL;
+ }
+
if (desc->state & (1<<MD_DISK_FAULTY))
set_bit(Faulty, &rdev->flags);
else if (desc->state & (1<<MD_DISK_SYNC)) {
@@ -1620,6 +1643,17 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
int i;
int active=0, working=0,failed=0,spare=0,nr_disks=0;
+ /*
+ * A 0.90 superblock has only MD_SB_DISKS descriptors and needs one
+ * free slot for spares/faulty disks. Refuse invalid geometry rather
+ * than indexing sb->disks[] out of bounds.
+ */
+ if (mddev->raid_disks < 0 || mddev->raid_disks >= MD_SB_DISKS) {
+ pr_warn("md: %s: invalid number of raid disks %d\n",
+ mdname(mddev), mddev->raid_disks);
+ return;
+ }
+
rdev->sb_size = MD_SB_BYTES;
sb = page_address(rdev->sb_page);
@@ -1693,6 +1727,12 @@ static void super_90_sync(struct mddev *mddev, struct md_rdev *rdev)
desc_nr = rdev2->raid_disk;
else
desc_nr = next_spare++;
+ /* The slot number must fit in the on-disk descriptor array. */
+ if (desc_nr < 0 || desc_nr >= MD_SB_DISKS) {
+ pr_warn("md: %s: invalid disk descriptor %d\n",
+ mdname(mddev), desc_nr);
+ return;
+ }
rdev2->desc_nr = desc_nr;
d = &sb->disks[rdev2->desc_nr];
nr_disks++;
@@ -4428,6 +4468,20 @@ raid_disks_store(struct mddev *mddev, const char *buf, size_t len)
if (err)
return err;
noio_flags = memalloc_noio_save();
+ /*
+ * Make sure the new value fits in the selected metadata format.
+ * A 0.90 superblock has only MD_SB_DISKS descriptors, and
+ * super_90_sync() uses raid_disks as the first free spare slot.
+ */
+ if (mddev->max_disks && n >= mddev->max_disks) {
+ err = -EINVAL;
+ goto out_unlock;
+ }
+ if (mddev->persistent && mddev->major_version == 0 &&
+ n >= MD_SB_DISKS) {
+ err = -EINVAL;
+ goto out_unlock;
+ }
if (mddev->pers) {
if (n != mddev->raid_disks)
err = update_raid_disks(mddev, n);
@@ -7926,6 +7980,17 @@ int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info)
mddev->ctime = ktime_get_real_seconds();
return 0;
}
+ /*
+ * A persistent 0.90 superblock has only MD_SB_DISKS descriptors, and
+ * one must stay free for spares/faulty disks. A larger raid_disks
+ * value would make super_90_sync() index sb->disks[] out of bounds.
+ */
+ if (info->raid_disks < 0 ||
+ (!info->not_persistent && info->raid_disks >= MD_SB_DISKS)) {
+ pr_warn("md: invalid number of raid disks %d\n",
+ info->raid_disks);
+ return -EINVAL;
+ }
mddev->major_version = MD_MAJOR_VERSION;
mddev->minor_version = MD_MINOR_VERSION;
mddev->patch_version = MD_PATCHLEVEL_VERSION;
^ permalink raw reply related [flat|nested] 20+ messages in thread