Skip to content

Commit 956b56a

Browse files
committed
vfio/pci: Fix ordering of eventfd vs virqfd shutdown
Both the INTx and MSI/X disable paths do an eventfd_ctx_put() for the trigger eventfd before calling vfio_virqfd_disable() any potential mask and unmask eventfds. This opens a use-after-free race where an inopportune irqfd can reference the freed signalling eventfd. Reorder to avoid this possibility. Signed-off-by: Alex Williamson <[email protected]>
1 parent 1a695a9 commit 956b56a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/vfio/pci/vfio_pci_intrs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd)
228228

229229
static void vfio_intx_disable(struct vfio_pci_device *vdev)
230230
{
231-
vfio_intx_set_signal(vdev, -1);
232231
vfio_virqfd_disable(&vdev->ctx[0].unmask);
233232
vfio_virqfd_disable(&vdev->ctx[0].mask);
233+
vfio_intx_set_signal(vdev, -1);
234234
vdev->irq_type = VFIO_PCI_NUM_IRQS;
235235
vdev->num_ctx = 0;
236236
kfree(vdev->ctx);
@@ -401,13 +401,13 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix)
401401
struct pci_dev *pdev = vdev->pdev;
402402
int i;
403403

404-
vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
405-
406404
for (i = 0; i < vdev->num_ctx; i++) {
407405
vfio_virqfd_disable(&vdev->ctx[i].unmask);
408406
vfio_virqfd_disable(&vdev->ctx[i].mask);
409407
}
410408

409+
vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
410+
411411
if (msix) {
412412
pci_disable_msix(vdev->pdev);
413413
kfree(vdev->msix);

0 commit comments

Comments
 (0)