Skip to contentSkip to conversation

PCIE/PME: fix possible use-after-free on remove

PATCH Applied Sven Van Asbroeck 2 participants 2 messages Mar 1, 2019 – Mar 2, 2019 PCI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PCIE/PME: fix possible use-after-free on remove

In remove(), ensure that the pme work cannot run after kfree() is called. Otherwise, this could result in a use-after-free.

This issue was detected with the help of Coccinelle.

Cc Sinan Kaya <[email protected]>
Cc Frederick Lawler <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Keith Busch <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
---
 drivers/pci/pcie/pme.c | 1 +
 1 file changed, 1 insertion(+)

v2:
rebased against Bjorn Helgaas's pcm/pm branch at
git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git

drivers/pci/pcie/pme.c +1 -0
index efa5b552914b..54d593d10396 100644
@@ -437,6 +437,7 @@ static void pcie_pme_remove(struct pcie_device *srv)
 
 	pcie_pme_disable_interrupt(srv->port, data);
 	free_irq(srv->irq, srv);
+	cancel_work_sync(&data->work);
 	kfree(data);
 }
 
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw
Quoted 4 lines · Sven Van Asbroeck

In remove(), ensure that the pme work cannot run after kfree() is called. Otherwise, this could result in a use-after-free.

Quoted 8 lines

This issue was detected with the help of Coccinelle.

Cc Sinan Kaya <[email protected]>
Cc Frederick Lawler <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Keith Busch <[email protected]>
Cc Rafael J. Wysocki <[email protected]>

Applied to pci/pm for v5.1, thanks!

Quoted 23 lines
---
 drivers/pci/pcie/pme.c | 1 +
 1 file changed, 1 insertion(+)

v2:
rebased against Bjorn Helgaas's pcm/pm branch at
git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git

drivers/pci/pcie/pme.c +1 -1
index efa5b552914b..54d593d10396 100644
@@ -437,6 +437,7 @@ static void pcie_pme_remove(struct pcie_device *srv)
 
        pcie_pme_disable_interrupt(srv->port, data);
        free_irq(srv->irq, srv);
+       cancel_work_sync(&data->work);
        kfree(data);
 }
 
--

2.17.1