mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid
@ 2025-11-16  2:18 Yu Kuai
  2025-11-17  0:36 ` Xiao Ni
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Yu Kuai @ 2025-11-16  2:18 UTC (permalink / raw)
  To: song, linux-raid, linux-kernel; +Cc: yukuai, linan122, xni, czhong

Commit 2107457e31fa ("md/raid0: Move queue limit setup before r0conf
initialization") dereference mddev->gendisk unconditionally, which is
NULL for dm-raid.

Fix this problem by reverting to old codes for dm-raid.

Fixes: 2107457e31fa ("md/raid0: Move queue limit setup before r0conf initialization")
Reported-and-tested-by: Changhui Zhong <czhong@redhat.com>
Closes: https://lore.kernel.org/all/CAGVVp+VqVnvGeneUoTbYvBv2cw6GwQRrR3B-iQ-_9rVfyumoKA@mail.gmail.com/
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
---
 drivers/md/raid0.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 47aee1b1d4d1..985c377356eb 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -68,7 +68,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
 	struct strip_zone *zone;
 	int cnt;
 	struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
-	unsigned int blksize = queue_logical_block_size(mddev->gendisk->queue);
+	unsigned int blksize = 512;
+
+	if (!mddev_is_dm(mddev))
+		blksize = queue_logical_block_size(mddev->gendisk->queue);
 
 	*private_conf = ERR_PTR(-ENOMEM);
 	if (!conf)
@@ -84,6 +87,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
 		sector_div(sectors, mddev->chunk_sectors);
 		rdev1->sectors = sectors * mddev->chunk_sectors;
 
+		if (mddev_is_dm(mddev))
+			blksize = max(blksize, queue_logical_block_size(
+				      rdev1->bdev->bd_disk->queue));
+
 		rdev_for_each(rdev2, mddev) {
 			pr_debug("md/raid0:%s:   comparing %pg(%llu)"
 				 " with %pg(%llu)\n",
-- 
2.51.0

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

* Re: [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid
  2025-11-16  2:18 [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid Yu Kuai
@ 2025-11-17  0:36 ` Xiao Ni
  2025-11-17  6:57 ` Li Nan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Xiao Ni @ 2025-11-17  0:36 UTC (permalink / raw)
  To: Yu Kuai; +Cc: song, linux-raid, linux-kernel, linan122, czhong

On Sun, Nov 16, 2025 at 10:18 AM Yu Kuai <yukuai@fnnas.com> wrote:
>
> Commit 2107457e31fa ("md/raid0: Move queue limit setup before r0conf
> initialization") dereference mddev->gendisk unconditionally, which is
> NULL for dm-raid.
>
> Fix this problem by reverting to old codes for dm-raid.
>
> Fixes: 2107457e31fa ("md/raid0: Move queue limit setup before r0conf initialization")
> Reported-and-tested-by: Changhui Zhong <czhong@redhat.com>
> Closes: https://lore.kernel.org/all/CAGVVp+VqVnvGeneUoTbYvBv2cw6GwQRrR3B-iQ-_9rVfyumoKA@mail.gmail.com/
> Signed-off-by: Yu Kuai <yukuai@fnnas.com>
> ---
>  drivers/md/raid0.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index 47aee1b1d4d1..985c377356eb 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -68,7 +68,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>         struct strip_zone *zone;
>         int cnt;
>         struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
> -       unsigned int blksize = queue_logical_block_size(mddev->gendisk->queue);
> +       unsigned int blksize = 512;
> +
> +       if (!mddev_is_dm(mddev))
> +               blksize = queue_logical_block_size(mddev->gendisk->queue);
>
>         *private_conf = ERR_PTR(-ENOMEM);
>         if (!conf)
> @@ -84,6 +87,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>                 sector_div(sectors, mddev->chunk_sectors);
>                 rdev1->sectors = sectors * mddev->chunk_sectors;
>
> +               if (mddev_is_dm(mddev))
> +                       blksize = max(blksize, queue_logical_block_size(
> +                                     rdev1->bdev->bd_disk->queue));
> +
>                 rdev_for_each(rdev2, mddev) {
>                         pr_debug("md/raid0:%s:   comparing %pg(%llu)"
>                                  " with %pg(%llu)\n",
> --
> 2.51.0
>

Hi all, the patch looks good to me.

Reviewed-by: Xiao Ni <xni@redhat.com>


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

* Re: [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid
  2025-11-16  2:18 [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid Yu Kuai
  2025-11-17  0:36 ` Xiao Ni
@ 2025-11-17  6:57 ` Li Nan
  2025-11-17 16:57 ` Paul Menzel
  2025-11-30  1:48 ` Yu Kuai
  3 siblings, 0 replies; 5+ messages in thread
From: Li Nan @ 2025-11-17  6:57 UTC (permalink / raw)
  To: Yu Kuai, song, linux-raid, linux-kernel; +Cc: xni, czhong



在 2025/11/16 10:18, Yu Kuai 写道:
> Commit 2107457e31fa ("md/raid0: Move queue limit setup before r0conf
> initialization") dereference mddev->gendisk unconditionally, which is
> NULL for dm-raid.
> 
> Fix this problem by reverting to old codes for dm-raid.
> 
> Fixes: 2107457e31fa ("md/raid0: Move queue limit setup before r0conf initialization")
> Reported-and-tested-by: Changhui Zhong <czhong@redhat.com>
> Closes: https://lore.kernel.org/all/CAGVVp+VqVnvGeneUoTbYvBv2cw6GwQRrR3B-iQ-_9rVfyumoKA@mail.gmail.com/
> Signed-off-by: Yu Kuai <yukuai@fnnas.com>
> ---
>   drivers/md/raid0.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index 47aee1b1d4d1..985c377356eb 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -68,7 +68,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>   	struct strip_zone *zone;
>   	int cnt;
>   	struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
> -	unsigned int blksize = queue_logical_block_size(mddev->gendisk->queue);
> +	unsigned int blksize = 512;
> +
> +	if (!mddev_is_dm(mddev))
> +		blksize = queue_logical_block_size(mddev->gendisk->queue);
>   
>   	*private_conf = ERR_PTR(-ENOMEM);
>   	if (!conf)
> @@ -84,6 +87,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>   		sector_div(sectors, mddev->chunk_sectors);
>   		rdev1->sectors = sectors * mddev->chunk_sectors;
>   
> +		if (mddev_is_dm(mddev))
> +			blksize = max(blksize, queue_logical_block_size(
> +				      rdev1->bdev->bd_disk->queue));
> +
>   		rdev_for_each(rdev2, mddev) {
>   			pr_debug("md/raid0:%s:   comparing %pg(%llu)"
>   				 " with %pg(%llu)\n",

LGTM

Reviewed-by: Li Nan <linan122@huawei.com>
-- 
Thanks,
Nan


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

* Re: [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid
  2025-11-16  2:18 [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid Yu Kuai
  2025-11-17  0:36 ` Xiao Ni
  2025-11-17  6:57 ` Li Nan
@ 2025-11-17 16:57 ` Paul Menzel
  2025-11-30  1:48 ` Yu Kuai
  3 siblings, 0 replies; 5+ messages in thread
From: Paul Menzel @ 2025-11-17 16:57 UTC (permalink / raw)
  To: Yu Kuai; +Cc: song, linux-raid, linux-kernel, linan122, xni, czhong

Dear Kuai,


Thank you for your patch.

Am 16.11.25 um 03:18 schrieb Yu Kuai:
> Commit 2107457e31fa ("md/raid0: Move queue limit setup before r0conf
> initialization") dereference mddev->gendisk unconditionally, which is
> NULL for dm-raid.
> 
> Fix this problem by reverting to old codes for dm-raid.
> 
> Fixes: 2107457e31fa ("md/raid0: Move queue limit setup before r0conf initialization")
> Reported-and-tested-by: Changhui Zhong <czhong@redhat.com>
> Closes: https://lore.kernel.org/all/CAGVVp+VqVnvGeneUoTbYvBv2cw6GwQRrR3B-iQ-_9rVfyumoKA@mail.gmail.com/
> Signed-off-by: Yu Kuai <yukuai@fnnas.com>
> ---
>   drivers/md/raid0.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index 47aee1b1d4d1..985c377356eb 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -68,7 +68,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>   	struct strip_zone *zone;
>   	int cnt;
>   	struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
> -	unsigned int blksize = queue_logical_block_size(mddev->gendisk->queue);
> +	unsigned int blksize = 512;
> +
> +	if (!mddev_is_dm(mddev))
> +		blksize = queue_logical_block_size(mddev->gendisk->queue);
>   
>   	*private_conf = ERR_PTR(-ENOMEM);
>   	if (!conf)
> @@ -84,6 +87,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>   		sector_div(sectors, mddev->chunk_sectors);
>   		rdev1->sectors = sectors * mddev->chunk_sectors;
>   
> +		if (mddev_is_dm(mddev))
> +			blksize = max(blksize, queue_logical_block_size(
> +				      rdev1->bdev->bd_disk->queue));
> +
>   		rdev_for_each(rdev2, mddev) {
>   			pr_debug("md/raid0:%s:   comparing %pg(%llu)"
>   				 " with %pg(%llu)\n",

Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>


Kind regards,

Paul

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

* Re: [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid
  2025-11-16  2:18 [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid Yu Kuai
                   ` (2 preceding siblings ...)
  2025-11-17 16:57 ` Paul Menzel
@ 2025-11-30  1:48 ` Yu Kuai
  3 siblings, 0 replies; 5+ messages in thread
From: Yu Kuai @ 2025-11-30  1:48 UTC (permalink / raw)
  To: song, linux-raid, linux-kernel, Yu Kuai; +Cc: linan122, xni, czhong

在 2025/11/16 10:18, Yu Kuai 写道:
> Commit 2107457e31fa ("md/raid0: Move queue limit setup before r0conf
> initialization") dereference mddev->gendisk unconditionally, which is
> NULL for dm-raid.
>
> Fix this problem by reverting to old codes for dm-raid.
>
> Fixes: 2107457e31fa ("md/raid0: Move queue limit setup before r0conf initialization")
> Reported-and-tested-by: Changhui Zhong <czhong@redhat.com>
> Closes: https://lore.kernel.org/all/CAGVVp+VqVnvGeneUoTbYvBv2cw6GwQRrR3B-iQ-_9rVfyumoKA@mail.gmail.com/
> Signed-off-by: Yu Kuai <yukuai@fnnas.com>
> ---
>   drivers/md/raid0.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
> index 47aee1b1d4d1..985c377356eb 100644
> --- a/drivers/md/raid0.c
> +++ b/drivers/md/raid0.c
> @@ -68,7 +68,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>   	struct strip_zone *zone;
>   	int cnt;
>   	struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
> -	unsigned int blksize = queue_logical_block_size(mddev->gendisk->queue);
> +	unsigned int blksize = 512;
> +
> +	if (!mddev_is_dm(mddev))
> +		blksize = queue_logical_block_size(mddev->gendisk->queue);
>   
>   	*private_conf = ERR_PTR(-ENOMEM);
>   	if (!conf)
> @@ -84,6 +87,10 @@ static int create_strip_zones(struct mddev *mddev, struct r0conf **private_conf)
>   		sector_div(sectors, mddev->chunk_sectors);
>   		rdev1->sectors = sectors * mddev->chunk_sectors;
>   
> +		if (mddev_is_dm(mddev))
> +			blksize = max(blksize, queue_logical_block_size(
> +				      rdev1->bdev->bd_disk->queue));
> +
>   		rdev_for_each(rdev2, mddev) {
>   			pr_debug("md/raid0:%s:   comparing %pg(%llu)"
>   				 " with %pg(%llu)\n",

Applied to md-6.19

-- 
Thanks,
Kuai

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

end of thread, other threads:[~2025-11-30  1:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-16  2:18 [PATCH] md/raid0: fix NULL pointer dereference in create_strip_zones() for dm-raid Yu Kuai
2025-11-17  0:36 ` Xiao Ni
2025-11-17  6:57 ` Li Nan
2025-11-17 16:57 ` Paul Menzel
2025-11-30  1:48 ` Yu Kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®