Skip to content

Commit 9b61500

Browse files
KAGA-KOKOgregkh
authored andcommitted
PCI/MSI: Destroy sysfs before freeing entries
commit 3735459 upstream. free_msi_irqs() frees the MSI entries before destroying the sysfs entries which are exposing them. Nothing prevents a concurrent free while a sysfs file is read and accesses the possibly freed entry. Move the sysfs release ahead of freeing the entries. Fixes: 1c51b50 ("PCI/MSI: Export MSI mode using attributes, not kobjects") Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Bjorn Helgaas <helgaas@kernel.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/87sfw5305m.ffs@tglx Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c49bfdf commit 9b61500

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

drivers/pci/msi.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,6 @@ static void free_msi_irqs(struct pci_dev *dev)
396396
for (i = 0; i < entry->nvec_used; i++)
397397
BUG_ON(irq_has_action(entry->irq + i));
398398

399-
pci_msi_teardown_msi_irqs(dev);
400-
401-
list_for_each_entry_safe(entry, tmp, msi_list, list) {
402-
if (entry->msi_attrib.is_msix) {
403-
if (list_is_last(&entry->list, msi_list))
404-
iounmap(entry->mask_base);
405-
}
406-
407-
list_del(&entry->list);
408-
free_msi_entry(entry);
409-
}
410-
411399
if (dev->msi_irq_groups) {
412400
sysfs_remove_groups(&dev->dev.kobj, dev->msi_irq_groups);
413401
msi_attrs = dev->msi_irq_groups[0]->attrs;
@@ -423,6 +411,18 @@ static void free_msi_irqs(struct pci_dev *dev)
423411
kfree(dev->msi_irq_groups);
424412
dev->msi_irq_groups = NULL;
425413
}
414+
415+
pci_msi_teardown_msi_irqs(dev);
416+
417+
list_for_each_entry_safe(entry, tmp, msi_list, list) {
418+
if (entry->msi_attrib.is_msix) {
419+
if (list_is_last(&entry->list, msi_list))
420+
iounmap(entry->mask_base);
421+
}
422+
423+
list_del(&entry->list);
424+
free_msi_entry(entry);
425+
}
426426
}
427427

428428
static void pci_intx_for_msi(struct pci_dev *dev, int enable)

0 commit comments

Comments
 (0)