Skip to content

Commit 385407a

Browse files
mmhalbonzini
authored andcommitted
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: 23200b7 ("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]>
1 parent 23e528d commit 385407a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/x86/kvm/xen.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
10691069
u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
10701070
: kvm->arch.xen_hvm_config.blob_size_32;
10711071
u8 *page;
1072+
int ret;
10721073

10731074
if (page_num >= blob_size)
10741075
return 1;
@@ -1079,10 +1080,10 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
10791080
if (IS_ERR(page))
10801081
return PTR_ERR(page);
10811082

1082-
if (kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE)) {
1083-
kfree(page);
1083+
ret = kvm_vcpu_write_guest(vcpu, page_addr, page, PAGE_SIZE);
1084+
kfree(page);
1085+
if (ret)
10841086
return 1;
1085-
}
10861087
}
10871088
return 0;
10881089
}

0 commit comments

Comments
 (0)