Skip to content

Commit 9f46c18

Browse files
committed
KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID
With shadow paging enabled, the INVPCID instruction results in a call to kvm_mmu_invpcid_gva. If INVPCID is executed with CR0.PG=0, the invlpg callback is not set and the result is a NULL pointer dereference. Fix it trivially by checking for mmu->invlpg before every call. There are other possibilities: - check for CR0.PG, because KVM (like all Intel processors after P5) flushes guest TLB on CR0.PG changes so that INVPCID/INVLPG are a nop with paging disabled - check for EFER.LMA, because KVM syncs and flushes when switching MMU contexts outside of 64-bit mode All of these are tricky, go for the simple solution. This is CVE-2022-1789. Reported-by: Yongkang Jia <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent ea8c66f commit 9f46c18

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5470,14 +5470,16 @@ void kvm_mmu_invpcid_gva(struct kvm_vcpu *vcpu, gva_t gva, unsigned long pcid)
54705470
uint i;
54715471

54725472
if (pcid == kvm_get_active_pcid(vcpu)) {
5473-
mmu->invlpg(vcpu, gva, mmu->root.hpa);
5473+
if (mmu->invlpg)
5474+
mmu->invlpg(vcpu, gva, mmu->root.hpa);
54745475
tlb_flush = true;
54755476
}
54765477

54775478
for (i = 0; i < KVM_MMU_NUM_PREV_ROOTS; i++) {
54785479
if (VALID_PAGE(mmu->prev_roots[i].hpa) &&
54795480
pcid == kvm_get_pcid(vcpu, mmu->prev_roots[i].pgd)) {
5480-
mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa);
5481+
if (mmu->invlpg)
5482+
mmu->invlpg(vcpu, gva, mmu->prev_roots[i].hpa);
54815483
tlb_flush = true;
54825484
}
54835485
}

0 commit comments

Comments
 (0)