public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind()
@ 2024-11-05 12:07 Zhongqiu Han
  2024-11-05 13:36 ` Niklas Cassel
  2024-11-05 17:38 ` Krzysztof Wilczyński
  0 siblings, 2 replies; 4+ messages in thread
From: Zhongqiu Han @ 2024-11-05 12:07 UTC (permalink / raw)
  To: manivannan.sadhasivam, kw, kishon, bhelgaas, lpieralisi, dlemoal
  Cc: quic_zhonhan, mhi, linux-arm-msm, linux-pci, linux-kernel

If platform_get_resource_byname() fails and returns NULL, dereferencing
res->start will cause a NULL pointer access. Add a check to prevent it.

Fixes: 1bf5f25324f7 ("PCI: endpoint: Add PCI Endpoint function driver for MHI bus")
Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
---
 drivers/pci/endpoint/functions/pci-epf-mhi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
index 7d070b1def11..2712026733ab 100644
--- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
+++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
@@ -873,6 +873,11 @@ static int pci_epf_mhi_bind(struct pci_epf *epf)
 
 	/* Get MMIO base address from Endpoint controller */
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mmio");
+	if (!res) {
+		dev_err(&pdev->dev, "Failed to get MMIO base address\n");
+		return -ENODEV;
+	}
+
 	epf_mhi->mmio_phys = res->start;
 	epf_mhi->mmio_size = resource_size(res);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind()
  2024-11-05 12:07 [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind() Zhongqiu Han
@ 2024-11-05 13:36 ` Niklas Cassel
  2024-11-05 16:07   ` Krzysztof Wilczyński
  2024-11-05 17:38 ` Krzysztof Wilczyński
  1 sibling, 1 reply; 4+ messages in thread
From: Niklas Cassel @ 2024-11-05 13:36 UTC (permalink / raw)
  To: Zhongqiu Han
  Cc: manivannan.sadhasivam, kw, kishon, bhelgaas, lpieralisi, dlemoal,
	mhi, linux-arm-msm, linux-pci, linux-kernel

On Tue, Nov 05, 2024 at 08:07:35PM +0800, Zhongqiu Han wrote:
> If platform_get_resource_byname() fails and returns NULL, dereferencing
> res->start will cause a NULL pointer access. Add a check to prevent it.
> 
> Fixes: 1bf5f25324f7 ("PCI: endpoint: Add PCI Endpoint function driver for MHI bus")
> Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
> ---
>  drivers/pci/endpoint/functions/pci-epf-mhi.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> index 7d070b1def11..2712026733ab 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> @@ -873,6 +873,11 @@ static int pci_epf_mhi_bind(struct pci_epf *epf)
>  
>  	/* Get MMIO base address from Endpoint controller */
>  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mmio");
> +	if (!res) {
> +		dev_err(&pdev->dev, "Failed to get MMIO base address\n");

dev_err(&epf->dev, "Failed to get mmio resource\n");
or
dev_err(&epf->dev, "Failed to get \"mmio\" resource\n");

Note: &epf->dev instead of &pdev->dev in order to be consistent with other
EPF ->bind() functions.

With that, feel free to add:
Reviewed-by: Niklas Cassel <cassel@kernel.org>


Kind regards,
Niklas

> +		return -ENODEV;
> +	}
> +
>  	epf_mhi->mmio_phys = res->start;
>  	epf_mhi->mmio_size = resource_size(res);
>  
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind()
  2024-11-05 13:36 ` Niklas Cassel
@ 2024-11-05 16:07   ` Krzysztof Wilczyński
  0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Wilczyński @ 2024-11-05 16:07 UTC (permalink / raw)
  To: Niklas Cassel
  Cc: Zhongqiu Han, manivannan.sadhasivam, kishon, bhelgaas, lpieralisi,
	dlemoal, mhi, linux-arm-msm, linux-pci, linux-kernel

Hello,

[...]
> >  	/* Get MMIO base address from Endpoint controller */
> >  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mmio");
> > +	if (!res) {
> > +		dev_err(&pdev->dev, "Failed to get MMIO base address\n");
> 
> dev_err(&epf->dev, "Failed to get mmio resource\n");
> or
> dev_err(&epf->dev, "Failed to get \"mmio\" resource\n");
> 
> Note: &epf->dev instead of &pdev->dev in order to be consistent with other
> EPF ->bind() functions.
> 
> With that, feel free to add:
> Reviewed-by: Niklas Cassel <cassel@kernel.org>

Thank you Niklas!

No need to send a new version of this patch.  I will update it on the
branch when applying.  Thank you!

	Krzysztof

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind()
  2024-11-05 12:07 [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind() Zhongqiu Han
  2024-11-05 13:36 ` Niklas Cassel
@ 2024-11-05 17:38 ` Krzysztof Wilczyński
  1 sibling, 0 replies; 4+ messages in thread
From: Krzysztof Wilczyński @ 2024-11-05 17:38 UTC (permalink / raw)
  To: Zhongqiu Han
  Cc: manivannan.sadhasivam, kishon, bhelgaas, lpieralisi, dlemoal, mhi,
	linux-arm-msm, linux-pci, linux-kernel

Hello,

> If platform_get_resource_byname() fails and returns NULL, dereferencing
> res->start will cause a NULL pointer access. Add a check to prevent it.

Applied to endpoint, thank you!

[01/01] PCI: endpoint: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind()
        https://git.kernel.org/pci/pci/c/ff977d1bf478

	Krzysztof

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-05 17:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-05 12:07 [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind() Zhongqiu Han
2024-11-05 13:36 ` Niklas Cassel
2024-11-05 16:07   ` Krzysztof Wilczyński
2024-11-05 17:38 ` Krzysztof Wilczyński

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox