From: Miroslav Cimerman <mc@raidlab.org>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai@fygo.io>
Cc: Li Nan <magiclinan@didiglobal.com>, Xiao Ni <xiao@kernel.org>,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] md: suspend the array before slot_store() removes a device
Date: Fri, 4 Dec 2026 01:58:35 +0000 [thread overview]
Message-ID: <20261204015835.1258975-1-mc@raidlab.org> (raw)
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
reply other threads:[~2026-12-04 1:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204015835.1258975-1-mc@raidlab.org \
--to=mc@raidlab.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=magiclinan@didiglobal.com \
--cc=song@kernel.org \
--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
all inboxes | Powered by JetHome®