All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: fix a error refcount get in pcie_device_make_active
@ 2021-03-23  2:35 Lv Yunlong
  0 siblings, 0 replies; only message in thread
From: Lv Yunlong @ 2021-03-23  2:35 UTC (permalink / raw)
  To: sathya.prakash, sreekanth.reddy, suganath-prabu.subramani, jejb,
	martin.petersen
  Cc: MPT-FusionLinux.pdl, linux-scsi, linux-kernel, Lv Yunlong

In pcie_device_make_active, pcie_device may be freed by
pcie_device_put(pcie_device). After it, the refcount of
pcie_device is increased by pcie_device_get(pcie_device).
The pcie_device is freed but refcount is non-zero. It could
cause use after free later.

My patch puts the pcie_device_get() ahead of pcie_device_put()
to avoid uaf.

Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index ffca03064797..17061f54d616 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -11432,12 +11432,12 @@ static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc,
 	unsigned long flags;
 
 	spin_lock_irqsave(&ioc->pcie_device_lock, flags);
-
+	pcie_device_get(pcie_device);
+
 	if (!list_empty(&pcie_device->list)) {
 		list_del_init(&pcie_device->list);
 		pcie_device_put(pcie_device);
 	}
-	pcie_device_get(pcie_device);
 	list_add_tail(&pcie_device->list, &ioc->pcie_device_list);
 
 	spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
-- 
2.25.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-23  2:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23  2:35 [PATCH] scsi: fix a error refcount get in pcie_device_make_active Lv Yunlong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.