]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 2 Jun 2022 15:05:15 +0000 (18:05 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 22 Jun 2022 12:22:27 +0000 (14:22 +0200)
commit6d95fdebe4cc7373bd8e2ec7374576ea7839b2d8
tree0de6c4d9a55d33ad3b1b68dadc0f8285c54fc04a
parent57ae629b0d3aff943b3287602b7de2e98f94d184
KVM: x86/mmu: fix NULL pointer dereference on guest INVPCID

CVE-2022-1789

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>
(backported from commit 9f46c187e2e680ecd9de7983e4d081c3391acc76)
[cengizcan: use mmu->root_hpa instead of non-existing mmu->root.hpa]
[cengizcan: adapted for 5.15 due to path and context differences]
Signed-off-by: Cengiz Can <cengiz.can@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Acked-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/x86/kvm/mmu/mmu.c