Skip to content

Commit 2c6d4c2

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Harden TDP MMU iteration against root w/o shadow page
Explicitly check that tdp_iter_start() is handed a valid shadow page to harden KVM against bugs, e.g. if KVM calls into the TDP MMU with an invalid or shadow MMU root (which would be a fatal KVM bug), the shadow page pointer will be NULL. Opportunistically stop the TDP MMU iteration instead of continuing on with garbage if the incoming root is bogus. Attempting to walk a garbage root is more likely to caused major problems than doing nothing. Cc: Yu Zhang <yu.c.zhang@linux.intel.com> Link: https://lore.kernel.org/r/20230729005200.1057358-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent c30e000 commit 2c6d4c2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

arch/x86/kvm/mmu/tdp_iter.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ void tdp_iter_restart(struct tdp_iter *iter)
3939
void tdp_iter_start(struct tdp_iter *iter, struct kvm_mmu_page *root,
4040
int min_level, gfn_t next_last_level_gfn)
4141
{
42-
int root_level = root->role.level;
43-
44-
WARN_ON_ONCE(root_level < 1);
45-
WARN_ON_ONCE(root_level > PT64_ROOT_MAX_LEVEL);
42+
if (WARN_ON_ONCE(!root || (root->role.level < 1) ||
43+
(root->role.level > PT64_ROOT_MAX_LEVEL))) {
44+
iter->valid = false;
45+
return;
46+
}
4647

4748
iter->next_last_level_gfn = next_last_level_gfn;
48-
iter->root_level = root_level;
49+
iter->root_level = root->role.level;
4950
iter->min_level = min_level;
5051
iter->pt_path[iter->root_level - 1] = (tdp_ptep_t)root->spt;
5152
iter->as_id = kvm_mmu_page_as_id(root);

0 commit comments

Comments
 (0)