mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] md: suspend the array before slot_store() removes a device
@ 2026-12-04  1:58 Miroslav Cimerman
  0 siblings, 0 replies; only message in thread
From: Miroslav Cimerman @ 2026-12-04  1:58 UTC (permalink / raw)
  To: Song Liu, Yu Kuai; +Cc: Li Nan, Xiao Ni, linux-raid, linux-kernel

Writing "none" to a member's slot removes the device without suspending
the array. raid1 and raid10 rely on suspend to keep a device in its
slot while a write uses it. A write that read the device before the
removal takes its reference after it. The write then dereferences the
cleared slot, which is NULL.

Suspend the array for "none", as rdev_attr_store() already does when
"remove" is written to the state.

Fixes: c891f1fd90e6 ("md: remove flag RemoveSynchronized")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20261127003231.1180197-1-mc@raidlab.org?part=7
Cc: stable@vger.kernel.org
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
The new check uses strncmp() like slot_store(), so the array is
suspended for every input that removes the device. Would you prefer
cmd_match() in both places instead or is this ok?

Reproduced on md-7.5 with a test-only delay before the write takes the
reference: KASAN NULL pointer dereference without this patch.

Prepared with help from an LLM.

 drivers/md/md.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index c71c3b043496..667e3b5d1ba3 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3779,6 +3779,12 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
 		    cmd_match(page, "-writemostly"))
 			suspend = true;
 	}
+	/*
+	 * slot_store() removes the device for "none". Removing needs the array
+	 * suspended, like the state_store() commands above.
+	 */
+	if (entry->store == slot_store && !strncmp(page, "none", 4))
+		suspend = true;
 
 	rv = suspend ? mddev_suspend_and_lock(mddev) : mddev_lock(mddev);
 	if (!rv) {

base-commit: c526b7cd32f75fea6021ffdab287b81cf38ddeb7
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04  1:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04  1:58 [PATCH] md: suspend the array before slot_store() removes a device Miroslav Cimerman

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

all inboxes | Powered by JetHome®