From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.106 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796349536; b=PGCYoN9zh82rXECwPUV0smaBk1Oo4ZqmL+PjweGMsm+SbMfuJheCVTr3An/nidKrDJ7u 7DecJ6xwvxpP67aeg4dIZgLVg6ajaXBKXQ4MEUE5HnPnZ1/sHYCUT4PmYiit5DjBzKpIo WEB3oYcNThwOZrCULecw/zYoB/T4Ic9JtJILdsQOuxbUtzR8emEaDFc/U29HNQdNC1MeY nwxBb6EJkdz6a/j7TXwHtrTOOh+SgIcCSKcrcb+uVqVtNl0+58swbaw9qF8+n0wkAQJCR Z4ODbLUdqWoloPqhpNKFINycENSMECI8YMnEPs0nhi9BPXTddKfD5L6YJlBWS1ijJyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796349536; h=DMARC-Filter:DKIM-Signature:X-Pm-Submission-Id:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=dfn0irGp3pYN+6DkW25vQTOCGp6D8JwgNrUwqf0Ye9A=; b=KMKx+ZnHFWX6NMBX+7EdJLUOYDzfmE5nBU18PXun09W/xhN+zu7o+GvJMkrGwPtyk/Lv CVENmXQCuhSFxn9rKBk6SMMj5+ZJom9RQS+/0N1wJYGzqMUuiGXKeDvkZNx1gluFLJxcT /uWcQWBK9nCe519M9thEDhU7N54td4HzC/AjURjkfAU8xX2+6joBioHnYmw4q7krHMta4 0AnzqvsKbOXW+0fJC3cDyxr7LHC8SdULVshmRd90iDFUAO+RTJDBvDyJ2jaqAvKVWvNkO rjTnYecMSDnF0wA522rjTPJZOimUhTE6CRWzA4Gw9Z8+MvBnuGZmA1WGB6saCXTcxQQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=raidlab.org; spf=pass smtp.mailfrom=raidlab.org; dkim=pass header.d=raidlab.org header.i=@raidlab.org header.a=rsa-sha256 header.s=protonmail header.b=CHuMeWWJ; arc=none smtp.remote-ip=109.224.244.106 Received: from mail-244106.protonmail.ch (mail-244106.protonmail.ch [109.224.244.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D914606A322 for ; Fri, 4 Dec 2026 01:58:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3D914606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raidlab.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raidlab.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=raidlab.org header.i=@raidlab.org header.a=rsa-sha256 header.s=protonmail header.b=CHuMeWWJ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raidlab.org; s=protonmail; t=1796349533; x=1796608733; bh=dfn0irGp3pYN+6DkW25vQTOCGp6D8JwgNrUwqf0Ye9A=; h=From:To:Cc:Subject:Date:Message-ID:From:To:Cc:Date:Subject: Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=CHuMeWWJAx+MyVW5gps5uTQoKXtImo3Ras9Qwf41XqLgrD7OjGubGxlRgSYy62shH OLrFGbNrZj0+asDGnTRO7mDzNmHI/5auNGkm9BL/3Tux8YR8CPD8ru5c/xFq+wuodc 0LpTI1o5R92if1g/NoObp9/t+bsHO8IjFQHFAZratiJQ8XSRGcS4qoMbxLKnEJU+Na qJU6E5+kaVnQ7XUJu03FjS7Gy9hxT/zsi9iFKoPY8R90OM66qxZdvMFsW+E5wN6/9W w4eYT7zRnhlSoNCEl7LaVExI9Z2IrzyIEKpg8PRZdCQzz7w2M4lE0YRRA3nUjn8S3B SHSOc1Pg+xxdQ== X-Pm-Submission-Id: 4jgZRD6Ddqz2ScdF From: Miroslav Cimerman To: Song Liu , Yu Kuai Cc: Li Nan , Xiao Ni , 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 Message-ID: <20261204015835.1258975-1-mc@raidlab.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Closes: https://sashiko.dev/#/patchset/20261127003231.1180197-1-mc@raidlab.org?part=7 Cc: stable@vger.kernel.org Signed-off-by: Miroslav Cimerman --- 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