All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH] gpiolib: keep the line state workqueue alive until device release
Date: Mon, 09 Nov 2026 14:34:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-205116@kernel.org> (raw)
In-Reply-To: <20261109-gpio-line-state-wq-uaf-v1-1-2e126ca3427d@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gpiolib: double destroy_workqueue() in gpiodev_release() on
  cdev add error
--

commit f0714550a8f7080c7dd00f07240622c9dd77f912
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

gpiolib: keep the line state workqueue alive until device release

This commit moves the destruction of gdev->line_state_wq from
gpiolib_cdev_unregister() to gpiodev_release() to avoid a use-after-free
race with concurrent gpiod_line_state_notify() calls during chip removal.

> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index fbdeda2f27871..c954c7eec2bee 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c

[ ... ]

> @@ -898,6 +899,9 @@ static void gpiodev_release(struct device *dev)
>  	synchronize_srcu(&gdev->desc_srcu);
>  	cleanup_srcu_struct(&gdev->desc_srcu);
>  
> +	if (gdev->line_state_wq)
> +		destroy_workqueue(gdev->line_state_wq);

[Severity: Medium]
Can this call destroy_workqueue() a second time on gdev->line_state_wq if
cdev_device_add() fails in gpiolib_cdev_register()?

drivers/gpio/gpiolib-cdev.c:gpiolib_cdev_register() {
	...
	ret = cdev_device_add(&gdev->chrdev, &gdev->dev);
	if (ret) {
		destroy_workqueue(gdev->line_state_wq);
		return ret;
	}
	...
}

When gpiolib_cdev_register() fails here, it destroys gdev->line_state_wq
without clearing the pointer.  The caller then unwinds via
gpio_device_put(gdev) -> gpiodev_release(), which sees the non-NULL
dangling pointer and calls destroy_workqueue() again, causing a
use-after-free.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109-gpio-line-state-wq-uaf-v1-1-2e126ca3427d@oss.qualcomm.com?part=1

      reply	other threads:[~2026-11-09 14:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 14:24 [PATCH] gpiolib: keep the line state workqueue alive until device release Bartosz Golaszewski
2026-11-09 14:34 ` 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-205116@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.