From: "Li Youhong" <dayou5941@163.com>
To: song@kernel.org, yukuai@fygo.io
Cc: magiclinan@didiglobal.com, xiao@kernel.org,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
Li Youhong <liyouhong@kylinos.cn>,
syzbot+a53c2918175b36cfd601@syzkaller.appspotmail.com,
stable@vger.kernel.org
Subject: [PATCH] md: fix NULL dereference of pers in md_start_sync()
Date: Fri, 6 Nov 2026 16:35:43 +0800 [thread overview]
Message-ID: <20261106083543.249267-1-dayou5941@163.com> (raw)
From: Li Youhong <liyouhong@kylinos.cn>
md_start_sync() is queued on md_misc_wq to start resync or to
manage spare disks. On a read-only array it calls
remove_and_add_spares(), which ends up in remove_spares() and
invokes pers->hot_remove_disk.
md_start_sync() does not check whether mddev->pers is still
valid before using it. dm-raid stops the array through
md_stop(), which clears pers. If the queued work then runs,
remove_spares() dereferences pers->hot_remove_disk and crashes.
The read-write path has the same exposure in
md_choose_sync_action().
Return via not_running if pers is already gone.
Fixes: db5e653d7c9f ("md: delay choosing sync action to md_start_sync()")
Reported-by: syzbot+a53c2918175b36cfd601@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a53c2918175b36cfd601
Cc: stable@vger.kernel.org
Signed-off-by: Li Youhong <liyouhong@kylinos.cn>
---
drivers/md/md.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 680b34a63cb3..b7e162f52408 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -10286,6 +10286,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;
+
if (!md_is_rdwr(mddev)) {
/*
* On a read-only array we can:
--
2.25.1
next reply other threads:[~2026-11-06 8:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 8:35 Li Youhong [this message]
2026-11-06 8:53 ` [PATCH] md: fix NULL dereference of pers in md_start_sync() sashiko-bot
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=20261106083543.249267-1-dayou5941@163.com \
--to=dayou5941@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=liyouhong@kylinos.cn \
--cc=magiclinan@didiglobal.com \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+a53c2918175b36cfd601@syzkaller.appspotmail.com \
--cc=xiao@kernel.org \
--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