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: 0f62d941acf9 ("genirq/msi: Provide msi_domain_alloc/free_irqs_descs_locked()")
Reported-by: Tong Zhang <ztong0001@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Tong Zhang <ztong0001@gmail.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://lore.kernel.org/r/87r1938vbn.ffs@tglx

Changed files
+2 -3
drivers
+2 -2
drivers/pci/msi/irqdomain.c
··· 28 28 msi_domain_free_irqs_descs_locked(domain, &dev->dev); 29 29 else 30 30 pci_msi_legacy_teardown_msi_irqs(dev); 31 + msi_free_msi_descs(&dev->dev); 31 32 } 32 33 33 34 /** ··· 172 171 if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS) 173 172 pci_msi_domain_update_chip_ops(info); 174 173 175 - info->flags |= MSI_FLAG_ACTIVATE_EARLY | MSI_FLAG_DEV_SYSFS | 176 - MSI_FLAG_FREE_MSI_DESCS; 174 + info->flags |= MSI_FLAG_ACTIVATE_EARLY | MSI_FLAG_DEV_SYSFS; 177 175 if (IS_ENABLED(CONFIG_GENERIC_IRQ_RESERVATION_MODE)) 178 176 info->flags |= MSI_FLAG_MUST_REACTIVATE; 179 177
-1
drivers/pci/msi/legacy.c
··· 77 77 { 78 78 msi_device_destroy_sysfs(&dev->dev); 79 79 arch_teardown_msi_irqs(dev); 80 - msi_free_msi_descs(&dev->dev); 81 80 }