Re: [PATCH v8 18/20] PCI/AER: Ratelimit correctable and non-fatal error logging

Breno Leitao
2025-08-01T13:35:25Z

On Fri, Aug 01, 2025 at 06:16:29AM -0700, Breno Leitao wrote:
> Hello Jon, Bjorn,
>
> On Thu, May 22, 2025 at 06:21:24PM -0500, Bjorn Helgaas wrote:
> > @@ -790,6 +818,9 @@ void pci_print_aer(struct pci_dev *dev, int aer_severity,
> > trace_aer_event(pci_name(dev), (status & ~mask),
> > aer_severity, tlp_header_valid, &aer->header_log);
> >
> > + if (!aer_ratelimit(dev, info.severity))
> > + return;
>
> I am seeing a kernel NULL pointer in the aer_ratelimit(), where
> dev->aer_info is NULL. This is happening on linus final 6.16 commit id.

Upon closer examination of the code, it appears we can replicate the
functionality of `pci_dev_aer_stats_incr()`, which is similarly invoked
within this code path.

commit 1b4ef90e8397eaf2bc4d0f8a2127d2d75c7ff5e0
Author: Breno Leitao <leitao@debian.org>
Date: Fri Aug 1 06:32:26 2025 -0700

PCI/AER: Check for NULL aer_info before ratelimiting in pci_print_aer()

Similarly to pci_dev_aer_stats_incr(), pci_print_aer() may be called
when dev->aer_info is NULL. Add a NULL check before proceeding to avoid
calling aer_ratelimit() with a NULL aer_info pointer, returning 1, which
does not rate limit, given this is fatal.

This prevents a kernel crash triggered by dereferencing a NULL pointer
in aer_ratelimit(), ensuring safer handling of PCI devices that lack
AER info. This change aligns pci_print_aer() with pci_dev_aer_stats_incr()
which already performs this NULL check.

Signed-off-by: Breno Leitao <leitao@debian.org>
Fixes: a57f2bfb4a5863 ("PCI/AER: Ratelimit correctable and non-fatal
error logging")

diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index 70ac661883672..b5f96fde4dcda 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -786,6 +786,9 @@ static void pci_rootport_aer_stats_incr(struct pci_dev *pdev,

static int aer_ratelimit(struct pci_dev *dev, unsigned int severity)
{
+ if (!dev->aer_info)
+ return 1;
+
switch (severity) {
case AER_NONFATAL:
return __ratelimit(&dev->aer_info->nonfatal_ratelimit);