Re: [PATCH v1 19/19] PCI/ERR: Avoid NULL bridge pointer
From: Yazen Ghannam
Date: Wed Nov 25 2026 - 11:58:06 EST
On Wed, Nov 25, 2026 at 05:30:32PM +0100, Pierre Gondois wrote:
>
> On 11/24/26 17:00, Yazen Ghannam wrote:
> > On Wed, Nov 18, 2026 at 04:11:48PM +0100, Pierre Gondois wrote:
> > > Hello Lukas, Kuppuswamy,
> > >
> > > On 11/17/26 19:57, Kuppuswamy Sathyanarayanan wrote:
> > > > On 11/17/26 03:50, Lukas Wunner wrote:
> > > > > On Tue, Nov 17, 2026 at 12:10:29PM +0100, Pierre Gondois wrote:
> > > > > > Return PCI_ERS_RESULT_DISCONNECT when no upstream bridge is available,
> > > > > > avoiding a NULL pointer dereference in pci_walk_bridge().
> > > > > How can that happen? If it can happen (which I doubt), why isn't this
> > > > > patch tagged for stable?
> > > > One way I can see is a device without a PCIe capability on a root bus.
> > > > pci_pcie_type() returns 0, which is PCI_EXP_TYPE_ENDPOINT, and
> > > > pci_upstream_bridge() returns NULL. Native AER never gets there. Only
> > > > firmware-first can, through aer_recover_work_func(), and only if
> > > > firmware reports a PCIe error section for such a device. If that is
> > > > the case, skipping recovery for !pci_is_pcie(pdev) in
> > > > aer_recover_work_func() seems a better fit than a check in
> > > > pcie_do_recovery().
> > > >
> > > > > Why is it at the end of this series? Does the series somehow make it
> > > > > possible that there's no upstream bridge? Which patch does that?
> > > > > If the preceding patches are not the cause of a potential NULL
> > > > > pointer deref, why isn't this patch submitted separately from the series?
> > > To test this serie, I generated and injected synthetic CPER records.
> > > The PCI device referenced in some synthetic CPER records did not
> > > actually exist. In such case, the kernel crashes due to a NULL
> > > pointer deferencement.
> > >
> > > This use case is indeed slightly unsusual and unlikely to happen
> > > in the real world. The patch was still included in the serie.
> > >
> > > Please let me know if the patch should be either dropped or better
> > > documented.
> > It would be good to include these details in the commit message.
> >
> > Also, I agree it is fair to be prepared for, and gracefully handle,
> > unexpected data from firmware. A platform may report a CPER to OS with
> > the intention that the data is only for reporting purposes, not recovery
> > action.
> >
> > **BUT**, we could argue this is a platform bug. CPER serverity is one
> > item used to decide if recovery should be attempted. The platform should
> > not report a severity that indicates recovery/action is needed while
> > giving bogus/incomplete data.
> >
> > If the platform is intending to share data for reporting only, then the
> > CPER severity should be set appropriately.
> >
> > Otherwise, this should be a big FW_BUG message "Platform reported
> > recoverable error for unknown device."
>
> I'm not sure to understand. Are you saying that we should
> try to fetch/resolve the PCI bridge in pci_aer_handle_error()
> before calling pcie_do_recovery() ?
>
I'm not sure where the best place is. Your patch adds a generic warning
in pcie_do_recovery(). It is not clear from this why the bridge is not
found. Is it because of a major hardware/topology issue or an
inconsistent error record?
To differentiate these two, you may need to do the check earlier. Or you
may need to pass in another piece of info indicating the source of the
report. Maybe a check for "native AER" is enough in this case.
Thanks,
Yazen