Skip to content

Commit b1b3440

Browse files
jsmart-ghmartinkpetersen
authored andcommitted
scsi: lpfc: Resolve NULL ptr dereference after an ELS LOGO is aborted
A use-after-free crash can occur after an ELS LOGO is aborted. Specifically, a nodelist structure is freed and then ndlp->vport->cfg_log_verbose is dereferenced in lpfc_nlp_get() when the discovery state machine is mistakenly called a second time with NLP_EVT_DEVICE_RM argument. Rework lpfc_cmpl_els_logo() to prevent the duplicate calls to release a nodelist structure. Link: https://lore.kernel.org/r/[email protected] Co-developed-by: Justin Tee <[email protected]> Signed-off-by: Justin Tee <[email protected]> Signed-off-by: James Smart <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 6f808bd commit b1b3440

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

drivers/scsi/lpfc/lpfc_els.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,10 +2998,7 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
29982998
ndlp->nlp_DID, ulp_status,
29992999
ulp_word4);
30003000

3001-
/* Call NLP_EVT_DEVICE_RM if link is down or LOGO is aborted */
30023001
if (lpfc_error_lost_link(ulp_status, ulp_word4)) {
3003-
lpfc_disc_state_machine(vport, ndlp, cmdiocb,
3004-
NLP_EVT_DEVICE_RM);
30053002
skip_recovery = 1;
30063003
goto out;
30073004
}
@@ -3021,18 +3018,10 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
30213018
spin_unlock_irq(&ndlp->lock);
30223019
lpfc_disc_state_machine(vport, ndlp, cmdiocb,
30233020
NLP_EVT_DEVICE_RM);
3024-
lpfc_els_free_iocb(phba, cmdiocb);
3025-
lpfc_nlp_put(ndlp);
3026-
3027-
/* Presume the node was released. */
3028-
return;
3021+
goto out_rsrc_free;
30293022
}
30303023

30313024
out:
3032-
/* Driver is done with the IO. */
3033-
lpfc_els_free_iocb(phba, cmdiocb);
3034-
lpfc_nlp_put(ndlp);
3035-
30363025
/* At this point, the LOGO processing is complete. NOTE: For a
30373026
* pt2pt topology, we are assuming the NPortID will only change
30383027
* on link up processing. For a LOGO / PLOGI initiated by the
@@ -3059,6 +3048,10 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
30593048
ndlp->nlp_DID, ulp_status,
30603049
ulp_word4, tmo,
30613050
vport->num_disc_nodes);
3051+
3052+
lpfc_els_free_iocb(phba, cmdiocb);
3053+
lpfc_nlp_put(ndlp);
3054+
30623055
lpfc_disc_start(vport);
30633056
return;
30643057
}
@@ -3075,6 +3068,10 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
30753068
lpfc_disc_state_machine(vport, ndlp, cmdiocb,
30763069
NLP_EVT_DEVICE_RM);
30773070
}
3071+
out_rsrc_free:
3072+
/* Driver is done with the I/O. */
3073+
lpfc_els_free_iocb(phba, cmdiocb);
3074+
lpfc_nlp_put(ndlp);
30783075
}
30793076

30803077
/**

0 commit comments

Comments
 (0)