From: sashiko-bot@kernel.org
To: "Zhihao Cheng" <chengzhihao1@huawei.com>
Cc: yukuai@fygo.io, linux-raid@vger.kernel.org
Subject: Re: [PATCH v3 2/4] md: Handle pers->run failure in level_store
Date: Wed, 23 Sep 2026 11:46:26 +0000 [thread overview]
Message-ID: <20260923114627.3CC921F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260923112159.94175-3-chengzhihao1@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] md: NULL pointer dereference in md_handle_request() after pers->run() fails
--
commit 3549464235e3de415ce8ceb834293e195eafad7d
Author: Zhihao Cheng <chengzhihao1@huawei.com>
md: Handle pers->run failure in level_store
This commit adds error handling for the pers->run(mddev) call in
level_store(). When pers->run() fails, it stops the array via __md_stop()
and unlinks sysfs nodes before unlocking and returning.
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 680b34a63cb3d..0a3252098780b 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
[ ... ]
> @@ -4229,7 +4230,33 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
> mddev->in_sync = 1;
> timer_delete_sync(&mddev->safemode_timer);
> }
> - pers->run(mddev);
> + rv = pers->run(mddev);
> + if (rv) {
> + /*
> + * ->run() has released the private data of the new personality,
> + * while the old one has already been released as well. There is
> + * nothing to fall back to, so stop the array to avoid leaving
> + * 'mddev->pers' pointing to a personality which has no private
> + * data, and reminds user to try to active the mddev again.
> + */
> + pr_warn("md: %s: failed to run %s after takeover, please try to active\n",
> + mdname(mddev), pers->head.name);
> + if (mddev->pers->sync_request && mddev->to_remove == NULL)
> + mddev->to_remove = &md_redundancy_group;
> + if (md_bitmap_enabled(mddev, true))
> + mddev->bitmap_ops->flush(mddev);
> + clear_bit(MD_SERIALIZE_POLICY, &mddev->flags);
> + mddev_destroy_serial_pool(mddev, NULL);
> + __md_stop(mddev);
> + rdev_for_each(rdev, mddev)
> + if (rdev->raid_disk >= 0)
> + sysfs_unlink_rdev(mddev, rdev);
> + set_capacity_and_notify(mddev->gendisk, 0);
> + mddev->changed = 1;
> + md_new_event();
> + sysfs_notify_dirent_safe(mddev->sysfs_state);
> + goto out_unlock;
[Severity: High]
Can this trigger a NULL pointer dereference in md_handle_request() for
concurrent bios?
If pers->run() fails, __md_stop() sets mddev->pers to NULL. The error path
then jumps to out_unlock, which subsequently calls mddev_unlock_and_resume().
When the array is resumed, mddev_unlock_and_resume() resurrects active_io
and wakes up mddev->sb_wait. If there are concurrent bios submitted to the
array, they may be blocked in md_handle_request() waiting on sb_wait:
drivers/md/md.c:md_handle_request() {
...
if (is_suspended(mddev, bio)) {
/* Bail out if REQ_NOWAIT is set for the bio */
if (bio->bi_opf & REQ_NOWAIT) {
bio_wouldblock_error(bio);
return true;
}
wait_event(mddev->sb_wait, !is_suspended(mddev, bio));
}
if (!percpu_ref_tryget_live(&mddev->active_io))
goto check_suspended;
}
if (!mddev->pers->make_request(mddev, bio)) {
...
}
Once woken up, they will re-acquire active_io and unconditionally dereference
mddev->pers->make_request. Since mddev->pers was set to NULL by __md_stop(),
will this result in a kernel panic?
> + }
> set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
> if (!mddev->thread)
> md_update_sb(mddev, 1);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260923112159.94175-1-chengzhihao1@huawei.com?part=2
next prev parent reply other threads:[~2026-09-23 11:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 11:21 [PATCH v3 0/4] md: Fix two raid5/raid10 bugs Zhihao Cheng
2026-09-23 11:21 ` [PATCH v3 1/4] md/raid5: Hide the origin mddev->thread before takeover Zhihao Cheng
2026-10-09 4:31 ` yu kuai
2026-10-09 7:12 ` Zhihao Cheng
2026-09-23 11:21 ` [PATCH v3 2/4] md: Handle pers->run failure in level_store Zhihao Cheng
2026-09-23 11:46 ` sashiko-bot [this message]
2026-09-23 11:48 ` Zhihao Cheng
2026-09-23 18:42 ` Bruce Johnston
2026-09-24 11:53 ` Zhihao Cheng
2026-09-24 17:37 ` Bruce Johnston
2026-10-09 5:05 ` yu kuai
2026-09-23 11:21 ` [PATCH v3 3/4] md/raid5: Don't free conf on raid5_run failure Zhihao Cheng
2026-09-23 11:21 ` [PATCH v3 4/4] md/raid10: Don't free conf on raid10_run failure Zhihao Cheng
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=20260923114627.3CC921F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chengzhihao1@huawei.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