PCI: ACPI: Check parent pointer in acpi_pci_find_companion()
PATCH 1/1 PCI: ACPI: Check parent pointer in acpi_pci_find_companion()
From: Rafael J. Wysocki <[email protected]>
If acpi_pci_find_companion() is called for a device whose parent pointer is NULL, it will crash when attempting to get the ACPI companion of the parent due to a NULL pointer dereference in the ACPI_COMPANION() macro.
This was not a problem before commit 375553a93201 ("PCI: Setup ACPI fwnode early and at the same time with OF") that made pci_setup_device() call pci_set_acpi_fwnode() and so it allowed devices with NULL parent pointers to be passed to acpi_pci_find_companion() which is the case in pci_iov_add_virtfn(), for instance.
Fix this issue by making acpi_pci_find_companion() check the device's parent pointer upfront and bail out if it is NULL.
While pci_iov_add_virtfn() can be changed to set the device's parent pointer before calling pci_setup_device() for it, checking pointers against NULL before dereferencing them is prudent anyway and looking for ACPI companions of virtual functions isn't really useful.
--- drivers/pci/pci-acpi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/pci-acpi.c +3 -0
@@ -1243,6 +1243,9 @@ static struct acpi_device *acpi_pci_findbool check_children;u64 addr; +if (!dev->parent) +return NULL ; +down_read (&pci_acpi_companion_lookup_sem); adev = pci_acpi_find_companion_hook ?
Rafael J. Wysocki
maintainerQuoted 22 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If
acpi_pci_find_companion()is called for a device whose parent pointer is NULL, it will crash when attempting to get the ACPI companion of the parent due to a NULL pointer dereference in theACPI_COMPANION()macro.This was not a problem before commit
375553a93201("PCI: Setup ACPI fwnode early and at the same time with OF") that madepci_setup_device()callpci_set_acpi_fwnode()and so it allowed devices with NULL parent pointers to be passed toacpi_pci_find_companion()which is the case inpci_iov_add_virtfn(), for instance.Fix this issue by making
acpi_pci_find_companion()check the device's parent pointer upfront and bail out if it is NULL.While
pci_iov_add_virtfn()can be changed to set the device's parent pointer before callingpci_setup_device()for it, checking pointers against NULL before dereferencing them is prudent anyway and looking for ACPI companions of virtual functions isn't really useful.
Quoted 5 lines
Fixes 375553a93201 ("PCI: Setup ACPI fwnode early and at the same time with OF")Reported-by Niklas Schnelle <[email protected]>Tested-by Niklas Schnelle <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>
Due to the lack of negative feedback I'm queuing this up for 5.15-rc5. If there are concerns, please let me know.
Quoted 21 lines
--- drivers/pci/pci-acpi.c | 3 +++ 1 file changed, 3 insertions(+)Index:
linux-pm/drivers/pci/pci-acpi.c
===================================================================drivers/pci/pci-acpi.c +3
-0@@ -1243,6 +1243,9 @@ static struct acpi_device *acpi_pci_findbool check_children;u64 addr; +if (!dev->parent) +return NULL ; +down_read (&pci_acpi_companion_lookup_sem); adev = pci_acpi_find_companion_hook ?
Quoted 21 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
If
acpi_pci_find_companion()is called for a device whose parent pointer is NULL, it will crash when attempting to get the ACPI companion of the parent due to a NULL pointer dereference in theACPI_COMPANION()macro.This was not a problem before commit
375553a93201("PCI: Setup ACPI fwnode early and at the same time with OF") that madepci_setup_device()callpci_set_acpi_fwnode()and so it allowed devices with NULL parent pointers to be passed toacpi_pci_find_companion()which is the case inpci_iov_add_virtfn(), for instance.Fix this issue by making
acpi_pci_find_companion()check the device's parent pointer upfront and bail out if it is NULL.While
pci_iov_add_virtfn()can be changed to set the device's parent pointer before callingpci_setup_device()for it, checking pointers against NULL before dereferencing them is prudent anyway and looking for ACPI companions of virtual functions isn't really useful.
Quoted 5 lines
Fixes 375553a93201 ("PCI: Setup ACPI fwnode early and at the same time with OF")Reported-by Niklas Schnelle <[email protected]>Tested-by Niklas Schnelle <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>
Quoted 21 lines
--- drivers/pci/pci-acpi.c | 3 +++ 1 file changed, 3 insertions(+)Index:
linux-pm/drivers/pci/pci-acpi.c
===================================================================drivers/pci/pci-acpi.c +3
-0@@ -1243,6 +1243,9 @@ static struct acpi_device *acpi_pci_findbool check_children;u64 addr; +if (!dev->parent) +return NULL ; +down_read (&pci_acpi_companion_lookup_sem); adev = pci_acpi_find_companion_hook ?