* [PATCH] x86/PCI: Fix Null pointer dereference after call to pcie_find_root_port()
@ 2024-08-12 20:26 Samasth Norway Ananda
2024-08-12 20:51 ` Bjorn Helgaas
2024-08-20 23:36 ` Bjorn Helgaas
0 siblings, 2 replies; 4+ messages in thread
From: Samasth Norway Ananda @ 2024-08-12 20:26 UTC (permalink / raw)
To: bhelgaas; +Cc: linux-pci, samasth.norway.ananda
If pcie_find_root_port() is unable to locate a root port, it will return
NULL. This NULL pointer needs to be handled before trying to dereference.
Fixes: 7d08f21f8c63 ("x86/PCI: Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4")
Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
---
arch/x86/pci/fixup.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c
index b33afb240601..98a9bb92d75c 100644
--- a/arch/x86/pci/fixup.c
+++ b/arch/x86/pci/fixup.c
@@ -980,7 +980,7 @@ static void amd_rp_pme_suspend(struct pci_dev *dev)
return;
rp = pcie_find_root_port(dev);
- if (!rp->pm_cap)
+ if (!rp || !rp->pm_cap)
return;
rp->pme_support &= ~((PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>
@@ -994,7 +994,7 @@ static void amd_rp_pme_resume(struct pci_dev *dev)
u16 pmc;
rp = pcie_find_root_port(dev);
- if (!rp->pm_cap)
+ if (!rp || !rp->pm_cap)
return;
pci_read_config_word(rp, rp->pm_cap + PCI_PM_PMC, &pmc);
--
2.45.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/PCI: Fix Null pointer dereference after call to pcie_find_root_port()
2024-08-12 20:26 [PATCH] x86/PCI: Fix Null pointer dereference after call to pcie_find_root_port() Samasth Norway Ananda
@ 2024-08-12 20:51 ` Bjorn Helgaas
2024-08-20 21:01 ` Mario Limonciello
2024-08-20 23:36 ` Bjorn Helgaas
1 sibling, 1 reply; 4+ messages in thread
From: Bjorn Helgaas @ 2024-08-12 20:51 UTC (permalink / raw)
To: Samasth Norway Ananda; +Cc: bhelgaas, linux-pci, Mario Limonciello
[+cc Mario, 7d08f21f8c63 author]
On Mon, Aug 12, 2024 at 01:26:59PM -0700, Samasth Norway Ananda wrote:
> If pcie_find_root_port() is unable to locate a root port, it will return
> NULL. This NULL pointer needs to be handled before trying to dereference.
>
> Fixes: 7d08f21f8c63 ("x86/PCI: Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4")
> Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
> ---
> arch/x86/pci/fixup.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c
> index b33afb240601..98a9bb92d75c 100644
> --- a/arch/x86/pci/fixup.c
> +++ b/arch/x86/pci/fixup.c
> @@ -980,7 +980,7 @@ static void amd_rp_pme_suspend(struct pci_dev *dev)
> return;
>
> rp = pcie_find_root_port(dev);
> - if (!rp->pm_cap)
> + if (!rp || !rp->pm_cap)
Seems reasonable. I suspect we haven't seen problems because these
quirks are limited to Device IDs that are all PCIe, but I think we
should check on principle and because it may be copied elsewhere where
it *does* matter.
> return;
>
> rp->pme_support &= ~((PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>
> @@ -994,7 +994,7 @@ static void amd_rp_pme_resume(struct pci_dev *dev)
> u16 pmc;
>
> rp = pcie_find_root_port(dev);
> - if (!rp->pm_cap)
> + if (!rp || !rp->pm_cap)
> return;
>
> pci_read_config_word(rp, rp->pm_cap + PCI_PM_PMC, &pmc);
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/PCI: Fix Null pointer dereference after call to pcie_find_root_port()
2024-08-12 20:51 ` Bjorn Helgaas
@ 2024-08-20 21:01 ` Mario Limonciello
0 siblings, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2024-08-20 21:01 UTC (permalink / raw)
To: Bjorn Helgaas, Samasth Norway Ananda; +Cc: bhelgaas, linux-pci
On 8/12/2024 15:51, Bjorn Helgaas wrote:
> [+cc Mario, 7d08f21f8c63 author]
>
> On Mon, Aug 12, 2024 at 01:26:59PM -0700, Samasth Norway Ananda wrote:
>> If pcie_find_root_port() is unable to locate a root port, it will return
>> NULL. This NULL pointer needs to be handled before trying to dereference.
>>
>> Fixes: 7d08f21f8c63 ("x86/PCI: Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4")
>> Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
>> ---
>> arch/x86/pci/fixup.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c
>> index b33afb240601..98a9bb92d75c 100644
>> --- a/arch/x86/pci/fixup.c
>> +++ b/arch/x86/pci/fixup.c
>> @@ -980,7 +980,7 @@ static void amd_rp_pme_suspend(struct pci_dev *dev)
>> return;
>>
>> rp = pcie_find_root_port(dev);
>> - if (!rp->pm_cap)
>> + if (!rp || !rp->pm_cap)
>
> Seems reasonable. I suspect we haven't seen problems because these
> quirks are limited to Device IDs that are all PCIe, but I think we
> should check on principle and because it may be copied elsewhere where
> it *does* matter.
Yeah totally agree, if nothing else it prevents copy/paste mistakes.
HOWEVER I don't think this needs to be a "Fixes" tag because there is no
problem in THIS code on the applicable systems. Those PCI devices are
always attached to a root port. So Bjorn I would suggest stripping the
Fixes tag when committing.
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
>
>> return;
>>
>> rp->pme_support &= ~((PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>
>> @@ -994,7 +994,7 @@ static void amd_rp_pme_resume(struct pci_dev *dev)
>> u16 pmc;
>>
>> rp = pcie_find_root_port(dev);
>> - if (!rp->pm_cap)
>> + if (!rp || !rp->pm_cap)
>> return;
>>
>> pci_read_config_word(rp, rp->pm_cap + PCI_PM_PMC, &pmc);
>> --
>> 2.45.2
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/PCI: Fix Null pointer dereference after call to pcie_find_root_port()
2024-08-12 20:26 [PATCH] x86/PCI: Fix Null pointer dereference after call to pcie_find_root_port() Samasth Norway Ananda
2024-08-12 20:51 ` Bjorn Helgaas
@ 2024-08-20 23:36 ` Bjorn Helgaas
1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2024-08-20 23:36 UTC (permalink / raw)
To: Samasth Norway Ananda; +Cc: bhelgaas, linux-pci, Mario Limonciello
On Mon, Aug 12, 2024 at 01:26:59PM -0700, Samasth Norway Ananda wrote:
> If pcie_find_root_port() is unable to locate a root port, it will return
> NULL. This NULL pointer needs to be handled before trying to dereference.
>
> Fixes: 7d08f21f8c63 ("x86/PCI: Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4")
> Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com>
Applied with Mario's Reviewed-by to pci/misc for v6.12, thank you!
> ---
> arch/x86/pci/fixup.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c
> index b33afb240601..98a9bb92d75c 100644
> --- a/arch/x86/pci/fixup.c
> +++ b/arch/x86/pci/fixup.c
> @@ -980,7 +980,7 @@ static void amd_rp_pme_suspend(struct pci_dev *dev)
> return;
>
> rp = pcie_find_root_port(dev);
> - if (!rp->pm_cap)
> + if (!rp || !rp->pm_cap)
> return;
>
> rp->pme_support &= ~((PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>
> @@ -994,7 +994,7 @@ static void amd_rp_pme_resume(struct pci_dev *dev)
> u16 pmc;
>
> rp = pcie_find_root_port(dev);
> - if (!rp->pm_cap)
> + if (!rp || !rp->pm_cap)
> return;
>
> pci_read_config_word(rp, rp->pm_cap + PCI_PM_PMC, &pmc);
> --
> 2.45.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-20 23:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-12 20:26 [PATCH] x86/PCI: Fix Null pointer dereference after call to pcie_find_root_port() Samasth Norway Ananda
2024-08-12 20:51 ` Bjorn Helgaas
2024-08-20 21:01 ` Mario Limonciello
2024-08-20 23:36 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox