public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: kvm: fix vector context allocation leak
@ 2026-03-14 22:31 Osama Abdelkader
  2026-03-16  9:23 ` Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Osama Abdelkader @ 2026-03-14 22:31 UTC (permalink / raw)
  To: Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, kvm, kvm-riscv, linux-riscv, linux-kernel
  Cc: Osama Abdelkader

When the second kzalloc (host_context.vector.datap) fails in
kvm_riscv_vcpu_alloc_vector_context, the first allocation
(guest_context.vector.datap) is leaked. Free it before returning.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 arch/riscv/kvm/vcpu_vector.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kvm/vcpu_vector.c b/arch/riscv/kvm/vcpu_vector.c
index 05f3cc2d8e31..5b6ad82d47be 100644
--- a/arch/riscv/kvm/vcpu_vector.c
+++ b/arch/riscv/kvm/vcpu_vector.c
@@ -80,8 +80,11 @@ int kvm_riscv_vcpu_alloc_vector_context(struct kvm_vcpu *vcpu)
 		return -ENOMEM;
 
 	vcpu->arch.host_context.vector.datap = kzalloc(riscv_v_vsize, GFP_KERNEL);
-	if (!vcpu->arch.host_context.vector.datap)
+	if (!vcpu->arch.host_context.vector.datap) {
+		kfree(vcpu->arch.guest_context.vector.datap);
+		vcpu->arch.guest_context.vector.datap = NULL;
 		return -ENOMEM;
+	}
 
 	return 0;
 }
-- 
2.43.0


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

* Re: [PATCH] riscv: kvm: fix vector context allocation leak
  2026-03-14 22:31 [PATCH] riscv: kvm: fix vector context allocation leak Osama Abdelkader
@ 2026-03-16  9:23 ` Markus Elfring
  2026-03-16 15:24   ` Osama Abdelkader
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2026-03-16  9:23 UTC (permalink / raw)
  To: Osama Abdelkader, kvm-riscv, linux-riscv, kvm, Albert Ou,
	Alexandre Ghiti, Anup Patel, Atish Patra, Palmer Dabbelt,
	Paul Walmsley
  Cc: LKML

> When the second kzalloc (host_context.vector.datap) fails in
> kvm_riscv_vcpu_alloc_vector_context, the first allocation
> (guest_context.vector.datap) is leaked. Free it before returning.

Were any source code analysis tools involved here?


How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc4#n145

Regards,
Markus

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

* Re: [PATCH] riscv: kvm: fix vector context allocation leak
  2026-03-16  9:23 ` Markus Elfring
@ 2026-03-16 15:24   ` Osama Abdelkader
  2026-03-16 16:36     ` Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Osama Abdelkader @ 2026-03-16 15:24 UTC (permalink / raw)
  To: Markus Elfring
  Cc: kvm-riscv, linux-riscv, kvm, Albert Ou, Alexandre Ghiti,
	Anup Patel, Atish Patra, Palmer Dabbelt, Paul Walmsley, LKML

On Mon, Mar 16, 2026 at 10:23:27AM +0100, Markus Elfring wrote:
> > When the second kzalloc (host_context.vector.datap) fails in
> > kvm_riscv_vcpu_alloc_vector_context, the first allocation
> > (guest_context.vector.datap) is leaked. Free it before returning.
> 
> Were any source code analysis tools involved here?
> 

No, there were found during manual review.

> 
> How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc4#n145
>

Done, I just sent v2, thank you.
 
> Regards,
> Markus

Best regards,
Osama

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

* Re: riscv: kvm: fix vector context allocation leak
  2026-03-16 15:24   ` Osama Abdelkader
@ 2026-03-16 16:36     ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-03-16 16:36 UTC (permalink / raw)
  To: Osama Abdelkader, kvm-riscv, linux-riscv, kvm
  Cc: Albert Ou, Alexandre Ghiti, Anup Patel, Atish Patra,
	Palmer Dabbelt, Paul Walmsley, LKML

>>> When the second kzalloc (host_context.vector.datap) fails in
>>> kvm_riscv_vcpu_alloc_vector_context, the first allocation
>>> (guest_context.vector.datap) is leaked. Free it before returning.
>> Were any source code analysis tools involved here?
>>
> No, there were found during manual review.

Would be looking for the support of advanced approaches
which would make such a “inspection” more convenient?

Regards,
Markus

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

end of thread, other threads:[~2026-03-16 16:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-14 22:31 [PATCH] riscv: kvm: fix vector context allocation leak Osama Abdelkader
2026-03-16  9:23 ` Markus Elfring
2026-03-16 15:24   ` Osama Abdelkader
2026-03-16 16:36     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox