kvm: Change offset in kvm_write_guest_offset_cached to unsigned
authorJim Mattson <jmattson@google.com>
Fri, 14 Dec 2018 22:34:43 +0000 (14:34 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 21 Dec 2018 10:28:22 +0000 (11:28 +0100)
commit7a86dab8cf2f0fdf508f3555dddfc236623bff60
treedb2444964b752655491d4a27e012f90d227f110f
parentf1b9dd5eb86cec1fcf66aad17e7701d98d024a9a
kvm: Change offset in kvm_write_guest_offset_cached to unsigned

Since the offset is added directly to the hva from the
gfn_to_hva_cache, a negative offset could result in an out of bounds
write. The existing BUG_ON only checks for addresses beyond the end of
the gfn_to_hva_cache, not for addresses before the start of the
gfn_to_hva_cache.

Note that all current call sites have non-negative offsets.

Fixes: 4ec6e8636256 ("kvm: Introduce kvm_write_guest_offset_cached()")
Reported-by: Cfir Cohen <cfir@google.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Cfir Cohen <cfir@google.com>
Reviewed-by: Peter Shier <pshier@google.com>
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
include/linux/kvm_host.h
virt/kvm/kvm_main.c