Skip to contentSkip to conversation

md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()

PATCH Superseded Tuo Li 2 participants 3 messages Dec 10, 2025 – Dec 25, 2025 MD RAID

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()

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().

---
 drivers/md/raid5.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/md/raid5.c +4 -3
index e57ce3295292..be3f9a127212 100644
@@ -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);
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 30 lines · Tuo Li

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().

---
  drivers/md/raid5.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/md/raid5.c +0 -0
index e57ce3295292..be3f9a127212 100644

drivers/md/raid5.c raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) · line 7195

Quoted 9 lines
drivers/md/raid5.c +3 -3
@@ -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;

+CC Xiao

This is still wrong, please add the NULL check and return early before raid5_quise(). And also add a fix tag:

fa1944bbe622 md/raid5: Wait sync io to finish before changing group cnt

Quoted 4 lines
drivers/md/raid5.c +1 -0
+	} else if (new != conf->worker_cnt_per_group) {
  		old_groups = conf->worker_groups;
  		if (old_groups)
  			flush_workqueue(raid5_wq);
Signature · 2 lines
Thansk,
Kuai
author
#2 lore raw

Hi Kuai,

Quoted 51 lines · Yu Kuai

Hi,

Quoted 30 lines · Tuo Li

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().

---
  drivers/md/raid5.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/md/raid5.c +0 -0
index e57ce3295292..be3f9a127212 100644

drivers/md/raid5.c raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) · line 7195

Quoted 9 lines
drivers/md/raid5.c +3 -3
@@ -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;

+CC Xiao

This is still wrong, please add the NULL check and return early before raid5_quise(). And also add a fix tag:

fa1944bbe622 md/raid5: Wait sync io to finish before changing group cnt

Quoted 8 lines

drivers/md/raid5.c raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) · line 7199

Quoted 4 lines
drivers/md/raid5.c +1 -0
+     } else if (new != conf->worker_cnt_per_group) {
              old_groups = conf->worker_groups;
              if (old_groups)
                      flush_workqueue(raid5_wq);

--
Thansk,
Kuai

Thanks for your reply!
I’ll prepare and submit a v2 patch shortly following your advice.

Sincerely,
Tuo