Skip to contentSkip to conversation

PCI/AER: Fix NULL pointer access by aer_info

PATCH Applied Vernon Yang 3 participants 4 messages Sep 4, 2025 – Sep 11, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI/AER: Fix NULL pointer access by aer_info

From: Vernon Yang <[email protected]>

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

---
 drivers/pci/pcie/aer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pcie/aer.c +4 -0
index e286c197d716..aeb2534f50dd 100644
@@ -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);
Signature · 1 line
2.51.0
#1 lore raw

Friendly ping.

Quoted 30 lines · Vernon Yang

From: Vernon Yang <[email protected]>

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

---
drivers/pci/pcie/aer.c | 4 ++++

1 file changed, 4 insertions(+)
drivers/pci/pcie/aer.c +4 -0
index e286c197d716..aeb2534f50dd 100644
@@ -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);
Signature · 1 line
2.51.0
#2 lore raw
In reply to Vernon Yang

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

Quoted 6 lines · Vernon Yang

From: Vernon Yang <[email protected]>

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

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")

Quoted 22 lines
---
 drivers/pci/pcie/aer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pcie/aer.c +4 -0
index e286c197d716..aeb2534f50dd 100644
@@ -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);
Signature · 1 line
2.51.0
#3 lore raw
Quoted 8 lines · Bjorn Helgaas

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

Quoted 5 lines · Vernon Yang

From: Vernon Yang <[email protected]>

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

Quoted 6 lines
Quoted 1 line

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. :)