Linux RAID subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwon.cho@skku.edu>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH v2] md: validate v1 dev_number while loading superblock
Date: Thu, 03 Dec 2026 20:12:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-248600@kernel.org> (raw)
In-Reply-To: <179632352675.3850376.17102584105921885328@skku.edu>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] md: super_1_load() mutates rdev before rejecting invalid
  dev_number
--

commit a0eec6cd1d25c6793206a833b9ec2bf2f91c3491
Author: Kyuwon Cho <kyuwon.cho@skku.edu>

md: validate v1 dev_number while loading superblock

This commit checks that sb->dev_number is less than sb->max_dev in
super_1_load() before assigning rdev->desc_nr, returning -EINVAL if it is
out of range.

> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 47da9edc1c606..27b0fedfbec87 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1913,8 +1913,10 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
>  	    && rdev->new_data_offset < sb_start + (rdev->sb_size/512))
>  		return -EINVAL;
>  
> -	rdev->desc_nr = le32_to_cpu(sb->dev_number);
> +	if (le32_to_cpu(sb->dev_number) >= le32_to_cpu(sb->max_dev))
> +		return -EINVAL;
>  
> +	rdev->desc_nr = le32_to_cpu(sb->dev_number);

[Severity: Medium]
Should this check happen before super_1_load() overwrites rdev fields?

Earlier in super_1_load(), rdev->data_offset, rdev->new_data_offset, and
rdev->sb_size are already updated from the incoming superblock.  In clustered
md, process_metadata_update() -> md_reload_sb() -> read_rdev() reloads a live
member and only restores rdev->sb_page and rdev->sb_loaded on error.

If the rejected superblock had a different data_offset or smaller max_dev,
subsequent bios use the overwritten data_offset and later super_1_sync()
writes can use an rdev->sb_size inconsistent with the restored superblock.
Moving this check alongside the max_dev header check avoids mutating rdev.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179632352675.3850376.17102584105921885328@skku.edu?part=1

      reply	other threads:[~2026-12-03 20:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 19:50 [PATCH v2] md: validate v1 dev_number while loading superblock Kyuwon Cho
2026-12-03 20:12 ` 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=sashiko-outbox-248600@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kyuwon.cho@skku.edu \
    --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