Skip to content

Commit 9191b8f

Browse files
committed
KVM: x86/mmu: avoid NULL-pointer dereference on page freeing bugs
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>
1 parent 57cb3bb commit 9191b8f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

arch/x86/kvm/mmu/mmu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,8 @@ static void mmu_free_root_page(struct kvm *kvm, hpa_t *root_hpa,
32063206
return;
32073207

32083208
sp = to_shadow_page(*root_hpa & PT64_BASE_ADDR_MASK);
3209+
if (WARN_ON(!sp))
3210+
return;
32093211

32103212
if (is_tdp_mmu_page(sp))
32113213
kvm_tdp_mmu_put_root(kvm, sp, false);

0 commit comments

Comments
 (0)