Skip to content

Commit 5762cb1

Browse files
sean-jcdwmw2
authored andcommitted
KVM: Do not partially reinitialize gfn=>pfn cache during activation
Don't partially reinitialize a gfn=>pfn cache when activating the cache, and instead assert that the cache is not valid during activation. Bug the VM if the assertion fails, as use-after-free and/or data corruption is all but guaranteed if KVM ends up with a valid-but-inactive cache. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: David Woodhouse <[email protected]>
1 parent 9f87791 commit 5762cb1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

virt/kvm/pfncache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,
345345
gpc->kvm = kvm;
346346
gpc->vcpu = vcpu;
347347
gpc->usage = usage;
348+
gpc->pfn = KVM_PFN_ERR_FAULT;
349+
gpc->uhva = KVM_HVA_ERR_BAD;
348350
}
349351
EXPORT_SYMBOL_GPL(kvm_gpc_init);
350352

@@ -353,10 +355,8 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len)
353355
struct kvm *kvm = gpc->kvm;
354356

355357
if (!gpc->active) {
356-
gpc->khva = NULL;
357-
gpc->pfn = KVM_PFN_ERR_FAULT;
358-
gpc->uhva = KVM_HVA_ERR_BAD;
359-
gpc->valid = false;
358+
if (KVM_BUG_ON(gpc->valid, kvm))
359+
return -EIO;
360360

361361
spin_lock(&kvm->gpc_lock);
362362
list_add(&gpc->list, &kvm->gpc_list);

0 commit comments

Comments
 (0)