Skip to content

Commit

Permalink
KVM: use after free in kvm_ioctl_create_device()
Browse files Browse the repository at this point in the history
We should move the ops->destroy(dev) after the list_del(&dev->vm_node)
so that we don't use "dev" after freeing it.

Fixes: a28ebea ("KVM: Protect device ops->create and list_add with kvm->lock")
Signed-off-by: Dan Carpenter <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Signed-off-by: Radim Krčmář <[email protected]>
  • Loading branch information
Dan Carpenter authored and rkrcmar committed Dec 1, 2016
1 parent 0f4828a commit a0f1d21
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2889,10 +2889,10 @@ static int kvm_ioctl_create_device(struct kvm *kvm,

ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);
if (ret < 0) {
ops->destroy(dev);
mutex_lock(&kvm->lock);
list_del(&dev->vm_node);
mutex_unlock(&kvm->lock);
ops->destroy(dev);
return ret;
}

Expand Down

0 comments on commit a0f1d21

Please sign in to comment.