Linux RAID subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aaditya Kansal" <aadityakansal390@gmail.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH] md: add max_disks bound check in older version
Date: Mon, 14 Sep 2026 00:02:47 +0000	[thread overview]
Message-ID: <20260914000248.2BE661F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260913234627.465492-1-aadityakansal390@gmail.com>

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

      parent reply	other threads:[~2026-09-14  0:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:37     ` syzbot
2026-09-13 23:51     ` sashiko-bot
2026-09-13 23:44   ` Aaditya Kansal
2026-09-13 23:46     ` syzbot
2026-09-14  0:02     ` sashiko-bot [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=20260914000248.2BE661F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aadityakansal390@gmail.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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