Skip to content

Commit a0af3d1

Browse files
committed
PCI/MSI: Prevent UAF in error path
When the core MSI allocation fails, then the PCI/MSI code uses an already freed MSI descriptor to unmask the MSI mask register in order to bring it back into reset state. Remove MSI_FLAG_FREE_MSI_DESCS from the PCI/MSI irqdomain flags and let the PCI/MSI code free the MSI descriptors after usage. Fixes: 0f62d94 ("genirq/msi: Provide msi_domain_alloc/free_irqs_descs_locked()") Reported-by: Tong Zhang <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Tong Zhang <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/r/87r1938vbn.ffs@tglx
1 parent 1d1df41 commit a0af3d1

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

drivers/pci/msi/irqdomain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void pci_msi_teardown_msi_irqs(struct pci_dev *dev)
2828
msi_domain_free_irqs_descs_locked(domain, &dev->dev);
2929
else
3030
pci_msi_legacy_teardown_msi_irqs(dev);
31+
msi_free_msi_descs(&dev->dev);
3132
}
3233

3334
/**
@@ -171,8 +172,7 @@ struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode,
171172
if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS)
172173
pci_msi_domain_update_chip_ops(info);
173174

174-
info->flags |= MSI_FLAG_ACTIVATE_EARLY | MSI_FLAG_DEV_SYSFS |
175-
MSI_FLAG_FREE_MSI_DESCS;
175+
info->flags |= MSI_FLAG_ACTIVATE_EARLY | MSI_FLAG_DEV_SYSFS;
176176
if (IS_ENABLED(CONFIG_GENERIC_IRQ_RESERVATION_MODE))
177177
info->flags |= MSI_FLAG_MUST_REACTIVATE;
178178

drivers/pci/msi/legacy.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,4 @@ void pci_msi_legacy_teardown_msi_irqs(struct pci_dev *dev)
7777
{
7878
msi_device_destroy_sysfs(&dev->dev);
7979
arch_teardown_msi_irqs(dev);
80-
msi_free_msi_descs(&dev->dev);
8180
}

0 commit comments

Comments
 (0)