]> git.itanic.dy.fi Git - linux-stable/commitdiff
ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo()
authorSergey Shtylyov <s.shtylyov@omp.ru>
Sat, 21 May 2022 20:34:10 +0000 (23:34 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Jun 2022 12:11:20 +0000 (14:11 +0200)
[ Upstream commit bf476fe22aa1851bab4728e0c49025a6a0bea307 ]

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. Initialize 'pi' instead to
'&ata_dummy_port_info' to fix the possible 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>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/ata/libata-core.c

index af8a1bac93458fc4d1ee5208f043c3df49611f90..fc37e075f3e15963ab7c8fac37b6cb39f0d51355 100644 (file)
@@ -6235,7 +6235,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,
                                      const struct ata_port_info * const * ppi,
                                      int n_ports)
 {
-       const struct ata_port_info *pi;
+       const struct ata_port_info *pi = &ata_dummy_port_info;
        struct ata_host *host;
        int i, j;
 
@@ -6243,7 +6243,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,
        if (!host)
                return NULL;
 
-       for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) {
+       for (i = 0, j = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
 
                if (ppi[j])