All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: mvsas: Fix use-after-free bugs in mvs_work_queue
@ 2025-09-20 13:42 Duoming Zhou
  2025-09-29 21:27 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: Duoming Zhou @ 2025-09-20 13:42 UTC (permalink / raw)
  To: linux-scsi
  Cc: linux-kernel, James.Bottomley, martin.petersen,
	christophe.jaillet, mingo, tglx, linux, fourier.thomas,
	Duoming Zhou

During the detaching of Marvell's SAS/SATA controller, the origin
code calls cancel_delayed_work() in mvs_free() to cancel the delayed
work item mwq->work_q. However, if mwq->work_q is already running,
the cancel_delayed_work() may fail to cancel it. This can lead to
use-after-free scenarios where mvs_free() frees the mvs_info while
mvs_work_queue() is still executing and attempts to access the
already-freed mvs_info.

A typical race condition is illustrated below:

CPU 0 (remove)            | CPU 1 (delayed work callback)
mvs_pci_remove()          |
  mvs_free()              | mvs_work_queue()
    cancel_delayed_work() |
      kfree(mvi)          |
                          |   mvi-> // UAF

Replace cancel_delayed_work() with cancel_delayed_work_sync() to
ensure that the delayed work item is properly canceled and any
executing delayed work item completes before the mvs_info is
deallocated.

This bug was found by static analysis.

Fixes: 20b09c2992fe ("[SCSI] mvsas: add support for 94xx; layout change; bug fixes")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
 drivers/scsi/mvsas/mv_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index 2c72da6b8cf0..7f1ad305eee6 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -124,7 +124,7 @@ static void mvs_free(struct mvs_info *mvi)
 	if (mvi->shost)
 		scsi_host_put(mvi->shost);
 	list_for_each_entry(mwq, &mvi->wq_list, entry)
-		cancel_delayed_work(&mwq->work_q);
+		cancel_delayed_work_sync(&mwq->work_q);
 	kfree(mvi->rsvd_tags);
 	kfree(mvi);
 }
-- 
2.34.1


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

* Re: [PATCH] scsi: mvsas: Fix use-after-free bugs in mvs_work_queue
  2025-09-20 13:42 [PATCH] scsi: mvsas: Fix use-after-free bugs in mvs_work_queue Duoming Zhou
@ 2025-09-29 21:27 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2025-09-29 21:27 UTC (permalink / raw)
  To: Duoming Zhou
  Cc: linux-scsi, linux-kernel, James.Bottomley, martin.petersen,
	christophe.jaillet, mingo, tglx, linux, fourier.thomas


Duoming,

> During the detaching of Marvell's SAS/SATA controller, the origin code
> calls cancel_delayed_work() in mvs_free() to cancel the delayed work
> item mwq->work_q. However, if mwq->work_q is already running, the
> cancel_delayed_work() may fail to cancel it. This can lead to
> use-after-free scenarios where mvs_free() frees the mvs_info while
> mvs_work_queue() is still executing and attempts to access the
> already-freed mvs_info.

Applied to 6.18/scsi-staging, thanks!

-- 
Martin K. Petersen

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

end of thread, other threads:[~2025-09-29 21:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-20 13:42 [PATCH] scsi: mvsas: Fix use-after-free bugs in mvs_work_queue Duoming Zhou
2025-09-29 21:27 ` Martin K. Petersen

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.