All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaditya Kansal <aadityakansal390@gmail.com>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>
Cc: Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
	linux-raid@vger.kernel.org,
	syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] md: fix out-of-bound by adding checks at store
Date: Thu, 1 Oct 2026 03:36:04 +0530	[thread overview]
Message-ID: <d26b5aa7-0d8e-4d9e-a6a0-a4edb618259c@gmail.com> (raw)
In-Reply-To: <20260923124634.5497-1-aadityakansal390@gmail.com>

On 9/23/26 6:16 PM, Aaditya Kansal wrote:
> 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.
>
> The repro is one configuration that triggers this bug, which is caused by
> the lack of proper checks at sysfs stores. Store is one path to reach
> OOB.
>
> Add helper function md_check_disks_fit_metadata() and call it at
> raid_disks_store() and metadata_store() to reject the write for
> mismatched configuration (raid_disks > MD_SB_DISKS for major == 0). This
> prevents invalid configuration via stores from reaching the super_90_sync
> function.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Reported-by: syzbot+9e3014263a35700ab49b@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=9e3014263a35700ab49b
> Signed-off-by: Aaditya Kansal <aadityakansal390@gmail.com>
> ---
> v2:
> - moved the fix from super_90_sync() to a level above at store functions
> - add checks at stores themselves to prevent wrong configuration from
>    reaching the target function
> - add helper function to be called at all the sites where check is
>    required
>
>   drivers/md/md.c | 23 ++++++++++++++++++++++-
>   1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 680b34a63cb3..f0f693f6bf7c 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1354,6 +1354,13 @@ int md_check_no_bitmap(struct mddev *mddev)
>   }
>   EXPORT_SYMBOL(md_check_no_bitmap);
>
> +static int md_check_disks_fit_metadata(int major, int raid_disks)
> +{
> +	if (major == 0 && raid_disks > MD_SB_DISKS)
> +		return -EINVAL;
> +	return 0;
> +}
> +
>   /*
>    * load_super for 0.90.0
>    */
> @@ -4448,8 +4455,15 @@ 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
> +	} else {
> +		err = md_check_disks_fit_metadata(mddev->major_version, n);
> +		if (err) {
> +			pr_warn("md: raid disks (%d) exceeds max disks (%d) for metadata version 0.90",
> +					n, MD_SB_DISKS);
> +			goto out_unlock;
> +		}
>   		mddev->raid_disks = n;
> +	}
>   out_unlock:
>   	memalloc_noio_restore(noio_flags);
>   	mddev_unlock_and_resume(mddev);
> @@ -5041,6 +5055,13 @@ metadata_store(struct mddev *mddev, const char *buf, size_t len)
>   	err = -ENOENT;
>   	if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL)
>   		goto out_unlock;
> +
> +	err = md_check_disks_fit_metadata(major, mddev->raid_disks);
> +	if (err) {
> +		pr_warn("md: metadata version 0.90 doesn't support raid disks count higher than %d",
> +				MD_SB_DISKS);
> +		goto out_unlock;
> +	}
>   	mddev->major_version = major;
>   	mddev->minor_version = minor;
>   	mddev->persistent = 1;
> --
> 2.55.0

Hi, ping for the patch.

-AK


      reply	other threads:[~2026-09-30 22:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 12:46 [PATCH v2] md: fix out-of-bound by adding checks at store Aaditya Kansal
2026-09-30 22:06 ` Aaditya Kansal [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=d26b5aa7-0d8e-4d9e-a6a0-a4edb618259c@gmail.com \
    --to=aadityakansal390@gmail.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=song@kernel.org \
    --cc=syzbot+9e3014263a35700ab49b@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.