[PATCH next] Drivers: hv: mshv: Fix uninitialize variable in mshv_ioctl_passthru_hvcall()

Dan Carpenter posted 1 patch 9 months ago
drivers/hv/mshv_root_main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH next] Drivers: hv: mshv: Fix uninitialize variable in mshv_ioctl_passthru_hvcall()
Posted by Dan Carpenter 9 months ago
The "ret" variable could be uninitialized on the success path depending
on if "is_async" is true of false.  Initialized it to zero.

Fixes: f5288d14069b ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/hv/mshv_root_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
index 29fa6d5a3994..b94d8fe0f691 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -151,13 +151,14 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
 				      void __user *user_args)
 {
 	u64 status;
-	int ret, i;
 	bool is_async;
 	struct mshv_root_hvcall args;
 	struct page *page;
 	unsigned int pages_order;
 	void *input_pg = NULL;
 	void *output_pg = NULL;
+	int ret = 0;
+	int i;
 
 	if (copy_from_user(&args, user_args, sizeof(args)))
 		return -EFAULT;
-- 
2.47.2
Re: [PATCH next] Drivers: hv: mshv: Fix uninitialize variable in mshv_ioctl_passthru_hvcall()
Posted by Nuno Das Neves 9 months ago
On 3/21/2025 7:35 AM, Dan Carpenter wrote:
> The "ret" variable could be uninitialized on the success path depending
> on if "is_async" is true of false.  Initialized it to zero.
> 
> Fixes: f5288d14069b ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/hv/mshv_root_main.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index 29fa6d5a3994..b94d8fe0f691 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -151,13 +151,14 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
>  				      void __user *user_args)
>  {
>  	u64 status;
> -	int ret, i;
>  	bool is_async;
>  	struct mshv_root_hvcall args;
>  	struct page *page;
>  	unsigned int pages_order;
>  	void *input_pg = NULL;
>  	void *output_pg = NULL;
> +	int ret = 0;
> +	int i;
>  
>  	if (copy_from_user(&args, user_args, sizeof(args)))
>  		return -EFAULT;

Thanks Dan, I already sent a fixup for this:
https://lore.kernel.org/linux-hyperv/1742492693-21960-1-git-send-email-nunodasneves@linux.microsoft.com/