Skip to content

Commit a0f1d21

Browse files
Dan Carpenterrkrcmar
authored andcommitted
KVM: use after free in kvm_ioctl_create_device()
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 <dan.carpenter@oracle.com> Reviewed-by: David Hildenbrand <david@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
1 parent 0f4828a commit a0f1d21

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

virt/kvm/kvm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2889,10 +2889,10 @@ static int kvm_ioctl_create_device(struct kvm *kvm,
28892889

28902890
ret = anon_inode_getfd(ops->name, &kvm_device_fops, dev, O_RDWR | O_CLOEXEC);
28912891
if (ret < 0) {
2892-
ops->destroy(dev);
28932892
mutex_lock(&kvm->lock);
28942893
list_del(&dev->vm_node);
28952894
mutex_unlock(&kvm->lock);
2895+
ops->destroy(dev);
28962896
return ret;
28972897
}
28982898

0 commit comments

Comments
 (0)