linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: Chengfeng Ye <cyeaa@connect.ust.hk>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] driver/ata: fix potential null pointer dereference on pointer last_sge
Date: Tue, 26 Oct 2021 13:09:41 +0900	[thread overview]
Message-ID: <81a99dd1-0ef6-9bd0-31c0-b0934023746b@opensource.wdc.com> (raw)
In-Reply-To: <20211025131304.17226-1-cyeaa@connect.ust.hk>

On 2021/10/25 22:13, Chengfeng Ye wrote:
> The pointer cs_desc could be null if the loop is not
> executed, so there is a potential NULL-PTR dereference
> issue. Fix this by adding a null check before dereference.
> 
> Signed-off-by: Chengfeng Ye <cyeaa@connect.ust.hk>
> ---
>  drivers/ata/sata_sil24.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
> index 06a1e27c4f84..2bd595da799f 100644
> --- a/drivers/ata/sata_sil24.c
> +++ b/drivers/ata/sata_sil24.c
> @@ -785,6 +785,8 @@ static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
>  		sge++;
>  	}
>  
> +	if (!last_sge)
> +		return;
>  	last_sge->flags = cpu_to_le32(SGE_TRM);
>  }

I do not think that this fix is necessary: sil24_fill_sg() is called only if the
qc has ATA_QCFLAG_DMAMAP set (see sil24_qc_prep()) and that in turn is only set
if ata_sg_setup() sees at least one sg entry. So the loop in sil24_fill_sg()
will always be executed for qc marked with ATA_QCFLAG_DMAMAP and so last_sg
cannot be NULL.

-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2021-10-26  4:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25 13:13 [PATCH] driver/ata: fix potential null pointer dereference on pointer last_sge Chengfeng Ye
2021-10-26  4:09 ` Damien Le Moal [this message]
2021-10-26 10:14   ` 回复: " YE Chengfeng

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=81a99dd1-0ef6-9bd0-31c0-b0934023746b@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=cyeaa@connect.ust.hk \
    --cc=linux-kernel@vger.kernel.org \
    /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).