Linux GPIO subsystem development
 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] gpio: virtuser: fix interrupt leak and UAF
Date: Fri, 06 Nov 2026 15:43:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-201721@kernel.org> (raw)
In-Reply-To: <20261106-gpio-virtuser-irq-uaf-leak-v1-1-ce9772d8ad0d@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] gpiolib: race condition and double free in desc_set_label()
  [1]
--

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

gpio: virtuser: fix interrupt leak and UAF

This commit serializes access to the virtual user interrupt state using the
per-line mutex, prevents duplicate IRQ requests, and registers a devm action
to free the interrupt on device unbind.

> diff --git a/drivers/gpio/gpio-virtuser.c b/drivers/gpio/gpio-virtuser.c
> index 185c1be39b277..21b4bc64d4d34 100644
> --- a/drivers/gpio/gpio-virtuser.c
> +++ b/drivers/gpio/gpio-virtuser.c

[ ... ]

> @@ -635,7 +635,7 @@ static ssize_t gpio_virtuser_consumer_write(struct file *file,
>  	if (ret)
>  		return ret;
>  
> -	scoped_guard(mutex, &data->consumer_lock)
> +	scoped_guard(mutex, &data->lock)
>  		strscpy(data->consumer, buf, sizeof(data->consumer));
>  
>  	return count;

[Severity: Critical]
This problem wasn't introduced by this patch, but can concurrent writes in
gpio_virtuser_consumer_write() race in desc_set_label() [1] and double
enqueue old->rh via call_srcu()?

Just above this hunk, gpio_virtuser_consumer_write() calls
gpiod_set_consumer_name() -> desc_set_label() without holding data->lock, and
desc_set_label() replaces desc->label without any update-side lock:

drivers/gpio/gpiolib.c:desc_set_label() {
	...
	old = rcu_replace_pointer(desc->label, new, 1);
	if (old)
		call_srcu(&desc->gdev->desc_srcu, &old->rh, desc_free_label);

	return 0;
}

Because rcu_replace_pointer() is just a load followed by a store, two
concurrent callers can read the same old pointer:

CPU0                                CPU1
gpio_virtuser_consumer_write()      gpio_virtuser_consumer_write()
  gpiod_set_consumer_name()           gpiod_set_consumer_name()
    desc_set_label()                    desc_set_label()
      old = rcu_dereference(...)
                                          old = rcu_dereference(...)
      rcu_assign_pointer(..., new0)
                                          rcu_assign_pointer(..., new1)
      call_srcu(..., &old->rh, ...)
                                          call_srcu(..., &old->rh, ...)
                                            <-- double call_srcu() / double free

Queuing the same rcu_head twice corrupts the SRCU callback list and double
frees old after the grace period, while leaking new0.

[1] https://sashiko.dev/#/bug/linux-8fa6e742-7945-4de7-8786-8ad6e6c6ea4e

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261106-gpio-virtuser-irq-uaf-leak-v1-1-ce9772d8ad0d@oss.qualcomm.com?part=1

  reply	other threads:[~2026-11-06 15:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 15:33 [PATCH] gpio: virtuser: fix interrupt leak and UAF Bartosz Golaszewski
2026-11-06 15:43 ` sashiko-bot [this message]
2026-11-09  8:30   ` Bartosz Golaszewski
2026-11-10  9:20 ` Bartosz Golaszewski

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-201721@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox