Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Herve Codina" <herve.codina@bootlin.com>
Cc: linux-pci@vger.kernel.org, linux-cxl@vger.kernel.org
Subject: Re: [PATCH v10 02/10] drivers: core: Use fw_devlink_set_device()
Date: Fri, 17 Jul 2026 15:12:00 +0000	[thread overview]
Message-ID: <20260717151200.854341F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717145147.823749-3-herve.codina@bootlin.com>

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

Pre-existing issues:
- [High] Lockless read of `fwnode->dev` can lead to Use-After-Free and NULL pointer dereferences.
--

--- Patch [2]: [PATCH v10 02/10] drivers: core: Use fw_devlink_set_device() ---
commit 80a2fb2740f34981de6ee4d63b13800473b38e85
Author: Herve Codina <herve.codina@bootlin.com>

drivers: core: Use fw_devlink_set_device()

This patch updates the driver core to use the dedicated
fw_devlink_set_device() helper instead of assigning the fwnode->dev field
directly.

> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 4d026682944f2..c205125344cf3 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
[ ... ]
> @@ -3925,7 +3925,7 @@ void device_del(struct device *dev)
>  	device_unlock(dev);
>  
>  	if (dev->fwnode && dev->fwnode->dev == dev)
> -		dev->fwnode->dev = NULL;
> +		fw_devlink_set_device(dev->fwnode, NULL);
>  
>  	/* Notify clients of device removal.  This call must come
>  	 * before dpm_sysfs_remove().

[Severity: High]
This is a pre-existing issue, but does this lockless assignment expose a race
condition with concurrent readers?

In device_del(), fwnode->dev is cleared locklessly via
fw_devlink_set_device(). Concurrently, other operations holding
fwnode_link_lock (which doesn't serialize with device_del()) read fwnode->dev.

For example, if get_dev_from_fwnode() is called concurrently:

drivers/base/core.c:get_dev_from_fwnode() {
    ...
    return get_device((fwnode)->dev);
}

If the thread is preempted between reading fwnode->dev and dereferencing it
in get_device(), and device_del() finishes allowing the device to be freed,
could this result in a use-after-free?

Similarly, in __fw_devlink_pickup_dangling_consumers():

drivers/base/core.c:__fw_devlink_pickup_dangling_consumers() {
    ...
    if (fwnode->dev && fwnode->dev->bus)
    ...
}

Could the compiler reload fwnode->dev between the NULL check and the
dereference, leading to a NULL pointer dereference?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717145147.823749-1-herve.codina@bootlin.com?part=2

  parent reply	other threads:[~2026-07-17 15:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 14:51 [PATCH v10 00/10] lan966x pci device: Add support for SFPs, PCI part Herve Codina
2026-07-17 14:51 ` [PATCH v10 01/10] driver core: fw_devlink: Introduce fw_devlink_set_device() Herve Codina
2026-07-17 14:58   ` sashiko-bot
2026-07-17 14:51 ` [PATCH v10 03/10] pinctrl: cs42l43: Use fw_devlink_set_device() Herve Codina
2026-07-17 15:05   ` sashiko-bot
2026-07-17 14:51 ` [PATCH v10 05/10] cxl/test: " Herve Codina
2026-07-17 14:58   ` sashiko-bot
2026-07-17 14:51 ` [PATCH v10 09/10] PCI: of: Remove fwnode_dev_initialized() call for a PCI root bridge node Herve Codina
2026-07-17 17:08   ` sashiko-bot
     [not found] ` <20260717145147.823749-5-herve.codina@bootlin.com>
2026-07-17 14:59   ` [PATCH v10 04/10] cxl/test: Use device_set_node() sashiko-bot
     [not found] ` <20260717145147.823749-7-herve.codina@bootlin.com>
2026-07-17 15:03   ` [PATCH v10 06/10] PCI: of: Use fw_devlink_set_device() sashiko-bot
     [not found] ` <20260717145147.823749-8-herve.codina@bootlin.com>
2026-07-17 15:06   ` [PATCH v10 07/10] PCI: of: Clear fwnode->dev during root bridge node removal and error path sashiko-bot
     [not found] ` <20260717145147.823749-9-herve.codina@bootlin.com>
2026-07-17 15:10   ` [PATCH v10 08/10] PCI: of: Set fwnode device of newly created PCI device nodes sashiko-bot
     [not found] ` <20260717145147.823749-3-herve.codina@bootlin.com>
2026-07-17 15:12   ` sashiko-bot [this message]
     [not found] ` <20260717145147.823749-11-herve.codina@bootlin.com>
2026-07-17 15:19   ` [PATCH v10 10/10] PCI: of: Guard against node removal with incorrect np->data sashiko-bot

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=20260717151200.854341F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=herve.codina@bootlin.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --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