lpfc: Early return after marking final NLP_DROPPED flag in dev_loss_tmo
Subsystems (2)
PATCH 1/1 lpfc: Early return after marking final NLP_DROPPED flag in dev_loss_tmo
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.
--- drivers/scsi/lpfc/lpfc_hbadisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/lpfc/lpfc_hbadisc.c +1 -1
@@ -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);
Signature · 1 line
2.38.0
We have a very reproducible test case that hit the problem this fixes.
Quoted 30 lines · Justin Tee
When a
dev_loss_tmoevent occurs, an ndlp lock is taken before checkingnlp_flagforNLP_DROPPED. There is an attempt to restore the ndlp lock when exiting the if statement, but thenlp_putkref 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 callingnlp_put.Signed-off-by Justin Tee <[email protected]>--- drivers/scsi/lpfc/lpfc_hbadisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/lpfc/lpfc_hbadisc.c +1
-2@@ -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); --2.38.0