[lvc-project] [PATCH] nullb: Adjust device size calculation in null_alloc_dev()

Zhu Yanjun yanjun.zhu at linux.dev
Tue Sep 17 10:21:02 MSK 2024


在 2024/9/17 15:07, Aleksandr Mishin 写道:
> In null_alloc_dev() device size is a subject to overflow because 'g_gb'
> (which is module parameter, may have any value and is not validated
> anywhere) is not cast to a larger data type before performing arithmetic.
>
> Cast 'g_gb' to unsigned long to prevent overflow.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 2984c8684f96 ("nullb: factor disk parameters")
> Signed-off-by: Aleksandr Mishin <amishin at t-argos.ru>
> ---
>   drivers/block/null_blk/main.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index 2f0431e42c49..5edbf9c0aceb 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -762,7 +762,7 @@ static struct nullb_device *null_alloc_dev(void)
>   		return NULL;
>   	}
>   
> -	dev->size = g_gb * 1024;

The member variable size in struct nullb_device is type "unsigned long".

As such, changing g_gb from int to "unsigned long" seems reasonable.

So I am fine with this.

Reviewed-by: Zhu Yanjun <yanjun.zhu at linux.dev>

Thanks a lot.

Zhu Yanjun

> +	dev->size = (unsigned long)g_gb * 1024;
>   	dev->completion_nsec = g_completion_nsec;
>   	dev->submit_queues = g_submit_queues;
>   	dev->prev_submit_queues = g_submit_queues;

-- 
Best Regards,
Yanjun.Zhu




More information about the lvc-project mailing list