linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport
@ 2020-07-29 23:10 Ewan D. Milne
  2020-08-04 16:21 ` James Smart
  2020-08-05  1:17 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Ewan D. Milne @ 2020-07-29 23:10 UTC (permalink / raw)
  To: linux-scsi; +Cc: james.smart

We cannot wait on a completion object in the lpfc_nvme_targetport structure
in the _destroy_targetport() code path because the NVMe/fc transport will
free that structure immediately after the .targetport_delete() callback.
This results in a use-after-free, and a crash if slub_debug=FZPU is enabled.

An earlier fix put put the completion on the stack, but commit 2a0fb340fcc8
("scsi: lpfc: Correct localport timeout duration error") subsequently changed
the code to reference the completion through a pointer in the object rather
than the local stack variable.  Fix this by using the stack variable directly.

Fixes: 2a0fb340fcc8 ("scsi: lpfc: Correct localport timeout duration error")
Signed-off-by: Ewan D. Milne <emilne@redhat.com>
---
 drivers/scsi/lpfc/lpfc_nvmet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c
index 88760416a8cb..fcd9d4c2f1ee 100644
--- a/drivers/scsi/lpfc/lpfc_nvmet.c
+++ b/drivers/scsi/lpfc/lpfc_nvmet.c
@@ -2112,7 +2112,7 @@ lpfc_nvmet_destroy_targetport(struct lpfc_hba *phba)
 		}
 		tgtp->tport_unreg_cmp = &tport_unreg_cmp;
 		nvmet_fc_unregister_targetport(phba->targetport);
-		if (!wait_for_completion_timeout(tgtp->tport_unreg_cmp,
+		if (!wait_for_completion_timeout(&tport_unreg_cmp,
 					msecs_to_jiffies(LPFC_NVMET_WAIT_TMO)))
 			lpfc_printf_log(phba, KERN_ERR, LOG_NVME,
 					"6179 Unreg targetport x%px timeout "
-- 
2.18.1


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

* Re: [PATCH] scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport
  2020-07-29 23:10 [PATCH] scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport Ewan D. Milne
@ 2020-08-04 16:21 ` James Smart
  2020-08-05  1:17 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: James Smart @ 2020-08-04 16:21 UTC (permalink / raw)
  To: Ewan D. Milne, linux-scsi



On 7/29/2020 4:10 PM, Ewan D. Milne wrote:
> We cannot wait on a completion object in the lpfc_nvme_targetport structure
> in the _destroy_targetport() code path because the NVMe/fc transport will
> free that structure immediately after the .targetport_delete() callback.
> This results in a use-after-free, and a crash if slub_debug=FZPU is enabled.
>
> An earlier fix put put the completion on the stack, but commit 2a0fb340fcc8
> ("scsi: lpfc: Correct localport timeout duration error") subsequently changed
> the code to reference the completion through a pointer in the object rather
> than the local stack variable.  Fix this by using the stack variable directly.
>
> Fixes: 2a0fb340fcc8 ("scsi: lpfc: Correct localport timeout duration error")
> Signed-off-by: Ewan D. Milne <emilne@redhat.com>
> ---
>

Thanks Ewan

Reviewed-by: James Smart <james.smart@broadcom.com>

-- james

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

* Re: [PATCH] scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport
  2020-07-29 23:10 [PATCH] scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport Ewan D. Milne
  2020-08-04 16:21 ` James Smart
@ 2020-08-05  1:17 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2020-08-05  1:17 UTC (permalink / raw)
  To: Ewan D. Milne, linux-scsi; +Cc: Martin K . Petersen, james.smart

On Wed, 29 Jul 2020 19:10:11 -0400, Ewan D. Milne wrote:

> We cannot wait on a completion object in the lpfc_nvme_targetport structure
> in the _destroy_targetport() code path because the NVMe/fc transport will
> free that structure immediately after the .targetport_delete() callback.
> This results in a use-after-free, and a crash if slub_debug=FZPU is enabled.
> 
> An earlier fix put put the completion on the stack, but commit 2a0fb340fcc8
> ("scsi: lpfc: Correct localport timeout duration error") subsequently changed
> the code to reference the completion through a pointer in the object rather
> than the local stack variable.  Fix this by using the stack variable directly.

Applied to 5.9/scsi-queue, thanks!

[1/1] scsi: lpfc: nvmet: Avoid hang / use-after-free again when destroying targetport
      https://git.kernel.org/mkp/scsi/c/af6de8c60fe9

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2020-08-05  1:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 23:10 [PATCH] scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport Ewan D. Milne
2020-08-04 16:21 ` James Smart
2020-08-05  1:17 ` Martin K. Petersen

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).