KVM: x86/mmu: avoid NULL-pointer dereference on page freeing bugs
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 9 Feb 2022 00:08:33 +0000 (19:08 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 May 2022 10:30:25 +0000 (12:30 +0200)
commit8e10a00b18769a757af763d4f55c4204200f44ef
treee1aa1e68c711245deae02bb73c35d23d48850343
parent6b68f26a6556ed51c892fbc07ddf7a25d7c1e2f5
KVM: x86/mmu: avoid NULL-pointer dereference on page freeing bugs

[ Upstream commit 9191b8f0745e63edf519e4a54a4aaae1d3d46fbd ]

WARN and bail if KVM attempts to free a root that isn't backed by a shadow
page.  KVM allocates a bare page for "special" roots, e.g. when using PAE
paging or shadowing 2/3/4-level page tables with 4/5-level, and so root_hpa
will be valid but won't be backed by a shadow page.  It's all too easy to
blindly call mmu_free_root_page() on root_hpa, be nice and WARN instead of
crashing KVM and possibly the kernel.

Reviewed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/kvm/mmu/mmu.c