Skip to content

Commit

Permalink
KVM: Do not partially reinitialize gfn=>pfn cache during activation
Browse files Browse the repository at this point in the history
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 <seanjc@google.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
  • Loading branch information
Sean Christopherson authored and David Woodhouse committed Nov 30, 2022
1 parent 9f87791 commit 5762cb1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions virt/kvm/pfncache.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm,
gpc->kvm = kvm;
gpc->vcpu = vcpu;
gpc->usage = usage;
gpc->pfn = KVM_PFN_ERR_FAULT;
gpc->uhva = KVM_HVA_ERR_BAD;
}
EXPORT_SYMBOL_GPL(kvm_gpc_init);

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

if (!gpc->active) {
gpc->khva = NULL;
gpc->pfn = KVM_PFN_ERR_FAULT;
gpc->uhva = KVM_HVA_ERR_BAD;
gpc->valid = false;
if (KVM_BUG_ON(gpc->valid, kvm))
return -EIO;

spin_lock(&kvm->gpc_lock);
list_add(&gpc->list, &kvm->gpc_list);
Expand Down

0 comments on commit 5762cb1

Please sign in to comment.