Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v6 1/2] HID: roccat: use device_is_registered() to check whether device is available
Date: Fri, 16 Oct 2026 11:45:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-174248@kernel.org> (raw)
In-Reply-To: <20261016113321.892452-2-dmantipov@yandex.ru>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] hid: Use-After-Free of struct device in roccat_device_available()
- [High] hid: roccat: UAF in roccat_device_available() during device removal
--

commit 55c9b90288fdb8c7ef6b2e3456eeca1cc08711d4
Author: Dmitry Antipov <dmantipov@yandex.ru>

HID: roccat: use device_is_registered() to check whether device is available

This commit introduces roccat_device_available() to check if a device is
registered. It removes the explicit 'exist' flag from struct roccat_device.

> diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
> index 5deb6da8d4f74..92a9b9f14f591 100644
> --- a/drivers/hid/hid-roccat.c
> +++ b/drivers/hid/hid-roccat.c

[ ... ]

> @@ -70,6 +69,13 @@ static struct roccat_device *devices[ROCCAT_MAX_DEVICES];
>  /* protects modifications of devices array */
>  static DEFINE_MUTEX(devices_lock);
>  
> +static bool roccat_device_available(struct roccat_device *device)
> +{
> +	struct device *dev = smp_load_acquire(&device->dev);
> +
> +	return dev ? device_is_registered(dev) : false;

[Severity: High]
Does this create a Use-After-Free risk when evaluated concurrently with device
removal?

If roccat_read() or roccat_poll() fetches the 'dev' pointer via
smp_load_acquire() but is then preempted before calling
device_is_registered():

Thread 1 (roccat_read/roccat_poll)
roccat_device_available()
    struct device *dev = smp_load_acquire(&device->dev);
    <preempted>

Thread 2 (roccat_disconnect)
    dev = xchg(&device->dev, NULL);
    device_destroy(dev->class, MKDEV(roccat_major, minor));

Since device_destroy() synchronously drops the reference and can free the
underlying struct device memory, could Thread 1 then resume and pass the freed
'dev' pointer to device_is_registered(), dereferencing freed memory?

[ ... ]

> @@ -365,13 +370,13 @@ EXPORT_SYMBOL_GPL(roccat_connect);
>  void roccat_disconnect(int minor)
>  {
>  	struct roccat_device *device;
> +	struct device *dev;
>  
>  	mutex_lock(&devices_lock);
>  	device = devices[minor];
>  
> -	device->exist = 0; /* TODO exist maybe not needed */
> -
> -	device_destroy(device->dev->class, MKDEV(roccat_major, minor));
> +	dev = xchg(&device->dev, NULL);
> +	device_destroy(dev->class, MKDEV(roccat_major, minor));

[Severity: High]
Since roccat_device_available() can be called from read and poll handlers
without holding devices_lock, does swapping the pointer and immediately
destroying the device leave concurrent readers unprotected?

>  
>  	devices[minor] = NULL;
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261016113321.892452-1-dmantipov@yandex.ru?part=1

  reply	other threads:[~2026-10-16 11:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29  6:57 [PATCH v5 0/3] Latest Roccat HID fixes Dmitry Antipov
2026-09-29  6:57 ` [PATCH v5 1/3] HID: roccat: use device_is_registered() to check whether device is available Dmitry Antipov
2026-09-29  7:14   ` sashiko-bot
2026-09-29  6:57 ` [PATCH v5 2/3] HID: roccat: fix device access in roccat_release() Dmitry Antipov
2026-09-29  6:57 ` [PATCH v5 3/3] HID: roccat: use kref to manage device instances Dmitry Antipov
2026-10-15 16:43 ` (subset) [PATCH v5 0/3] Latest Roccat HID fixes Benjamin Tissoires
2026-10-15 16:47 ` Benjamin Tissoires
2026-10-16 11:33   ` [PATCH v6 0/2] Last remaining " Dmitry Antipov
2026-10-16 11:33     ` [PATCH v6 1/2] HID: roccat: use device_is_registered() to check whether device is available Dmitry Antipov
2026-10-16 11:45       ` sashiko-bot [this message]
2026-10-16 11:33     ` [PATCH v6 2/2] HID: roccat: use kref to manage device instances Dmitry Antipov
2026-10-16 11:46       ` 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=sashiko-outbox-174248@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmantipov@yandex.ru \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@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