Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH] md: fix NULL dereference of pers in md_start_sync()
@ 2026-11-06  8:35 Li Youhong
  2026-11-06  8:53 ` sashiko-bot
  2026-11-08  3:14 ` yu kuai
  0 siblings, 2 replies; 3+ messages in thread
From: Li Youhong @ 2026-11-06  8:35 UTC (permalink / raw)
  To: song, yukuai
  Cc: magiclinan, xiao, linux-raid, linux-kernel, Li Youhong,
	syzbot+a53c2918175b36cfd601, stable

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-08  3:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-08  3:14 ` yu kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox