Skip to content

Commit

Permalink
KVM: irqfd: fix race between EPOLLHUP and irq_bypass_register_consumer
Browse files Browse the repository at this point in the history
commit 9432a31 upstream.

A comment warning against this bug is there, but the code is not doing what
the comment says.  Therefore it is possible that an EPOLLHUP races against
irq_bypass_register_consumer.  The EPOLLHUP handler schedules irqfd_shutdown,
and if that runs soon enough, you get a use-after-free.

Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Paolo Bonzini authored and Greg Kroah-Hartman committed Aug 24, 2018
1 parent b84ec04 commit 1186a6e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions virt/kvm/eventfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
if (events & POLLIN)
schedule_work(&irqfd->inject);

/*
* do not drop the file until the irqfd is fully initialized, otherwise
* we might race against the POLLHUP
*/
fdput(f);
#ifdef CONFIG_HAVE_KVM_IRQ_BYPASS
irqfd->consumer.token = (void *)irqfd->eventfd;
irqfd->consumer.add_producer = kvm_arch_irq_bypass_add_producer;
Expand All @@ -423,6 +418,12 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
#endif

srcu_read_unlock(&kvm->irq_srcu, idx);

/*
* do not drop the file until the irqfd is fully initialized, otherwise
* we might race against the POLLHUP
*/
fdput(f);
return 0;

fail:
Expand Down

0 comments on commit 1186a6e

Please sign in to comment.