scsi: lpfc: Resolve NULL ptr dereference after an ELS LOGO is aborted
authorJames Smart <jsmart2021@gmail.com>
Fri, 3 Jun 2022 17:43:25 +0000 (10:43 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Jun 2022 12:21:57 +0000 (14:21 +0200)
[ Upstream commit b1b3440f437b75fb2a9b0cfe58df461e40eca474 ]

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/20220603174329.63777-6-jsmart2021@gmail.com
Co-developed-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: Justin Tee <justin.tee@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/lpfc/lpfc_els.c

index ce28c4a30460fbf94e0f18d3ae14b7fb084596cc..5f44a0763f37df0e8c45a5ad20643a8260a68985 100644 (file)
@@ -2955,18 +2955,10 @@ lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
                spin_unlock_irq(&ndlp->lock);
                lpfc_disc_state_machine(vport, ndlp, cmdiocb,
                                        NLP_EVT_DEVICE_RM);
-               lpfc_els_free_iocb(phba, cmdiocb);
-               lpfc_nlp_put(ndlp);
-
-               /* Presume the node was released. */
-               return;
+               goto out_rsrc_free;
        }
 
 out:
-       /* Driver is done with the IO.  */
-       lpfc_els_free_iocb(phba, cmdiocb);
-       lpfc_nlp_put(ndlp);
-
        /* At this point, the LOGO processing is complete. NOTE: For a
         * pt2pt topology, we are assuming the NPortID will only change
         * on link up processing. For a LOGO / PLOGI initiated by the
@@ -2993,6 +2985,10 @@ out:
                                 ndlp->nlp_DID, irsp->ulpStatus,
                                 irsp->un.ulpWord[4], irsp->ulpTimeout,
                                 vport->num_disc_nodes);
+
+               lpfc_els_free_iocb(phba, cmdiocb);
+               lpfc_nlp_put(ndlp);
+
                lpfc_disc_start(vport);
                return;
        }
@@ -3009,6 +3005,10 @@ out:
                lpfc_disc_state_machine(vport, ndlp, cmdiocb,
                                        NLP_EVT_DEVICE_RM);
        }
+out_rsrc_free:
+       /* Driver is done with the I/O. */
+       lpfc_els_free_iocb(phba, cmdiocb);
+       lpfc_nlp_put(ndlp);
 }
 
 /**