Skip to content

Commit 70c8327

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86: Bug the VM if an accelerated x2APIC trap occurs on a "bad" reg
Bug the VM if retrieving the x2APIC MSR/register while processing an accelerated vAPIC trap VM-Exit fails. In theory it's impossible for the lookup to fail as hardware has already validated the register, but bugs happen, and not checking the result of kvm_lapic_msr_read() would result in consuming the uninitialized "val" if a KVM or hardware bug occurs. Fixes: 1bd9dfe ("KVM: x86: Do not block APIC write for non ICR registers") Reported-by: Dan Carpenter <[email protected]> Cc: Suravee Suthikulpanit <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c3c28d2 commit 70c8327

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arch/x86/kvm/lapic.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,10 +2284,12 @@ void kvm_apic_write_nodecode(struct kvm_vcpu *vcpu, u32 offset)
22842284
struct kvm_lapic *apic = vcpu->arch.apic;
22852285
u64 val;
22862286

2287-
if (apic_x2apic_mode(apic))
2288-
kvm_lapic_msr_read(apic, offset, &val);
2289-
else
2287+
if (apic_x2apic_mode(apic)) {
2288+
if (KVM_BUG_ON(kvm_lapic_msr_read(apic, offset, &val), vcpu->kvm))
2289+
return;
2290+
} else {
22902291
val = kvm_lapic_get_reg(apic, offset);
2292+
}
22912293

22922294
/*
22932295
* ICR is a single 64-bit register when x2APIC is enabled. For legacy

0 commit comments

Comments
 (0)