linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virt: acrn: fix memory leak in acrn_dev_ioctl()
@ 2022-01-04  8:53 Zhou Qingyang
  2022-01-04 10:18 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Zhou Qingyang @ 2022-01-04  8:53 UTC (permalink / raw)
  To: zhou1615
  Cc: kjlu, Fei Li, Greg Kroah-Hartman, Shuo Liu, Zhi Wang,
	Reinette Chatre, linux-kernel

In acrn_dev_ioctl(), cpu_regs is not released or passed out on several 
error paths which could lead to memory leak bug.

Fix this bug by adding kfree of cpu_regs on error paths.

This bug was found by a static analyzer.

Builds with CONFIG_ACRN_GUEST=y, CONFIG_ACRN_HSM=y show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: 2ad2aaee1bc9 ("virt: acrn: Introduce an ioctl to set vCPU registers state")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
The analysis employs differential checking to identify inconsistent
security operations (e.g., checks or kfrees) between two code paths
and confirms that the inconsistent operations are not recovered in
the current function or the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

 drivers/virt/acrn/hsm.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c
index 5419794fccf1..1eb0a17aadde 100644
--- a/drivers/virt/acrn/hsm.c
+++ b/drivers/virt/acrn/hsm.c
@@ -182,21 +182,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])
-				return -EINVAL;
+			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])
-				return -EINVAL;
+			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])
-				return -EINVAL;
+			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])
-				return -EINVAL;
+			    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)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] virt: acrn: fix memory leak in acrn_dev_ioctl()
  2022-01-04  8:53 [PATCH] virt: acrn: fix memory leak in acrn_dev_ioctl() Zhou Qingyang
@ 2022-01-04 10:18 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2022-01-04 10:18 UTC (permalink / raw)
  To: Zhou Qingyang
  Cc: kjlu, Fei Li, Shuo Liu, Zhi Wang, Reinette Chatre, linux-kernel

On Tue, Jan 04, 2022 at 04:53:21PM +0800, Zhou Qingyang wrote:
> In acrn_dev_ioctl(), cpu_regs is not released or passed out on several 
> error paths which could lead to memory leak bug.
> 
> Fix this bug by adding kfree of cpu_regs on error paths.
> 
> This bug was found by a static analyzer.
> 
> Builds with CONFIG_ACRN_GUEST=y, CONFIG_ACRN_HSM=y show no new warnings,
> and our static analyzer no longer warns about this code.
> 
> Fixes: 2ad2aaee1bc9 ("virt: acrn: Introduce an ioctl to set vCPU registers state")
> Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
> ---
> The analysis employs differential checking to identify inconsistent
> security operations (e.g., checks or kfrees) between two code paths
> and confirms that the inconsistent operations are not recovered in
> the current function or the callers, so they constitute bugs.
> 
> Note that, as a bug found by static analysis, it can be a false
> positive or hard to trigger. Multiple researchers have cross-reviewed
> the bug.

Then why have all of those researchers put their reviewed-by on this
change?

Note that your university is still in many kernel maintainer's
ignore-list (myself included, I dug this up as I saw Fei's response.)
Please work with your administration and the process that is currently
happening in order to give you all the needed training so you will not
keep causing these types of basic errors that keep your patches from
being accepted.

*plonk*

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-04 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04  8:53 [PATCH] virt: acrn: fix memory leak in acrn_dev_ioctl() Zhou Qingyang
2022-01-04 10:18 ` Greg Kroah-Hartman

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).