linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Nilesh Javali <njavali@marvell.com>, martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org,
	GR-QLogic-Storage-Upstream@marvell.com, bhazarika@marvell.com,
	agurumurthy@marvell.com, sdeodhar@marvell.com
Subject: Re: [PATCH 2/8] qla2xxx: klocwork - Fix potential null pointer dereference
Date: Thu, 18 May 2023 10:42:00 -0700	[thread overview]
Message-ID: <f312be96-786e-f5f3-a92e-54a5983dfa19@acm.org> (raw)
In-Reply-To: <20230518075841.40363-3-njavali@marvell.com>

On 5/18/23 00:58, Nilesh Javali wrote:
> From: Bikash Hazarika <bhazarika@marvell.com>
> 
> Klocwork tool reported 'cur_dsd' may be dereferenced.
> Add fix to validate pointer before dereferencing
> the pointer.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Bikash Hazarika <bhazarika@marvell.com>
> Signed-off-by: Nilesh Javali <njavali@marvell.com>
> ---
>   drivers/scsi/qla2xxx/qla_iocb.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
> index 6acfdcc48b16..a092151aef77 100644
> --- a/drivers/scsi/qla2xxx/qla_iocb.c
> +++ b/drivers/scsi/qla2xxx/qla_iocb.c
> @@ -664,9 +664,11 @@ qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt,
>   	}
>   
>   	/* Null termination */
> -	cur_dsd->address = 0;
> -	cur_dsd->length = 0;
> -	cur_dsd++;
> +	if (cur_dsd) {
> +		cur_dsd->address = 0;
> +		cur_dsd->length = 0;
> +		cur_dsd++;
> +	}
>   	cmd_pkt->control_flags |= cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE);
>   	return 0;
>   }

Please add BUG_ON(!cur_dsd) above the first cur_dsd dereference instead 
of making the above change. The above change hides a bug. Hiding bugs 
doesn't help anyone.

Bart.

  reply	other threads:[~2023-05-18 17:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18  7:58 [PATCH 0/8] qla2xxx klocwork fixes Nilesh Javali
2023-05-18  7:58 ` [PATCH 1/8] qla2xxx: klocwork - Array index may go out of bound Nilesh Javali
2023-05-18  7:58 ` [PATCH 2/8] qla2xxx: klocwork - Fix potential null pointer dereference Nilesh Javali
2023-05-18 17:42   ` Bart Van Assche [this message]
2023-05-31 11:43     ` [EXT] " Nilesh Javali
2023-05-31 12:33       ` Bart Van Assche
2023-06-07  8:31         ` Nilesh Javali
2023-05-18  7:58 ` [PATCH 3/8] qla2xxx: klocwork - Check for a valid fcport pointer Nilesh Javali
2023-05-18 17:44   ` Bart Van Assche
2023-05-18  7:58 ` [PATCH 4/8] qla2xxx: klocwork - Check valid rport returned by fc_bsg_to_rport Nilesh Javali
2023-05-18  7:58 ` [PATCH 5/8] qla2xxx: klocwork - Fix buffer overrun Nilesh Javali
2023-05-18  7:58 ` [PATCH 6/8] qla2xxx: klocwork - pointer may be dereferenced Nilesh Javali
2023-05-18  7:58 ` [PATCH 7/8] qla2xxx: klocwork - correct the index of array Nilesh Javali
2023-05-18 17:47   ` Bart Van Assche
2023-05-18  7:58 ` [PATCH 8/8] qla2xxx: Update version to 10.02.08.400-k Nilesh Javali

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f312be96-786e-f5f3-a92e-54a5983dfa19@acm.org \
    --to=bvanassche@acm.org \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=agurumurthy@marvell.com \
    --cc=bhazarika@marvell.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=njavali@marvell.com \
    --cc=sdeodhar@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).