linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCIE/PME: fix possible use-after-free on remove
@ 2019-02-18 19:57 Sven Van Asbroeck
  2019-02-25 14:57 ` Mika Westerberg
  0 siblings, 1 reply; 2+ messages in thread
From: Sven Van Asbroeck @ 2019-02-18 19:57 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, linux-kernel, Sinan Kaya, Frederick Lawler,
	Mika Westerberg, Keith Busch

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 <okaya@kernel.org>
Cc: Frederick Lawler <fred@fredlawl.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Keith Busch <keith.busch@intel.com>
Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
---
 drivers/pci/pcie/pme.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pcie/pme.c b/drivers/pci/pcie/pme.c
index 0dbcf429089f..87823f669ccc 100644
--- a/drivers/pci/pcie/pme.c
+++ b/drivers/pci/pcie/pme.c
@@ -427,9 +427,12 @@ static int pcie_pme_resume(struct pcie_device *srv)
  */
 static void pcie_pme_remove(struct pcie_device *srv)
 {
+	struct pcie_pme_service_data *data = get_service_data(srv);
+
 	pcie_pme_suspend(srv);
 	free_irq(srv->irq, srv);
-	kfree(get_service_data(srv));
+	cancel_work_sync(&data->work);
+	kfree(data);
 }
 
 static int pcie_pme_runtime_suspend(struct pcie_device *srv)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] PCIE/PME: fix possible use-after-free on remove
  2019-02-18 19:57 [PATCH] PCIE/PME: fix possible use-after-free on remove Sven Van Asbroeck
@ 2019-02-25 14:57 ` Mika Westerberg
  0 siblings, 0 replies; 2+ messages in thread
From: Mika Westerberg @ 2019-02-25 14:57 UTC (permalink / raw)
  To: Sven Van Asbroeck
  Cc: Bjorn Helgaas, linux-pci, linux-kernel, Sinan Kaya,
	Frederick Lawler, Keith Busch

On Mon, Feb 18, 2019 at 02:57:30PM -0500, Sven Van Asbroeck wrote:
> 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 <okaya@kernel.org>
> Cc: Frederick Lawler <fred@fredlawl.com>
> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-25 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-18 19:57 [PATCH] PCIE/PME: fix possible use-after-free on remove Sven Van Asbroeck
2019-02-25 14:57 ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).