mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-13 23:34:05 +08:00
virt: acrn: fix a memory leak in acrn_dev_ioctl()
The vm_param and cpu_regs need to be freed via kfree() before return -EINVAL error. Fixes:9c5137aedd
("virt: acrn: Introduce VM management interfaces") Fixes:2ad2aaee1b
("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> Link: https://lore.kernel.org/r/20220308092047.1008409-1-butterflyhuangxx@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
8a6e85f75a
commit
ecd1735f14
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user