KVM: use after free in kvm_ioctl_create_device()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 30 Nov 2016 19:21:05 +0000 (22:21 +0300)
committerRadim Krčmář <rkrcmar@redhat.com>
Thu, 1 Dec 2016 15:10:50 +0000 (16:10 +0100)
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: a28ebea2adc4 ("KVM: Protect device ops->create and list_add with kvm->lock")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
virt/kvm/kvm_main.c

index 5c360347a1e9fc2091f5abf0bbb6a3432e13add9..7f9ee2929cfea3ba0d30740e5c82109c14d359e4 100644 (file)
@@ -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;
        }