]> git.baikalelectronics.ru Git - kernel.git/commit
KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 20 May 2022 17:48:11 +0000 (13:48 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 30 May 2022 07:28:58 +0000 (09:28 +0200)
commit58bb69c3ed7c7b606edd07c8cf651510f1d40d71
treee1fc953787c1c4aa2b18c49a1584a005c9cfee42
parentc16cfe50bc05588ae3055a38e7d832683810dff4
KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID

commit 9d92d81746bbd23da80ef78906269bd8bb7ed053 upstream.

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 <kangel@zju.edu.cn>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[fix conflict due to missing 9b8852a7ef3229db20d44b5420c854e4a4434a14]
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/mmu/mmu.c