From: sashiko-bot@kernel.org
To: ZhaoJinming <zhaojinming@uniontech.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI/ASPM: Add missing NULL check for link in sysfs show/store callbacks
Date: Mon, 27 Jul 2026 07:41:28 +0000 [thread overview]
Message-ID: <20260727074129.4F1E51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727072915.3954329-1-zhaojinming@uniontech.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] Inconsistent Return Code in sysfs show callbacks
Pre-existing issues:
- [High] Use-After-Free (TOCTOU Race) due to lockless fetch of pcie_link_state
--
--- Patch [1]: [PATCH] PCI/ASPM: Add missing NULL check for link in sysfs show/store callbacks ---
commit 123c7550e88a60508484ee2915e5a520ce8e1364
Author: ZhaoJinming <zhaojinming@uniontech.com>
PCI/ASPM: Add missing NULL check for link in sysfs show/store callbacks
This commit adds NULL checks for the return value of pcie_aspm_get_link() in
the ASPM and clkpm sysfs show and store callbacks. It aims to prevent NULL
pointer dereferences when the device is not PCIe or the link state has not
been initialized.
> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> index 172783e7f519a..108d151a786e7 100644
> --- a/drivers/pci/pcie/aspm.c
> +++ b/drivers/pci/pcie/aspm.c
> @@ -1654,6 +1654,9 @@ static ssize_t aspm_attr_show_common(struct device *dev,
> struct pci_dev *pdev = to_pci_dev(dev);
> struct pcie_link_state *link = pcie_aspm_get_link(pdev);
>
> + if (!link)
> + return 0;
> +
[Severity: Low]
Does returning 0 here mean a successful read of 0 bytes, presenting an empty
file to userspace instead of an error? Should this return -ENODEV similar
to the corresponding store callback?
> return sysfs_emit(buf, "%d\n", (link->aspm_enabled & state) ? 1 : 0);
> }
>
> @@ -1665,6 +1668,9 @@ static ssize_t aspm_attr_store_common(struct device *dev,
> struct pcie_link_state *link = pcie_aspm_get_link(pdev);
> bool state_enable;
>
> + if (!link)
> + return -ENODEV;
> +
[Severity: High]
This isn't a bug introduced by this patch, but does fetching the link
locklessly here introduce a use-after-free race?
If a concurrent device hot-unplug of a sibling function occurs,
pcie_aspm_exit_link_state() could acquire the aspm_lock, free the shared link
structure, and set the parent's link_state to NULL.
Because this sysfs callback fetches the link before acquiring the lock, could
it hold a dangling pointer, which is then dereferenced later in this function
when the lock is acquired?
aspm_attr_store_common()
...
down_read(&pci_bus_sem);
mutex_lock(&aspm_lock);
...
link->aspm_disable &= ~state;
Does this same lockless fetch race also exist in clkpm_store(),
aspm_attr_show_common(), and clkpm_show()?
[ ... ]
> @@ -1713,6 +1719,9 @@ static ssize_t clkpm_show(struct device *dev,
> struct pci_dev *pdev = to_pci_dev(dev);
> struct pcie_link_state *link = pcie_aspm_get_link(pdev);
>
> + if (!link)
> + return 0;
> +
[Severity: Low]
Does returning 0 here mean a successful read of 0 bytes, presenting an empty
file to userspace instead of an error? Should this return -ENODEV similar
to the clkpm_store() callback?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727072915.3954329-1-zhaojinming@uniontech.com?part=1
next prev parent reply other threads:[~2026-07-27 7:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 7:29 [PATCH] PCI/ASPM: Add missing NULL check for link in sysfs show/store callbacks ZhaoJinming
2026-07-27 7:41 ` sashiko-bot [this message]
2026-07-27 10:13 ` Lukas Wunner
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=20260727074129.4F1E51F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhaojinming@uniontech.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.