lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251107065229.GA3932045@liuwe-devbox-debian-v2.local>
Date: Fri, 7 Nov 2025 06:52:29 +0000
From: Wei Liu <wei.liu@...nel.org>
To: Rahul Kumar <rk0006818@...il.com>
Cc: kys@...rosoft.com, haiyangz@...rosoft.com, wei.liu@...nel.org,
	decui@...rosoft.com, linux-hyperv@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-kernel-mentees@...ts.linux.dev,
	skhan@...uxfoundation.org
Subject: Re: [PATCH] drivers/hv: Use kmalloc_array() instead of kmalloc()

On Tue, Nov 04, 2025 at 05:46:18PM +0530, Rahul Kumar wrote:
> Documentation/process/deprecated.rst recommends against the use of
> kmalloc with dynamic size calculations due to the risk of overflow and
> smaller allocation being made than the caller was expecting.
> 
> Replace kmalloc() with kmalloc_array() in hv_common.c to make the
> intended allocation size clearer and avoid potential overflow issues.
> 
> The number of pages (pgcount) is bounded, so overflow is not a
> practical concern here. However, using kmalloc_array() better reflects
> the intent to allocate an array and improves consistency with other
> allocations.
> 
> No functional change intended.
> 
> Signed-off-by: Rahul Kumar <rk0006818@...il.com>

Applied to hyperv-next. Thanks.

> ---
>  drivers/hv/hv_common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index e109a620c83f..68689beb383c 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -487,7 +487,7 @@ int hv_common_cpu_init(unsigned int cpu)
>  	 * online and then taken offline
>  	 */
>  	if (!*inputarg) {
> -		mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags);
> +		mem = kmalloc_array(pgcount, HV_HYP_PAGE_SIZE, flags);
>  		if (!mem)
>  			return -ENOMEM;
>  
> -- 
> 2.43.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ