Skip to content

Commit b5b359a

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Disallow guest from using !visible slots for page tables
Explicitly inject a page fault if guest attempts to use a !visible gfn as a page table. kvm_vcpu_gfn_to_hva_prot() will naturally handle the case where there is no memslot, but doesn't catch the scenario where the gfn points at a KVM-internal memslot. Letting the guest backdoor its way into accessing KVM-internal memslots isn't dangerous on its own, e.g. at worst the guest can crash itself, but disallowing the behavior will simplify fixing how KVM handles !visible guest root gfns (immediately synthesizing a triple fault when loading the root is architecturally wrong). Link: https://lore.kernel.org/r/20230729005200.1057358-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 2c6d4c2 commit b5b359a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/x86/kvm/mmu/paging_tmpl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
361361
++walker->level;
362362

363363
do {
364+
struct kvm_memory_slot *slot;
364365
unsigned long host_addr;
365366

366367
pt_access = pte_access;
@@ -391,7 +392,11 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
391392
if (unlikely(real_gpa == INVALID_GPA))
392393
return 0;
393394

394-
host_addr = kvm_vcpu_gfn_to_hva_prot(vcpu, gpa_to_gfn(real_gpa),
395+
slot = kvm_vcpu_gfn_to_memslot(vcpu, gpa_to_gfn(real_gpa));
396+
if (!kvm_is_visible_memslot(slot))
397+
goto error;
398+
399+
host_addr = gfn_to_hva_memslot_prot(slot, gpa_to_gfn(real_gpa),
395400
&walker->pte_writable[walker->level - 1]);
396401
if (unlikely(kvm_is_error_hva(host_addr)))
397402
goto error;

0 commit comments

Comments
 (0)