Skip to content

Commit ebbdf37

Browse files
peiliisean-jc
authored andcommitted
KVM: Validate hva in kvm_gpc_activate_hva() to fix __kvm_gpc_refresh() WARN
Check that the virtual address is "ok" when activating a gfn_to_pfn_cache with a host VA to ensure that KVM never attempts to use a bad address. This fixes a bug where KVM fails to check the incoming address when handling KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA in kvm_xen_vcpu_set_attr(). Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=fd555292a1da3180fc82 Tested-by: [email protected] Signed-off-by: Pei Li <[email protected]> Reviewed-by: Paul Durrant <[email protected]> Reviewed-by: David Woodhouse <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: rewrite changelog with --verbose] Signed-off-by: Sean Christopherson <[email protected]>
1 parent dee67a9 commit ebbdf37

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

arch/x86/kvm/xen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
741741
} else {
742742
void __user * hva = u64_to_user_ptr(data->u.shared_info.hva);
743743

744-
if (!PAGE_ALIGNED(hva) || !access_ok(hva, PAGE_SIZE)) {
744+
if (!PAGE_ALIGNED(hva)) {
745745
r = -EINVAL;
746746
} else if (!hva) {
747747
kvm_gpc_deactivate(&kvm->arch.xen.shinfo_cache);

virt/kvm/pfncache.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
430430

431431
int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long uhva, unsigned long len)
432432
{
433+
if (!access_ok((void __user *)uhva, len))
434+
return -EINVAL;
435+
433436
return __kvm_gpc_activate(gpc, INVALID_GPA, uhva, len);
434437
}
435438

0 commit comments

Comments
 (0)