Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Priyank Rathod" <rathodpriyank@google.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI/AER: Fix struct pci_dev reference leak in aer_process_err_devices()
Date: Sun, 30 Aug 2026 20:39:26 +0000	[thread overview]
Message-ID: <20260830203926.F2C261F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260830-fix-aer-refcount-leak-v1-1-64e1013add12@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Lockless access to `dev->driver` in `pci_aer_handle_error` can lead to use-after-free if the driver is concurrently unbound.
--

commit 9885b6e8d159d70ef8c2c474b114ae69fb1805af
Author: Priyank Rathod <rathodpriyank@google.com>

PCI/AER: Fix struct pci_dev reference leak in aer_process_err_devices()

This commit fixes a reference leak on struct pci_dev that occurs when a device
without the AER extended capability is added as an error source. It does this
by decoupling device reference release from handle_error_source() and calling
pci_dev_put() unconditionally in aer_process_err_devices().

> diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
> index c4fd9c0b2a548..2401b3a18f07d 100644
> --- a/drivers/pci/pcie/aer.c
> +++ b/drivers/pci/pcie/aer.c
> @@ -1197,7 +1197,6 @@ static void handle_error_source(struct pci_dev *dev, struct aer_err_info *info)
>  {
>  	cxl_rch_handle_error(dev, info);
>  	pci_aer_handle_error(dev, info);

[Severity: High]
This isn't a bug introduced by this patch, but does pci_aer_handle_error()
safely access dev->driver?

Looking at pci_aer_handle_error() in drivers/pci/pcie/aer.c, when handling
correctable errors, it reads dev->driver into a local pointer without
holding the device lock:

static void pci_aer_handle_error(struct pci_dev *dev, struct aer_err_info *info)
{
	...
	if (info->severity == AER_CORRECTABLE) {
		...
		if (pcie_aer_is_native(dev)) {
			struct pci_driver *pdrv = dev->driver;

			if (pdrv && pdrv->err_handler &&
			    pdrv->err_handler->cor_error_detected)
				pdrv->err_handler->cor_error_detected(dev);
			...
		}
	}
	...
}

Since pci_aer_handle_error() executes in a threaded IRQ context (via
aer_process_err_devices()), could a concurrent sysfs driver unbind or module
unload clear dev->driver and free the driver module immediately after the
pointer is read?

This contrasts with pcie_do_recovery() and cxl_rch_handle_error_iter(), which
appear to correctly hold the device lock (device_lock(&dev->dev)) before
accessing dev->driver.

> -	pci_dev_put(dev);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260830-fix-aer-refcount-leak-v1-1-64e1013add12@google.com?part=1

  reply	other threads:[~2026-08-30 20:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-30 20:28 [PATCH] PCI/AER: Fix struct pci_dev reference leak in aer_process_err_devices() Priyank Rathod
2026-08-30 20:39 ` sashiko-bot [this message]
2026-08-30 21:02 ` Lukas Wunner
2026-08-30 21:14 ` Lukas Wunner
2026-08-31  3:24   ` Priyank Rathod

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=20260830203926.F2C261F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rathodpriyank@google.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