Commit bf476fe2 authored by Sergey Shtylyov's avatar Sergey Shtylyov Committed by Damien Le Moal
Browse files

ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo()



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: default avatarSergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: default avatarDamien Le Moal <damien.lemoal@opensource.wdc.com>
parent a734510f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5462,7 +5462,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;

@@ -5470,7 +5470,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])