linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue
@ 2020-11-18 13:13 Colin King
  2020-11-19 20:53 ` James Smart
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Colin King @ 2020-11-18 13:13 UTC (permalink / raw)
  To: James Smart, Dick Kennedy, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

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")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/scsi/lpfc/lpfc_scsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index f989490359a5..3b989f720937 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -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
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue
  2020-11-18 13:13 [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue Colin King
@ 2020-11-19 20:53 ` James Smart
  2020-11-20  3:14 ` Martin K. Petersen
  2020-11-24  3:58 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: James Smart @ 2020-11-19 20:53 UTC (permalink / raw)
  To: Colin King, Dick Kennedy, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi
  Cc: kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1778 bytes --]



On 11/18/2020 5:13 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   drivers/scsi/lpfc/lpfc_scsi.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
> index f989490359a5..3b989f720937 100644
> --- a/drivers/scsi/lpfc/lpfc_scsi.c
> +++ b/drivers/scsi/lpfc/lpfc_scsi.c
> @@ -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

Looks good.

Reviewed-by: James Smart <james.smart@broadcom.com>

-- james


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4163 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue
  2020-11-18 13:13 [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue Colin King
  2020-11-19 20:53 ` James Smart
@ 2020-11-20  3:14 ` Martin K. Petersen
  2020-11-24  3:58 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-11-20  3:14 UTC (permalink / raw)
  To: Colin King
  Cc: James Smart, Dick Kennedy, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi, kernel-janitors, linux-kernel


Colin,

> 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!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue
  2020-11-18 13:13 [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue Colin King
  2020-11-19 20:53 ` James Smart
  2020-11-20  3:14 ` Martin K. Petersen
@ 2020-11-24  3:58 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-11-24  3:58 UTC (permalink / raw)
  To: linux-scsi, James Smart, Colin King, James E . J . Bottomley,
	Dick Kennedy
  Cc: Martin K . Petersen, linux-kernel, kernel-janitors

On Wed, 18 Nov 2020 13:13:45 +0000, Colin King wrote:

> 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

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-24  3:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 13:13 [PATCH][next] scsi: lpfc: fix pointer defereference before it is null checked issue Colin King
2020-11-19 20:53 ` James Smart
2020-11-20  3:14 ` Martin K. Petersen
2020-11-24  3:58 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).