Skip to content

Commit a7a5485

Browse files
bonziniZhengShunQian
authored andcommitted
KVM: irqfd: fix race between EPOLLHUP and irq_bypass_register_consumer
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 <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Signed-off-by: Sudip Mukherjee <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 19c12ea commit a7a5485

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

virt/kvm/eventfd.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
405405
if (events & POLLIN)
406406
schedule_work(&irqfd->inject);
407407

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

425420
srcu_read_unlock(&kvm->irq_srcu, idx);
421+
422+
/*
423+
* do not drop the file until the irqfd is fully initialized, otherwise
424+
* we might race against the POLLHUP
425+
*/
426+
fdput(f);
426427
return 0;
427428

428429
fail:

0 commit comments

Comments
 (0)