linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()
@ 2025-12-10  7:41 Tuo Li
  2025-12-25  7:40 ` Yu Kuai
  0 siblings, 1 reply; 3+ messages in thread
From: Tuo Li @ 2025-12-10  7:41 UTC (permalink / raw)
  To: song, yukuai; +Cc: linux-raid, linux-kernel, 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().

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()
  2025-12-10  7:41 [PATCH] md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt() Tuo Li
@ 2025-12-25  7:40 ` Yu Kuai
  2025-12-25 12:34   ` Tuo Li
  0 siblings, 1 reply; 3+ messages in thread
From: Yu Kuai @ 2025-12-25  7:40 UTC (permalink / raw)
  To: Tuo Li, song; +Cc: linux-raid, linux-kernel, xni, yukuai

Hi,

在 2025/12/10 15:41, 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().
>
> 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;

+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

> +	} else if (new != conf->worker_cnt_per_group) {
>   		old_groups = conf->worker_groups;
>   		if (old_groups)
>   			flush_workqueue(raid5_wq);

-- 
Thansk,
Kuai

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt()
  2025-12-25  7:40 ` Yu Kuai
@ 2025-12-25 12:34   ` Tuo Li
  0 siblings, 0 replies; 3+ messages in thread
From: Tuo Li @ 2025-12-25 12:34 UTC (permalink / raw)
  To: yukuai; +Cc: song, linux-raid, linux-kernel, xni

Hi Kuai,

On Thu, Dec 25, 2025 at 3:40 PM Yu Kuai <yukuai@fnnas.com> wrote:
>
> Hi,
>
> 在 2025/12/10 15:41, 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().
> >
> > 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;
>
> +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
>
> > +     } 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-25 12:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10  7:41 [PATCH] md/raid5: fix possible null-pointer dereferences in raid5_store_group_thread_cnt() Tuo Li
2025-12-25  7:40 ` Yu Kuai
2025-12-25 12:34   ` Tuo Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).