Commit b2740d35 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: ensure __gfn_to_pfn_memslot initializes *writable

For the kvm_is_error_hva, ubsan complains if the uninitialized writable
is passed to __direct_map, even though the value itself is not used
(__direct_map goes to mmu_set_spte->set_spte->set_mmio_spte but never
looks at that argument).

Ensuring that __gfn_to_pfn_memslot initializes *writable is cheap and
avoids this kind of issue.
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 107d44a2
...@@ -1434,11 +1434,17 @@ kvm_pfn_t __gfn_to_pfn_memslot(struct kvm_memory_slot *slot, gfn_t gfn, ...@@ -1434,11 +1434,17 @@ kvm_pfn_t __gfn_to_pfn_memslot(struct kvm_memory_slot *slot, gfn_t gfn,
{ {
unsigned long addr = __gfn_to_hva_many(slot, gfn, NULL, write_fault); unsigned long addr = __gfn_to_hva_many(slot, gfn, NULL, write_fault);
if (addr == KVM_HVA_ERR_RO_BAD) if (addr == KVM_HVA_ERR_RO_BAD) {
if (writable)
*writable = false;
return KVM_PFN_ERR_RO_FAULT; return KVM_PFN_ERR_RO_FAULT;
}
if (kvm_is_error_hva(addr)) if (kvm_is_error_hva(addr)) {
if (writable)
*writable = false;
return KVM_PFN_NOSLOT; return KVM_PFN_NOSLOT;
}
/* Do not map writable pfn in the readonly memslot. */ /* Do not map writable pfn in the readonly memslot. */
if (writable && memslot_is_readonly(slot)) { if (writable && memslot_is_readonly(slot)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment