Skip to contentSkip to conversation

New Defects reported by Coverity Scan for Linux

DISCUSSION Bjorn Helgaas 3 participants 5 messages Nov 10, 2020 – Nov 11, 2020 PCI

lore
Share & tools
lore
#0 lore raw

New Coverity complaint about v5.10-rc3, resulting from 9fff3256f93d ("PCI: dwc: Restore ATU memory resource setup to use last entry").

I didn't try to figure out if this is real or a false positive, so just FYI.

----- Forwarded message from [email protected] -----

Date: Mon, 09 Nov 2020 11:13:37 +0000 (UTC)
From: [email protected]
To: [email protected]
Subject: New Defects reported by Coverity Scan for Linux
Message-ID: <[email protected]>

** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc()

________________________________________________________________________________________________________
*** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc() 590

591     		/* Get last memory resource entry */
592     		resource_list_for_each_entry(tmp, &pp->bridge->windows)
593     			if (resource_type(tmp->res) == IORESOURCE_MEM)
594     				entry = tmp;

595

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1469110: Null pointer dereferences (FORWARD_NULL) Dereferencing null pointer "entry".

596     		dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0,
597     					  PCIE_ATU_TYPE_MEM, entry->res->start,
598     					  entry->res->start - entry->offset,
599     					  resource_size(entry->res));
600     		if (pci->num_viewport > 2)
601     			dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX2,
#1 lore raw
Quoted 19 lines · Bjorn Helgaas

New Coverity complaint about v5.10-rc3, resulting from 9fff3256f93d ("PCI: dwc: Restore ATU memory resource setup to use last entry").

I didn't try to figure out if this is real or a false positive, so just FYI.

----- Forwarded message from [email protected] -----

Date: Mon, 09 Nov 2020 11:13:37 +0000 (UTC)
From: [email protected]
To: [email protected]
Subject: New Defects reported by Coverity Scan for Linux
Message-ID: <[email protected]>

** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc()

Quoted 7 lines

________________________________________________________________________________________________________
*** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc() 590

591     		/* Get last memory resource entry */
592     		resource_list_for_each_entry(tmp, &pp->bridge->windows)
593     			if (resource_type(tmp->res) == IORESOURCE_MEM)

Can the pp->bridge->windows list be empty in a typical use case?

Quoted 10 lines

594 entry = tmp;
595

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1469110: Null pointer dereferences (FORWARD_NULL) Dereferencing null pointer "entry".

596     		dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX0,
597     					  PCIE_ATU_TYPE_MEM, entry->res->start,
598     					  entry->res->start - entry->offset,
599     					  resource_size(entry->res));
600     		if (pci->num_viewport > 2)
601     			dw_pcie_prog_outbound_atu(pci, PCIE_ATU_REGION_INDEX2,
#2 lore raw
Quoted 31 lines · Gustavo Pimentel
Quoted 19 lines · Bjorn Helgaas

New Coverity complaint about v5.10-rc3, resulting from 9fff3256f93d ("PCI: dwc: Restore ATU memory resource setup to use last entry").

I didn't try to figure out if this is real or a false positive, so just FYI.

----- Forwarded message from [email protected] -----

Date: Mon, 09 Nov 2020 11:13:37 +0000 (UTC)
From: [email protected]
To: [email protected]
Subject: New Defects reported by Coverity Scan for Linux
Message-ID: <[email protected]>

** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc()

Quoted 7 lines

________________________________________________________________________________________________________
*** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc() 590
591 /* Get last memory resource entry */
592 resource_list_for_each_entry(tmp, &pp->bridge->windows)
593 if (resource_type(tmp->res) == IORESOURCE_MEM)

Quoted 1 line

Can the pp->bridge->windows list be empty in a typical use case?

Only if the DT has missing/malformed 'ranges'. 'ranges' is required to have any memory or i/o space, so we would error out before this point.

Rob

#3 lore raw
Quoted 30 lines · Rob Herring
Quoted 28 lines · Gustavo Pimentel
Quoted 24 lines · Bjorn Helgaas

New Coverity complaint about v5.10-rc3, resulting from 9fff3256f93d ("PCI: dwc: Restore ATU memory resource setup to use last entry").

I didn't try to figure out if this is real or a false positive, so just FYI.

----- Forwarded message from [email protected] -----

Date: Mon, 09 Nov 2020 11:13:37 +0000 (UTC)
From: [email protected]
To: [email protected]
Subject: New Defects reported by Coverity Scan for Linux
Message-ID: <[email protected]>

** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc()

________________________________________________________________________________________________________
*** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc() 590
591 /* Get last memory resource entry */
592 resource_list_for_each_entry(tmp, &pp->bridge->windows)
593 if (resource_type(tmp->res) == IORESOURCE_MEM)

Quoted 4 lines
Quoted 1 line

Can the pp->bridge->windows list be empty in a typical use case?

Only if the DT has missing/malformed 'ranges'. 'ranges' is required to have any memory or i/o space, so we would error out before this point.

There are a lot of paths that lead here, and it's an awful lot of work to verify that they all correctly error out if 'ranges' is invalid.

It would really be nice if we could structure this in such a way that local analysis could show that we never dereference a null pointer here.

I wouldn't want to uglify the code unnecessarily, but if a small code change could avoid this false positive, I think it might be worth doing.

Bjorn

#4 lore raw
Quoted 32 lines · Bjorn Helgaas
Quoted 30 lines · Rob Herring
Quoted 28 lines · Gustavo Pimentel
Quoted 24 lines · Bjorn Helgaas

New Coverity complaint about v5.10-rc3, resulting from 9fff3256f93d ("PCI: dwc: Restore ATU memory resource setup to use last entry").

I didn't try to figure out if this is real or a false positive, so just FYI.

----- Forwarded message from [email protected] -----

Date: Mon, 09 Nov 2020 11:13:37 +0000 (UTC)
From: [email protected]
To: [email protected]
Subject: New Defects reported by Coverity Scan for Linux
Message-ID: <[email protected]>

** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc()

________________________________________________________________________________________________________
*** CID 1469110: Null pointer dereferences (FORWARD_NULL) /drivers/pci/controller/dwc/pcie-designware-host.c: 596 in dw_pcie_setup_rc() 590
591 /* Get last memory resource entry */
592 resource_list_for_each_entry(tmp, &pp->bridge->windows)
593 if (resource_type(tmp->res) == IORESOURCE_MEM)

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Can the pp->bridge->windows list be empty in a typical use case?

Only if the DT has missing/malformed 'ranges'. 'ranges' is required to have any memory or i/o space, so we would error out before this point.

There are a lot of paths that lead here, and it's an awful lot of work to verify that they all correctly error out if 'ranges' is invalid.

There used to be, but I've gotten rid of most. There's also only one caller of dw_pcie_setup_rc() in the probe path with my latest series of DWC cleanups that's not applied yet. The only other callers are from a couple of resume hooks (which I plan to define common functions for).

The pci_host_bridge allocation/init fails if bridge->windows is not populated. But actually, 'windows' can never be NULL as it is a list_head. So it's pp or pp->bridge being NULL that's the complaint, but that doesn't really change things. The flow is like this:

dw_pcie_host_init()

    -> devm_pci_alloc_host_bridge()
    pp->bridge = bridge;
    ...
    -> dw_pcie_setup_rc()
Quoted 3 lines

It would really be nice if we could structure this in such a way that local analysis could show that we never dereference a null pointer here.

I've considered making struct pcie_port and struct pci_host_bridge a single allocation. I'm not sure that's really worth doing though.

Quoted 3 lines

I wouldn't want to uglify the code unnecessarily, but if a small code change could avoid this false positive, I think it might be worth doing.

Other than also passing in bridge ptr, not sure. Maybe if it is static which will happen with a common resume routine. That would just shift the problem though it would be a bit clearer that we really couldn't ever get to a resume callback with a NULL.

Rob