[PATCH] md: suspend the array before slot_store() removes a device

From: Miroslav Cimerman

Date: Thu Dec 03 2026 - 20:59:05 EST


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@xxxxxxxxxx>
Closes: https://sashiko.dev/#/patchset/20261127003231.1180197-1-mc@xxxxxxxxxxx?part=7
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
---
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