From: sashiko-bot@kernel.org
To: "Li Youhong" <dayou5941@163.com>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io
Subject: Re: [PATCH] md: fix NULL dereference of pers in md_start_sync()
Date: Fri, 06 Nov 2026 08:53:36 +0000 [thread overview]
Message-ID: <sashiko-outbox-201094@kernel.org> (raw)
In-Reply-To: <20261106083543.249267-1-dayou5941@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] md: use-after-free of mddev in md_start_sync() after md_stop()
--
commit 430c0b94e66563acd0f6769283c9a65888eb4dba
Author: Li Youhong <liyouhong@kylinos.cn>
md: fix NULL dereference of pers in md_start_sync()
This commit adds a NULL check for mddev->pers in md_start_sync() to bail
out via not_running if md_stop() has already cleared pers.
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 03e35386a8028..9cafa8d673e82 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -10312,6 +10312,13 @@ static void md_start_sync(struct work_struct *ws)
> noio_flags = memalloc_noio_save();
> }
>
> + /*
> + * md_stop() clears pers. This work may have been queued earlier and
> + * can run after that, so pers may already be NULL here.
> + */
> + if (!mddev->pers)
> + goto not_running;
[Severity: High]
Can md_start_sync() still use mddev after it is freed when dm-raid calls
md_stop()?
Standard md teardown in do_md_stop() calls stop_sync_thread(), which flushes
mddev->sync_work before __md_stop() clears mddev->pers. In contrast,
dm-raid's raid_dtr() calls md_stop(), unlocks reconfig_mutex, flushes only
event_work, and immediately destroys and frees rs without cancelling or
flushing sync_work:
CPU0 CPU1 (kworker)
raid_dtr() md_start_sync()
mddev_lock_nointr(&rs->md)
md_stop(&rs->md)
__md_stop(&rs->md)
mddev->pers = NULL
mddev_unlock(&rs->md)
mddev_lock_nointr(mddev)
if (!mddev->pers)
goto not_running;
...
mddev_unlock(mddev)
raid_set_free(rs)
mddev_destroy(&rs->md)
percpu_ref_exit(&mddev->active_io)
kfree(rs)
__mddev_resume(mddev, false)
test_and_clear_bit(..., &mddev->recovery)
<-- use-after-free
If md_start_sync() starts after raid_dtr() unlocks reconfig_mutex, it can
also access freed mddev memory before reaching the !mddev->pers check, and
the check itself sits after the conditional unlock-and-suspend block that
can drop reconfig_mutex and suspend an already-stopped array.
Should md_stop() (or __md_stop_writes()) flush or cancel mddev->sync_work
before __md_stop() clears mddev->pers?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106083543.249267-1-dayou5941@163.com?part=1
next prev parent reply other threads:[~2026-11-06 8:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 8:35 [PATCH] md: fix NULL dereference of pers in md_start_sync() Li Youhong
2026-11-06 8:53 ` sashiko-bot [this message]
2026-11-08 3:14 ` yu kuai
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-201094@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dayou5941@163.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 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.