Skip to contentSkip to conversation

scsi: lpfc: fix pointer defereference before it is null checked issue

PATCH Applied Colin King 3 participants 4 messages Nov 18, 2020 – Nov 24, 2020

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 scsi: lpfc: fix pointer defereference before it is null checked issue

From: Colin Ian King <[email protected]>

There is a null check on pointer lpfc_cmd after the pointer has been dereferenced when pointers rdata and ndlp are initialized at the start of the function. Fix this by only assigning rdata and ndlp after the pointer lpfc_cmd has been null checked.

Addresses-Coverity: ("Dereference before null check")

Fixes 96e209be6ecb ("scsi: lpfc: Convert SCSI I/O completions to SLI-3 and SLI-4 handlers")
---
 drivers/scsi/lpfc/lpfc_scsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/scsi/lpfc/lpfc_scsi.c +5 -2
index f989490359a5..3b989f720937 100644
@@ -4022,8 +4022,8 @@ lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
 	struct lpfc_io_buf *lpfc_cmd  		(struct lpfc_io_buf *)pwqeIn->context1;
 	struct lpfc_vport *vport = pwqeIn->vport;
-	struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
-	struct lpfc_nodelist *ndlp = rdata->pnode;
+	struct lpfc_rport_data *rdata;
+	struct lpfc_nodelist *ndlp;
 	struct scsi_cmnd *cmd;
 	unsigned long flags;
 	struct lpfc_fast_path_event *fast_path_evt;
@@ -4040,6 +4040,9 @@ lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
 		return;
 	}
 
+	rdata = lpfc_cmd->rdata;
+	ndlp = rdata->pnode;
+
 	if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
 		/* TOREMOVE - currently this flag is checked during
 		 * the release of lpfc_iocbq. Remove once we move
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Colin King

From: Colin Ian King <[email protected]>

There is a null check on pointer lpfc_cmd after the pointer has been dereferenced when pointers rdata and ndlp are initialized at the start of the function. Fix this by only assigning rdata and ndlp after the pointer lpfc_cmd has been null checked.

Addresses-Coverity: ("Dereference before null check")

Fixes 96e209be6ecb ("scsi: lpfc: Convert SCSI I/O completions to SLI-3 and SLI-4 handlers")
---
  drivers/scsi/lpfc/lpfc_scsi.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/scsi/lpfc/lpfc_scsi.c +2 -2
index f989490359a5..3b989f720937 100644
@@ -4022,8 +4022,8 @@ lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
  	struct lpfc_io_buf *lpfc_cmd =
  		(struct lpfc_io_buf *)pwqeIn->context1;
  	struct lpfc_vport *vport = pwqeIn->vport;
-	struct lpfc_rport_data *rdata = lpfc_cmd->rdata;
-	struct lpfc_nodelist *ndlp = rdata->pnode;
+	struct lpfc_rport_data *rdata;
+	struct lpfc_nodelist *ndlp;
  	struct scsi_cmnd *cmd;
  	unsigned long flags;
  	struct lpfc_fast_path_event *fast_path_evt;

drivers/scsi/lpfc/lpfc_scsi.c lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn, · line 4048

Quoted 9 lines
drivers/scsi/lpfc/lpfc_scsi.c +3 -0
@@ -4040,6 +4040,9 @@ lpfc_fcp_io_cmd_wqe_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeIn,
  		return;
  	}
 
+	rdata = lpfc_cmd->rdata;
+	ndlp = rdata->pnode;
+
  	if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  		/* TOREMOVE - currently this flag is checked during
  		 * the release of lpfc_iocbq. Remove once we move

Looks good.

-- james

#2 lore raw
In reply to Colin King

Colin,

Quoted 4 lines

There is a null check on pointer lpfc_cmd after the pointer has been dereferenced when pointers rdata and ndlp are initialized at the start of the function. Fix this by only assigning rdata and ndlp after the pointer lpfc_cmd has been null checked.

Applied to 5.11/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw
In reply to Colin King
Quoted 4 lines · Colin King

There is a null check on pointer lpfc_cmd after the pointer has been dereferenced when pointers rdata and ndlp are initialized at the start of the function. Fix this by only assigning rdata and ndlp after the pointer lpfc_cmd has been null checked.

Applied to 5.11/scsi-queue, thanks!

[1/1] scsi: lpfc: Fix pointer defereference before it is null checked issue

      https://git.kernel.org/mkp/scsi/c/1e7dddb2e76a
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering