All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Michal Luczaj <mhal@rbox.co>,
	Sean Christopherson <seanjc@google.com>,
	Yu Zhang <yu.c.zhang@linux.intel.com>,
	kvm@vger.kernel.org, Paul Durrant <paul@xen.org>
Subject: [PATCH 1/6] KVM: x86/xen: Fix memory leak in kvm_xen_write_hypercall_page()
Date: Mon, 26 Dec 2022 12:03:15 +0000	[thread overview]
Message-ID: <20221226120320.1125390-1-dwmw2@infradead.org> (raw)
In-Reply-To: <b36fa02bc338d6892e63e37768bf47f035339e30.camel@infradead.org>

From: Michal Luczaj <mhal@rbox.co>

Release page irrespectively of kvm_vcpu_write_guest() return value.

Suggested-by: Paul Durrant <paul@xen.org>
Fixes: 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled")
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Message-Id: <20221220151454.712165-1-mhal@rbox.co>
Reviewed-by: Paul Durrant <paul@xen.org>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 arch/x86/kvm/xen.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index d7af40240248..d1a98d834d18 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -1069,6 +1069,7 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
 		u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
 				  : kvm->arch.xen_hvm_config.blob_size_32;
 		u8 *page;
+		int ret;
 
 		if (page_num >= blob_size)
 			return 1;
@@ -1079,10 +1080,10 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
 		if (IS_ERR(page))
 			return PTR_ERR(page);
 
-		if (kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE)) {
-			kfree(page);
+		ret = kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE);
+		kfree(page);
+		if (ret)
 			return 1;
-		}
 	}
 	return 0;
 }
-- 
2.35.3


  reply	other threads:[~2022-12-26 12:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-24  8:53 [PATCH] KVM: x86/xen: Fix SRCU/RCU usage in readers of evtchn_ports Paolo Bonzini
2022-12-24 10:54 ` David Woodhouse
2022-12-26 11:21 ` David Woodhouse
2022-12-26 12:03   ` David Woodhouse [this message]
2022-12-26 12:03     ` [PATCH 2/6] KVM: x86/xen: Use kvm_read_guest_virt() instead of open-coding it badly David Woodhouse
2022-12-26 12:03     ` [PATCH 3/6] KVM: x86/xen: Fix SRCU/RCU usage in readers of evtchn_ports David Woodhouse
2022-12-26 12:03     ` [PATCH 4/6] KVM: x86/xen: Simplify eventfd IOCTLs David Woodhouse
2022-12-26 12:03     ` [PATCH 5/6] KVM: x86/xen: Add KVM_XEN_INVALID_GPA and KVM_XEN_INVALID_GFN to uapi David Woodhouse
2022-12-26 12:03     ` [PATCH 6/6] KVM: x86/xen: Documentation updates and clarifications David Woodhouse
2022-12-27 11:02     ` [PATCH 1/6] KVM: x86/xen: Fix memory leak in kvm_xen_write_hypercall_page() Paolo Bonzini

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=20221226120320.1125390-1-dwmw2@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=mhal@rbox.co \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=yu.c.zhang@linux.intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.