md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()
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
@@ -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
Hi,
Quoted 30 lines · Tuo Li
The variable
mddev->privateis first assigned to conf and then checked:conf = mddev->private; if (!conf) ...If conf is NULL, then
mddev->privateis also NULL. However, the function does not return at this point, andraid5_quiesce()is later called with mddev as the argument. Insideraid5_quiesce(),mddev->privateis 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 <[email protected]>--- drivers/md/raid5.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/md/raid5.c +0
-0
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
Hi Kuai,
Quoted 51 lines · Yu Kuai
Hi,
Quoted 30 lines · Tuo Li
The variable
mddev->privateis first assigned to conf and then checked:conf = mddev->private; if (!conf) ...If conf is NULL, then
mddev->privateis also NULL. However, the function does not return at this point, andraid5_quiesce()is later called with mddev as the argument. Insideraid5_quiesce(),mddev->privateis 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 <[email protected]>--- drivers/md/raid5.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/md/raid5.c +0
-0drivers/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:
fa1944bbe622md/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