From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH v7 5/5] gpio: shared: convert to using software nodes for GPIO shared proxy lookup
Date: Wed, 28 Oct 2026 15:10:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-188040@kernel.org> (raw)
In-Reply-To: <20261028-gpio-shared-fwnode-lookup-v7-5-acb453b6fbd5@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] gpio: shared: use-after-free in gpio_shared_remove_proxy_dev() on swnode teardown
--
commit 8040c150f4a36d793af070d87bfa19010fce092d
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
gpio: shared: convert to using software nodes for GPIO shared proxy lookup
This commit replaces platform lookup tables for shared GPIO proxy devices
with dummy software nodes assigned to the proxy auxiliary devices. This
allows looking up the target proxy GPIO device by its firmware node even
when no consumer struct device is present.
> diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c
> index c0e2a1207cccf..4f5ecdfcc63ac 100644
> --- a/drivers/gpio/gpiolib-shared.c
> +++ b/drivers/gpio/gpiolib-shared.c
[ ... ]
> @@ -529,6 +540,8 @@ static void gpio_shared_remove_proxy_dev(struct gpio_shared_ref *ref)
> scoped_guard(mutex, &ref->lock) {
> proxy = ref->proxy_dev;
> ref->proxy_dev = NULL;
> + software_node_unregister(&ref->proxy_swnode);
> + ref->proxy_fwnode = NULL;
> }
[Severity: High]
Does unregistering ref->proxy_swnode before deleting the proxy auxiliary
device cause a use-after-free of the struct swnode during device removal?
In gpio_shared_make_proxy_dev(), software_node_register() allocates the
struct swnode with an initial reference count of 1 (and swnode->managed
set to false), and device_set_node() attaches its fwnode to adev->dev.
When auxiliary_device_add() registers adev->dev (and when the proxy driver
registers its gpio_device), software_node_notify() increments the swnode
reference count for each device.
In gpio_shared_remove_proxy_dev(), calling software_node_unregister()
before auxiliary_device_delete(proxy) drops the initial creation reference
while proxy->dev is still registered:
gpio_shared_remove_proxy_dev()
software_node_unregister(&ref->proxy_swnode) -> drops initial ref
auxiliary_device_delete(proxy)
device_del(&proxy->dev)
device_platform_notify_remove(&proxy->dev)
software_node_notify_remove(&proxy->dev)
When software_node_notify_remove() runs in drivers/base/swnode.c,
swnode_put() drops the last remaining reference and frees the struct
swnode, and then immediately reads from the freed structure:
swnode_put(swnode);
if (swnode->managed) {
set_secondary_fwnode(dev, NULL);
swnode_put(swnode);
}
In addition, because swnode->managed is false, proxy->dev.fwnode is not
cleared, so acpi_device_notify_remove() in device_platform_notify_remove()
immediately dereferences dev->fwnode->ops on the freed swnode.
Should software_node_unregister(&ref->proxy_swnode) be called after
auxiliary_device_delete(proxy) and auxiliary_device_uninit(proxy) (or with
device_set_node(&proxy->dev, NULL) before unregistering), matching the
error unwind order in gpio_shared_make_proxy_dev()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261028-gpio-shared-fwnode-lookup-v7-0-acb453b6fbd5@oss.qualcomm.com?part=5
prev parent reply other threads:[~2026-10-28 15:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 14:44 [PATCH v7 0/5] gpio: shared: replace platform lookup with dummy software nodes Bartosz Golaszewski
2026-10-28 14:44 ` [PATCH v7 1/5] gpio: shared: factor out per-entry teardown helper Bartosz Golaszewski
2026-10-28 14:44 ` [PATCH v7 2/5] gpio: shared: factor out per-entry setup helper Bartosz Golaszewski
2026-10-28 14:44 ` [PATCH v7 3/5] gpio: shared: unwind partial failures in gpiochip_setup_shared() Bartosz Golaszewski
2026-10-28 14:44 ` [PATCH v7 4/5] gpio: shared: detach the proxy device from struct gpio_shared_ref Bartosz Golaszewski
2026-10-28 14:44 ` [PATCH v7 5/5] gpio: shared: convert to using software nodes for GPIO shared proxy lookup Bartosz Golaszewski
2026-10-28 15:10 ` 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=sashiko-outbox-188040@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=linux-gpio@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 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.