From: sashiko-bot@kernel.org
To: "Ruoyu Wang" <ruoyuw560@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] xen/pcifront: Fix PCI device reference leak in AER handling
Date: Thu, 13 Aug 2026 15:41:10 +0000 [thread overview]
Message-ID: <20260813154111.619221F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260813153138.3953222-1-ruoyuw560@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Accessing `pcidev->dev.driver` and invoking driver AER callbacks without holding `device_lock` risks a Use-After-Free due to concurrent driver unbinding.
- [High] Unconditional invocation of optional AER callbacks (`mmio_enabled`, `slot_reset`, `resume`) without verifying they are implemented by the driver.
--
--- Patch [1]: [PATCH] xen/pcifront: Fix PCI device reference leak in AER handling ---
commit 8d4be8a3c9e93de894d26cb69e9804d8f8ff8144
Author: Ruoyu Wang <ruoyuw560@gmail.com>
xen/pcifront: Fix PCI device reference leak in AER handling
This commit fixes a reference leak in pcifront_common_process by storing
the AER callback result, releasing the device reference, and then returning.
This keeps the device alive while its callback runs and balances the lookup
on every successful path.
> --- a/drivers/pci/xen-pcifront.c
> +++ b/drivers/pci/xen-pcifront.c
[ ... ]
> @@ -597,21 +598,25 @@ static pci_ers_result_t pcifront_common_process(int cmd,
> pci_dbg(pcidev, "trying to call AER service\n");
> switch (cmd) {
> case XEN_PCI_OP_aer_detected:
> - return pdrv->err_handler->error_detected(pcidev, state);
> + result = pdrv->err_handler->error_detected(pcidev, state);
> + break;
[Severity: High]
This isn't a bug introduced by this patch, but is it safe to access the
driver pointer and invoke callbacks in this function without holding the
device lock?
The code earlier extracts the driver:
pcidev = pci_get_domain_bus_and_slot(domain, bus, devfn);
if (!pcidev || !pcidev->dev.driver) {
...
}
pdrv = to_pci_driver(pcidev->dev.driver);
If a concurrent unbind occurs (for example, via sysfs), can the driver be
unbound and freed between the check for pcidev->dev.driver and the callback
invocation? Core PCI error recovery typically holds the device lock to prevent
a use-after-free or NULL pointer dereference in this scenario.
> case XEN_PCI_OP_aer_mmio:
> - return pdrv->err_handler->mmio_enabled(pcidev);
> + result = pdrv->err_handler->mmio_enabled(pcidev);
> + break;
> case XEN_PCI_OP_aer_slotreset:
> - return pdrv->err_handler->slot_reset(pcidev);
> + result = pdrv->err_handler->slot_reset(pcidev);
> + break;
[Severity: High]
This is a pre-existing issue, but does this code assume all drivers
implement the optional AER callbacks?
The function checks if the error_detected callback is present before
entering the switch statement:
if (pdrv->err_handler && pdrv->err_handler->error_detected) {
...
}
However, many PCI drivers do not implement mmio_enabled, slot_reset, or
resume. If the Xen backend forwards one of these events for a driver lacking
the specific callback, could invoking it here result in an immediate NULL
pointer dereference?
> case XEN_PCI_OP_aer_resume:
> pdrv->err_handler->resume(pcidev);
> - return PCI_ERS_RESULT_NONE;
> + break;
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260813153138.3953222-1-ruoyuw560@gmail.com?part=1
prev parent reply other threads:[~2026-08-13 15:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 15:31 [PATCH] xen/pcifront: Fix PCI device reference leak in AER handling Ruoyu Wang
2026-08-13 15:41 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260813154111.619221F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ruoyuw560@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox