Skip to contentSkip to conversation

scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport

PATCH Applied Ewan D. Milne 3 participants 3 messages Jul 29, 2020 – Aug 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: lpfc: nvmet: avoid hang / use-after-free again when destroying targetport

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")
---
 drivers/scsi/lpfc/lpfc_nvmet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/lpfc/lpfc_nvmet.c +1 -1
index 88760416a8cb..fcd9d4c2f1ee 100644
@@ -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 "
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Ewan D. Milne

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.

Quoted 9 lines

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

---

Thanks Ewan

-- james

#2 lore raw
In reply to Ewan D. Milne
Quoted 9 lines · Ewan D. Milne

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
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering