linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Xiaolong Huang <butterflyhuangxx@gmail.com>
Cc: fei1.li@intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] virt: acrn: fix a memory leak in acrn_dev_ioctl()
Date: Tue, 8 Mar 2022 10:56:08 +0100	[thread overview]
Message-ID: <YicoOC+WZhNLq+pX@kroah.com> (raw)
In-Reply-To: <20220308092047.1008409-1-butterflyhuangxx@gmail.com>

On Tue, Mar 08, 2022 at 05:20:47PM +0800, Xiaolong Huang wrote:
> The vm_param and cpu_regs need to be freed via kfree()
> before return -EINVAL error.
> 
> Fixes: 9c5137aedd11 ("virt: acrn: Introduce VM management interfaces")
> Fixes: 2ad2aaee1bc9 ("virt: acrn: Introduce an ioctl to set vCPU registers state")
> Signed-off-by: Xiaolong Huang <butterflyhuangxx@gmail.com>
> Signed-off-by: Fei Li <fei1.li@intel.com>
> ---
>  drivers/virt/acrn/hsm.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c
> index 5419794fccf1..423ea888d79a 100644
> --- a/drivers/virt/acrn/hsm.c
> +++ b/drivers/virt/acrn/hsm.c
> @@ -136,8 +136,10 @@ static long acrn_dev_ioctl(struct file *filp, unsigned int cmd,
>  		if (IS_ERR(vm_param))
>  			return PTR_ERR(vm_param);
>  
> -		if ((vm_param->reserved0 | vm_param->reserved1) != 0)
> +		if ((vm_param->reserved0 | vm_param->reserved1) != 0) {
> +			kfree(vm_param);
>  			return -EINVAL;
> +		}
>  
>  		vm = acrn_vm_create(vm, vm_param);
>  		if (!vm) {
> @@ -182,21 +184,29 @@ static long acrn_dev_ioctl(struct file *filp, unsigned int cmd,
>  			return PTR_ERR(cpu_regs);
>  
>  		for (i = 0; i < ARRAY_SIZE(cpu_regs->reserved); i++)
> -			if (cpu_regs->reserved[i])
> +			if (cpu_regs->reserved[i]) {
> +				kfree(cpu_regs);
>  				return -EINVAL;
> +			}
>  
>  		for (i = 0; i < ARRAY_SIZE(cpu_regs->vcpu_regs.reserved_32); i++)
> -			if (cpu_regs->vcpu_regs.reserved_32[i])
> +			if (cpu_regs->vcpu_regs.reserved_32[i]) {
> +				kfree(cpu_regs);
>  				return -EINVAL;
> +			}
>  
>  		for (i = 0; i < ARRAY_SIZE(cpu_regs->vcpu_regs.reserved_64); i++)
> -			if (cpu_regs->vcpu_regs.reserved_64[i])
> +			if (cpu_regs->vcpu_regs.reserved_64[i]) {
> +				kfree(cpu_regs);
>  				return -EINVAL;
> +			}
>  
>  		for (i = 0; i < ARRAY_SIZE(cpu_regs->vcpu_regs.gdt.reserved); i++)
>  			if (cpu_regs->vcpu_regs.gdt.reserved[i] |
> -			    cpu_regs->vcpu_regs.idt.reserved[i])
> +			    cpu_regs->vcpu_regs.idt.reserved[i]) {
> +				kfree(cpu_regs);
>  				return -EINVAL;
> +			}
>  
>  		ret = hcall_set_vcpu_regs(vm->vmid, virt_to_phys(cpu_regs));
>  		if (ret < 0)
> 
> base-commit: 5859a2b1991101d6b978f3feb5325dad39421f29
> -- 
> 2.25.1
> 

How did you test this?

  reply	other threads:[~2022-03-08  9:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08  9:20 [PATCH] virt: acrn: fix a memory leak in acrn_dev_ioctl() Xiaolong Huang
2022-03-08  9:56 ` Greg KH [this message]
2022-03-08 10:14   ` butt3rflyh4ck
2022-03-08 10:16     ` Greg KH
2022-03-15  2:44       ` butt3rflyh4ck
2022-03-15  6:49         ` Greg KH
2022-03-15  7:36           ` butt3rflyh4ck
2022-03-15  7:50             ` Greg KH
2022-03-15  8:04   ` butt3rflyh4ck
  -- strict thread matches above, loose matches on Subject: below --
2022-03-01 10:00 Xiaolong Huang
2022-03-03  6:01 ` Li Fei1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YicoOC+WZhNLq+pX@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=butterflyhuangxx@gmail.com \
    --cc=fei1.li@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).