From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: Sergey Shtylyov <s.shtylyov@omp.ru>, linux-ide@vger.kernel.org
Subject: Re: [PATCH] ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo()
Date: Sat, 21 May 2022 08:45:13 +0900 [thread overview]
Message-ID: <d2d4a222-b3d3-b3a6-41a4-db2fc4c11038@opensource.wdc.com> (raw)
In-Reply-To: <3727e0b4-3958-283f-c0cf-6b8b898ab018@omp.ru>
On 5/21/22 05:53, Sergey Shtylyov wrote:
> In an unlikely (and probably wrong?) case that the 'ppi' parameter of
> ata_host_alloc_pinfo() points to an array starting with a NULL pointer,
> there's going to be a kernel oops as the 'pi' local variable won't get
> reassigned from the initial value of NULL. Assign &ata_dummy_port_info
> to 'pi' at the start of the *for* loop instead to fix this kernel oops
> for good...
>
> Found by Linux Verification Center (linuxtesting.org) with the SVACE static
> analysis tool.
>
> Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
>
> ---
> This patch is against the 'for-next' branch of Damien's 'libata.git' repo.
>
> drivers/ata/libata-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: libata/drivers/ata/libata-core.c
> ===================================================================
> --- libata.orig/drivers/ata/libata-core.c
> +++ libata/drivers/ata/libata-core.c
> @@ -5470,7 +5470,7 @@ struct ata_host *ata_host_alloc_pinfo(st
> if (!host)
> return NULL;
>
> - for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) {
> + for (i = 0, j = 0, pi = &ata_dummy_port_info; i < host->n_ports; i++) {
> struct ata_port *ap = host->ports[i];
>
> if (ppi[j])
I had a fight with this one a while back as the build bot was complaining
about this a while back. pi cannot be null in this case, but silencing
warnings is good. So OK.
Just one nit: please move the initialization of pi to its declaration to
avoid the overly long for line.
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2022-05-20 23:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-20 20:53 [PATCH] ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo() Sergey Shtylyov
2022-05-20 23:45 ` Damien Le Moal [this message]
2022-05-21 20:00 ` Sergey Shtylyov
2022-05-22 8:46 ` Damien Le Moal
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=d2d4a222-b3d3-b3a6-41a4-db2fc4c11038@opensource.wdc.com \
--to=damien.lemoal@opensource.wdc.com \
--cc=linux-ide@vger.kernel.org \
--cc=s.shtylyov@omp.ru \
/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