FAILED: patch "[PATCH] KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID" failed to apply to 5.4-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9f46c187e2e680ecd9de7983e4d081c3391acc76 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Fri, 20 May 2022 13:48:11 -0400
Subject: [PATCH] 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.
arch/x86/kvm/mmu/mmu.c +4 -2
@@ -5470,14 +5470,16 @@ void kvm_mmu_invpcid_gva(struct kvm_vcpu *vcpu, gva_t gva, unsigned long pcid)uint i;if (pcid ==kvm_get_active_pcid (vcpu)) { - mmu->invlpg (vcpu, gva, mmu->root.hpa); +if (mmu->invlpg) + mmu->invlpg (vcpu, gva, mmu->root.hpa); tlb_flush = true; }for (i =0 ; i <KVM_MMU_NUM_PREV_ROOTS ; i++) {if (VALID_PAGE (mmu->prev_roots[i].hpa) && pcid ==kvm_get_pcid (vcpu, mmu->prev_roots[i].pgd)) { - mmu->invlpg (vcpu, gva, mmu->prev_roots[i].hpa); +if (mmu->invlpg) + mmu->invlpg (vcpu, gva, mmu->prev_roots[i].hpa); tlb_flush = true; } }
Quoted 8 lines · On 5/21/22 15:59, [email protected] wrote:
The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.thanks,
Quoted 9 lines
greg k-h
------------------ original commit in Linus's tree ------------------
Quoted 1 line
From
9f46c187e2e680ecd9de7983e4d081c3391acc76Mon Sep 17 00:00:00 2001From: Paolo Bonzini <[email protected]>
Date: Fri, 20 May 2022 13:48:11 -0400
Subject: [PATCH] KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID
I don't think 5.4 or earlier need this patch as (AFAICT) the bug was introduced by:
commit 5efac0741ce238e0844d3f7af00198f81e84926a
Author: Paolo Bonzini <[email protected]> Date: Mon Mar 23 20:42:57 2020 -0400
KVM: x86: introduce kvm_mmu_invalidate_gva
which was merged in v5.8 and has not been backported to v5.4.y or any earlier stable branch.
The reproducer does not crash on latest v5.4.y, which agrees with the above.
Vegard