From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwon.cho@skku.edu>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH] md: validate v1 dev_number while loading superblock
Date: Thu, 03 Dec 2026 17:46:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-248300@kernel.org> (raw)
In-Reply-To: <179621082761.2397410.3913367575512805215@skku.edu>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] md: super_1_load() desc_nr=-1 causes dev_roles[-1] OOB and
stale dev_number
- [Low] md: Fixes tag cites 1da177e4c3f4 instead of introducing commit
31b65a0d3894
- [Low] md: two-step write to rdev->desc_nr in super_1_load() races with
RCU readers
--
commit 141b0781ca4e4bf71f443a15d7441d9cc5894d2a
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
> md: validate v1 dev_number while loading superblock
>
> super_1_load() copies dev_number to rdev->desc_nr without checking it
> against the dev_roles array described by max_dev. Assembly normally catches
> this later in super_1_validate(), but an array configured through sysfs can
> reach super_1_sync() without that validation and index past dev_roles.
>
> Normalize an invalid descriptor number when the superblock is loaded. The
> normal rdev binding path will then assign a valid free descriptor number.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
[Severity: Low]
In 1da177e4c3f4 ("Linux-2.6.12-rc2"), super_1_load() did not assign
rdev->desc_nr; that assignment was moved there later. Should this tag
instead be:
Fixes: 31b65a0d3894 ("[PATCH] md: set desc_nr correctly for version-1 superblocks")
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 47da9edc1c606..5a6c87942bfd8 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1914,6 +1914,9 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
> return -EINVAL;
>
> rdev->desc_nr = le32_to_cpu(sb->dev_number);
> + if (rdev->desc_nr < 0 ||
> + rdev->desc_nr >= le32_to_cpu(sb->max_dev))
> + rdev->desc_nr = -1;
>
> if (!rdev->bb_page) {
> rdev->bb_page = alloc_page(GFP_KERNEL);
[Severity: High]
Can setting rdev->desc_nr to -1 here cause an out-of-bounds write to
sb->dev_roles[-1] in super_1_sync()?
super_1_load() is also called on already-bound rdevs in analyze_sbs() and
read_rdev(), which do not call bind_rdev_to_array() afterward. During
assembly of a device with an out-of-range sb->dev_number, analyze_sbs()
reloads the superblock and resets rdev->desc_nr back to -1.
Because rdev->desc_nr is signed, -1 bypasses the rdev->desc_nr >=
mddev->max_disks check in analyze_sbs() that previously kicked the device,
and super_1_validate() leaves it bound with rdev->desc_nr == -1.
When super_1_sync() runs, sb->dev_roles[-1] overwrites sb->pad3 on every
member disk, causing later super_1_load() calls to reject even healthy
disks when check_new_feature is enabled. does_sb_need_changing() and
check_sb_changes() also read sb->dev_roles[-1] out of bounds.
Separately, super_1_sync() never writes sb->dev_number, so an invalid
on-disk dev_number stays stale even on the sysfs path after
bind_rdev_to_array() assigns a valid descriptor. Returning -EINVAL from
super_1_load() on an out-of-range sb->dev_number avoids both issues.
[Severity: Low]
Can writing the unvalidated sb->dev_number directly into rdev->desc_nr
before clamping it to -1 race with concurrent RCU readers?
analyze_sbs() and read_rdev() call super_1_load() on already-bound rdevs
while holding only mddev->reconfig_mutex, whereas md_seq_show() reads
rdev->desc_nr under mddev->lock and rcu_read_lock():
CPU0 CPU1
analyze_sbs()
super_1_load()
rdev->desc_nr = le32_to_cpu(...)
md_seq_show()
rcu_read_lock()
seq_printf(..., rdev->desc_nr)
<-- reads unvalidated value
rdev->desc_nr = -1
This transiently exposes the out-of-range descriptor number to /proc/mdstat
(and similarly to GET_DISK_INFO via md_find_rdev_nr_rcu() during clustered
reloads) and triggers a KCSAN data race. Validating into a local variable
before updating rdev->desc_nr avoids publishing the invalid value.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179621082761.2397410.3913367575512805215@skku.edu?part=1
prev parent reply other threads:[~2026-12-03 17:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:48 [PATCH] md: validate v1 dev_number while loading superblock Kyuwon Cho
2026-12-03 17:46 ` 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-248300@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