public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI/AER: Fix NULL pointer access by aer_info
@ 2025-09-04 18:25 Vernon Yang
  2025-09-11 13:30 ` Vernon Yang
  2025-09-11 22:54 ` Bjorn Helgaas
  0 siblings, 2 replies; 4+ messages in thread
From: Vernon Yang @ 2025-09-04 18:25 UTC (permalink / raw)
  To: mahesh, bhelgaas, oohall
  Cc: linuxppc-dev, linux-pci, linux-kernel, Vernon Yang

From: Vernon Yang <yanglincheng@kylinos.cn>

The kzalloc(GFP_KERNEL) may return NULL, so all accesses to
aer_info->xxx will result in kernel panic. Fix it.

Signed-off-by: Vernon Yang <yanglincheng@kylinos.cn>
---
 drivers/pci/pcie/aer.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index e286c197d716..aeb2534f50dd 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -383,6 +383,10 @@ void pci_aer_init(struct pci_dev *dev)
 		return;
 
 	dev->aer_info = kzalloc(sizeof(*dev->aer_info), GFP_KERNEL);
+	if (!dev->aer_info) {
+		dev->aer_cap = 0;
+		return;
+	}
 
 	ratelimit_state_init(&dev->aer_info->correctable_ratelimit,
 			     DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
-- 
2.51.0


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

* Re: [PATCH] PCI/AER: Fix NULL pointer access by aer_info
  2025-09-04 18:25 [PATCH] PCI/AER: Fix NULL pointer access by aer_info Vernon Yang
@ 2025-09-11 13:30 ` Vernon Yang
  2025-09-11 22:54 ` Bjorn Helgaas
  1 sibling, 0 replies; 4+ messages in thread
From: Vernon Yang @ 2025-09-11 13:30 UTC (permalink / raw)
  To: mahesh, bhelgaas, oohall
  Cc: Vernon Yang, linuxppc-dev, linux-pci, linux-kernel, Vernon Yang

Friendly ping.

> On Sep 5, 2025, at 02:25, Vernon Yang <vernon2gm@gmail.com> wrote:
> 
> From: Vernon Yang <yanglincheng@kylinos.cn>
> 
> The kzalloc(GFP_KERNEL) may return NULL, so all accesses to
> aer_info->xxx will result in kernel panic. Fix it.
> 
> Signed-off-by: Vernon Yang <yanglincheng@kylinos.cn>
> ---
> drivers/pci/pcie/aer.c | 4 ++++
> 1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
> index e286c197d716..aeb2534f50dd 100644
> --- a/drivers/pci/pcie/aer.c
> +++ b/drivers/pci/pcie/aer.c
> @@ -383,6 +383,10 @@ void pci_aer_init(struct pci_dev *dev)
> return;
> 
> dev->aer_info = kzalloc(sizeof(*dev->aer_info), GFP_KERNEL);
> + if (!dev->aer_info) {
> + dev->aer_cap = 0;
> + return;
> + }
> 
> ratelimit_state_init(&dev->aer_info->correctable_ratelimit,
>     DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
> -- 
> 2.51.0
> 


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

* Re: [PATCH] PCI/AER: Fix NULL pointer access by aer_info
  2025-09-04 18:25 [PATCH] PCI/AER: Fix NULL pointer access by aer_info Vernon Yang
  2025-09-11 13:30 ` Vernon Yang
@ 2025-09-11 22:54 ` Bjorn Helgaas
  2025-09-11 23:41   ` Keith Busch
  1 sibling, 1 reply; 4+ messages in thread
From: Bjorn Helgaas @ 2025-09-11 22:54 UTC (permalink / raw)
  To: Vernon Yang
  Cc: mahesh, bhelgaas, oohall, linuxppc-dev, linux-pci, linux-kernel,
	Vernon Yang, Terry Bowman, Robert Richter, linux-cxl,
	Smita Koralahalli, Dongdong Liu

[+cc Terry, Robert, CXL list, Smita, Dongdong]

On Fri, Sep 05, 2025 at 02:25:27AM +0800, Vernon Yang wrote:
> From: Vernon Yang <yanglincheng@kylinos.cn>
> 
> The kzalloc(GFP_KERNEL) may return NULL, so all accesses to
> aer_info->xxx will result in kernel panic. Fix it.
> 
> Signed-off-by: Vernon Yang <yanglincheng@kylinos.cn>

Applied to pci/aer for v6.18, thanks, Vernon!

Not directly related to this patch, but I'm concerned about some users
of dev->aer_cap.

Most users of dev->aer_cap either (a) check that it's set before using
it or (b) are called in paths obviously only reachable via an AER
interrupt.

But there are a few users of dev->aer_cap that use it without checking
it for zero, and it's not obvious to me that it must be valid:

  - pci_aer_unmask_internal_errors(), added by b7e9392d5d46 ("PCI/AER:
    Unmask RCEC internal errors to enable RCH downstream port error
    handling")

  - dpc_get_aer_uncorrect_severity(), added by 9f08a5d896ce ("PCI/DPC:
    Fix print AER status in DPC event handling")

  - dpc_is_surprise_removal(), added by 2ae8fbbe1cd4 ("PCI/DPC: Ignore
    Surprise Down error on hot removal")

> ---
>  drivers/pci/pcie/aer.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
> index e286c197d716..aeb2534f50dd 100644
> --- a/drivers/pci/pcie/aer.c
> +++ b/drivers/pci/pcie/aer.c
> @@ -383,6 +383,10 @@ void pci_aer_init(struct pci_dev *dev)
>  		return;
>  
>  	dev->aer_info = kzalloc(sizeof(*dev->aer_info), GFP_KERNEL);
> +	if (!dev->aer_info) {
> +		dev->aer_cap = 0;
> +		return;
> +	}
>  
>  	ratelimit_state_init(&dev->aer_info->correctable_ratelimit,
>  			     DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);
> -- 
> 2.51.0
> 

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

* Re: [PATCH] PCI/AER: Fix NULL pointer access by aer_info
  2025-09-11 22:54 ` Bjorn Helgaas
@ 2025-09-11 23:41   ` Keith Busch
  0 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2025-09-11 23:41 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Vernon Yang, mahesh, bhelgaas, oohall, linuxppc-dev, linux-pci,
	linux-kernel, Vernon Yang, Terry Bowman, Robert Richter,
	linux-cxl, Smita Koralahalli, Dongdong Liu

On Thu, Sep 11, 2025 at 05:54:57PM -0500, Bjorn Helgaas wrote:
> [+cc Terry, Robert, CXL list, Smita, Dongdong]
> 
> On Fri, Sep 05, 2025 at 02:25:27AM +0800, Vernon Yang wrote:
> > From: Vernon Yang <yanglincheng@kylinos.cn>
> > 
> > The kzalloc(GFP_KERNEL) may return NULL, so all accesses to
> > aer_info->xxx will result in kernel panic. Fix it.
> > 
> > Signed-off-by: Vernon Yang <yanglincheng@kylinos.cn>
> 
> Applied to pci/aer for v6.18, thanks, Vernon!
> 
> Not directly related to this patch, but I'm concerned about some users
> of dev->aer_cap.

pci_aer_init is called pretty early during boot. If we can't malloc a
few hundred bytes at that point, the aer_cap users will be the least of
your concerns. :)

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

end of thread, other threads:[~2025-09-11 23:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-04 18:25 [PATCH] PCI/AER: Fix NULL pointer access by aer_info Vernon Yang
2025-09-11 13:30 ` Vernon Yang
2025-09-11 22:54 ` Bjorn Helgaas
2025-09-11 23:41   ` Keith Busch

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