]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
KVM: fix irqfd assign/deassign race
authorMarcelo Tosatti <mtosatti@redhat.com>
Thu, 14 Oct 2010 16:49:58 +0000 (13:49 -0300)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 29 Oct 2010 04:51:38 +0000 (21:51 -0700)
commit 6bbfb2653177a00f70e57e53625502d43804fed0 upstream.

I think I see the following (theoretical) race:

During irqfd assign, we drop irqfds lock before we
schedule inject work. Therefore, deassign running
on another CPU could cause shutdown and flush to run
before inject, causing user after free in inject.

A simple fix it to schedule inject under the lock.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Gregory Haskins <ghaskins@novell.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
virt/kvm/eventfd.c

index b81f0ebbaaadb6db5c62ef3d8078117630152b35..33993e38fced5b6183e59f6e9600fe60552f07ce 100644 (file)
@@ -217,7 +217,6 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
        events = file->f_op->poll(file, &irqfd->pt);
 
        list_add_tail(&irqfd->list, &kvm->irqfds.items);
-       spin_unlock_irq(&kvm->irqfds.lock);
 
        /*
         * Check if there was an event already pending on the eventfd
@@ -226,6 +225,8 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
        if (events & POLLIN)
                schedule_work(&irqfd->inject);
 
+       spin_unlock_irq(&kvm->irqfds.lock);
+
        /*
         * do not drop the file until the irqfd is fully initialized, otherwise
         * we might race against the POLLHUP