From: sashiko-bot@kernel.org
To: "Shuai Liu" <847807867@qq.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH v3] md: fix use-after-free of mddev in md_start_sync workqueue
Date: Thu, 26 Nov 2026 01:06:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-234521@kernel.org> (raw)
In-Reply-To: <tencent_B6137BEEFCD26A2CCBF27D4DF0B81D622608@qq.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] md: stop_sync_thread() skips flush_work() after
MD_RECOVERY_RUNNING clears
--
commit cae588baa1080f65953ef30de3a815480f1b5d39
Author: Shuai Liu <847807867@qq.com>
md: fix use-after-free of mddev in md_start_sync workqueue
This commit takes an mddev reference when queueing sync_work, checks
MD_RECOVERY_FROZEN in the read-only branch of md_check_recovery(), and
flushes sync_work unconditionally in stop_sync_thread() and raid_dtr().
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 47da9edc1c606..dfad785da26b5 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -5224,8 +5224,7 @@ static void stop_sync_thread(struct mddev *mddev, bool locked)
> * never happen
> */
> md_wakeup_thread_directly(&mddev->sync_thread);
> - if (work_pending(&mddev->sync_work))
> - flush_work(&mddev->sync_work);
> + flush_work(&mddev->sync_work);
>
> wait_event(resync_wait,
> !test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
[Severity: Medium]
Can stop_sync_thread() still return without calling flush_work() while
md_start_sync() is running?
stop_sync_thread() returns early when MD_RECOVERY_RUNNING is clear:
drivers/md/md.c:stop_sync_thread() {
if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
if (!locked)
mddev_unlock(mddev);
return;
}
...
}
In md_start_sync(), the not_running path clears MD_RECOVERY_RUNNING
before calling mddev_unlock(), __mddev_resume(), and
sysfs_notify_dirent_safe(mddev->sysfs_action) (and on the normal path,
the newly woken sync_thread can finish and be reaped before
md_start_sync() reaches sysfs_notify_dirent_safe()). Once
reconfig_mutex is released in mddev_unlock(), a concurrent stop or
reconfiguration caller sees MD_RECOVERY_RUNNING clear and skips
flush_work(&mddev->sync_work):
kworker (md_start_sync) CPU1 (do_md_stop, mode == 2)
----------------------- ----------------------------
not_running:
clear_bit(MD_RECOVERY_RUNNING)
mddev_unlock(mddev)
mddev_lock(mddev)
__md_stop_writes(mddev)
stop_sync_thread(mddev, true)
!test_bit(MD_RECOVERY_RUNNING)
return; <-- skips flush_work()
mddev->to_remove = &md_redundancy_group
mddev_unlock(mddev)
sysfs_put(mddev->sysfs_action)
if (test_and_clear_bit(MD_RECOVERY_RECOVER) &&
mddev->sysfs_action)
sysfs_notify_dirent_safe(mddev->sysfs_action) <-- use-after-free
mddev->sysfs_action = NULL
In addition to the mddev->sysfs_action use-after-free, if
md_start_sync() suspended the array and has not yet reached
__mddev_resume(mddev, false), __md_stop() -> mddev_detach() sees
is_md_suspended(mddev) true and skips mddev->pers->quiesce().
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_B6137BEEFCD26A2CCBF27D4DF0B81D622608@qq.com?part=1
prev parent reply other threads:[~2026-11-26 1:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 0:45 [PATCH v3] md: fix use-after-free of mddev in md_start_sync workqueue Shuai Liu
2026-11-26 1:06 ` 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-234521@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=847807867@qq.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