diff options
author | Michal Luczaj <[email protected]> | 2022-12-26 12:03:15 +0000 |
---|---|---|
committer | Paolo Bonzini <[email protected]> | 2022-12-27 06:01:48 -0500 |
commit | 385407a69d5140825d4cdab814cbf128ba63a64a (patch) | |
tree | ad20fd284404a5307883eaac513885fa352f5dca | |
parent | 23e528d9bce2385967370ad95a7d52a3c7a0a016 (diff) |
KVM: x86/xen: Fix memory leak in kvm_xen_write_hypercall_page()
Release page irrespectively of kvm_vcpu_write_guest() return value.
Suggested-by: Paul Durrant <[email protected]>
Fixes: 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled")
Signed-off-by: Michal Luczaj <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Paul Durrant <[email protected]>
Signed-off-by: David Woodhouse <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
-rw-r--r-- | arch/x86/kvm/xen.c | 7 |
1 files 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; } |