Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v3 2/4] HID: roccat: use device_is_registered() to check whether device is available
Date: Wed, 16 Sep 2026 08:09:00 +0000	[thread overview]
Message-ID: <20260916080901.47D6F1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260916080013.56388-2-dmantipov@yandex.ru>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid: roccat: UAF/NULL deref in roccat_device_available() during disconnect
--

commit cd1f0994ff4ff722b51fd011ca302365c749f4ad
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 whether a device
is actually available by calling device_is_registered(device->dev), replacing
the explicit 'exist' flag from 'struct roccat_device'.

> diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
> index 5deb6da8d4f74..454b201c0524b 100644
> --- a/drivers/hid/hid-roccat.c
> +++ b/drivers/hid/hid-roccat.c
[ ... ]
> @@ -70,6 +69,11 @@ 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)
> +{
> +	return device->dev ? device_is_registered(device->dev) : false;
> +}
> +

[Severity: High]
Does this introduce a Use-After-Free or NULL pointer dereference race?

When roccat_device_available() is called, device->dev is evaluated. If a
concurrent thread calls roccat_disconnect() and frees the device structure via
device_destroy(), device_is_registered(device->dev) may access freed memory.
Also, a compiler double-fetch could result in a direct NULL pointer dereference.

[ ... ]
> @@ -105,7 +109,7 @@ static ssize_t roccat_read(struct file *file, char __user *buffer,
>  				retval = -ERESTARTSYS;
>  				break;
>  			}
> -			if (!device->exist) {
> +			if (!roccat_device_available(device)) {
>  				retval = -EIO;
>  				break;
>  			}

[Severity: High]
Can this race occur here?

roccat_read() calls roccat_device_available() without holding devices_lock.
This means the device's availability is evaluated locklessly while
roccat_disconnect() might be tearing down the device.

[ ... ]
> @@ -149,7 +153,7 @@ static __poll_t roccat_poll(struct file *file, poll_table *wait)
>  	poll_wait(file, &reader->device->wait, wait);
>  	if (reader->cbuf_start != reader->device->cbuf_end)
>  		return EPOLLIN | EPOLLRDNORM;
> -	if (!reader->device->exist)
> +	if (!roccat_device_available(reader->device))
>  		return EPOLLERR | EPOLLHUP;
>  	return 0;
>  }

[Severity: High]
Similarly, roccat_poll() calls roccat_device_available() without holding
devices_lock, exposing it to the same race condition as roccat_read().

[ ... ]
> @@ -369,10 +372,8 @@ void roccat_disconnect(int minor)
>  	mutex_lock(&devices_lock);
>  	device = devices[minor];
>  
> -	device->exist = 0; /* TODO exist maybe not needed */
> -
>  	device_destroy(device->dev->class, MKDEV(roccat_major, minor));
> -
> +	device->dev = NULL;
>  	devices[minor] = NULL;
>  
>  	if (device->open) {

[Severity: High]
Could this teardown path trigger the race?

roccat_disconnect() holds devices_lock, destroys and drops the reference to
the device with device_destroy(), and then nullifies device->dev.
Since roccat_read() and roccat_poll() don't hold devices_lock, they can
dereference device->dev concurrently just before or as it is being freed.

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

  reply	other threads:[~2026-09-16  8:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  8:00 [PATCH v3 1/4] HID: roccat: fix locking in roccat_connect() and roccat_disconnect() Dmitry Antipov
2026-09-16  8:00 ` [PATCH v3 2/4] HID: roccat: use device_is_registered() to check whether device is available Dmitry Antipov
2026-09-16  8:09   ` sashiko-bot [this message]
2026-09-16  8:00 ` [PATCH v3 3/4] HID: roccat: fix device access in roccat_release() Dmitry Antipov
2026-09-16  8:00 ` [PATCH v3 4/4] HID: roccat: use kref to manage device instances Dmitry Antipov
2026-09-16  8:17   ` 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=20260916080901.47D6F1F00899@smtp.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