The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Tuo Li <islituo@gmail.com>
To: song@kernel.org, yukuai@fnnas.com
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tuo Li <islituo@gmail.com>
Subject: [PATCH] md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()
Date: Wed, 10 Dec 2025 15:41:12 +0800	[thread overview]
Message-ID: <20251210074112.3975053-1-islituo@gmail.com> (raw)

The variable mddev->private is first assigned to conf and then checked:

  conf = mddev->private;
  if (!conf) ...

If conf is NULL, then mddev->private is also NULL. However, the function
does not return at this point, and raid5_quiesce() is later called with
mddev as the argument. Inside raid5_quiesce(), mddev->private is again
assigned to conf, which is then dereferenced in multiple places, for
example:

  conf->quiesce = 0;
  wake_up(&conf->wait_for_quiescent);
  ...

This can lead to several null-pointer dereferences.

To fix these issues, the function should unlock mddev and return early when
conf is NULL, following the pattern in raid5_change_consistency_policy().

Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/md/raid5.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index e57ce3295292..be3f9a127212 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7190,9 +7190,10 @@ raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len)
 	raid5_quiesce(mddev, true);
 
 	conf = mddev->private;
-	if (!conf)
-		err = -ENODEV;
-	else if (new != conf->worker_cnt_per_group) {
+	if (!conf) {
+		mddev_unlock_and_resume(mddev);
+		return -ENODEV;
+	} else if (new != conf->worker_cnt_per_group) {
 		old_groups = conf->worker_groups;
 		if (old_groups)
 			flush_workqueue(raid5_wq);
-- 
2.43.0


             reply	other threads:[~2025-12-10  7:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10  7:41 Tuo Li [this message]
2025-12-25  7:40 ` [PATCH] md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt() Yu Kuai
2025-12-25 12:34   ` Tuo Li

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=20251210074112.3975053-1-islituo@gmail.com \
    --to=islituo@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=yukuai@fnnas.com \
    /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