scsi: lpfc: Early return after marking final NLP_DROPPED flag in dev_loss_tmo
authorJustin Tee <justin.tee@broadcom.com>
Fri, 8 Sep 2023 21:18:52 +0000 (14:18 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 14 Sep 2023 00:49:34 +0000 (20:49 -0400)
When a dev_loss_tmo event occurs, an ndlp lock is taken before checking
nlp_flag for NLP_DROPPED.  There is an attempt to restore the ndlp lock
when exiting the if statement, but the nlp_put kref could be the final
decrement causing a use-after-free memory access on a released ndlp object.

Instead of trying to reacquire the ndlp lock after checking nlp_flag, just
return after calling nlp_put.

Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Link: https://lore.kernel.org/r/20230908211852.37576-1-justintee8345@gmail.com
Reviewed-by: "Ewan D. Milne" <emilne@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/lpfc/lpfc_hbadisc.c

index 51afb60859ebf957c6f4eb1e0f2a169e093e55f3..674dd07aae72a310b075316e5989331e62d5879b 100644 (file)
@@ -203,7 +203,7 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
                        ndlp->nlp_flag |= NLP_DROPPED;
                        spin_unlock_irqrestore(&ndlp->lock, iflags);
                        lpfc_nlp_put(ndlp);
-                       spin_lock_irqsave(&ndlp->lock, iflags);
+                       return;
                }
 
                spin_unlock_irqrestore(&ndlp->lock, iflags);