From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v4 2/4] HID: roccat: use device_is_registered() to check whether device is available
Date: Wed, 16 Sep 2026 15:56:46 +0000 [thread overview]
Message-ID: <20260916155646.EC61B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260916154733.78464-2-dmantipov@yandex.ru>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] HID: roccat: use-after-free of device->dev in roccat_device_available()
--
commit 10e7416f7d2b9142317f413c7988155b077d1914
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 the device
is registered rather than relying on a boolean exist flag. It replaces
the flag checks in the read, poll, and release paths with the new helper.
> diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
> index 5deb6da8d4f74..96aa508111a1b 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 = READ_ONCE(device->dev);
> +
> + return dev ? device_is_registered(dev) : false;
[Severity: High]
Does this lockless check risk a use-after-free of the dev pointer in
drivers/hid/hid-roccat.c?
If a userspace process calls roccat_read() or roccat_poll() on the character
device while the physical device is simultaneously unplugged,
roccat_disconnect() can run concurrently. Since roccat_disconnect() unregisters
and drops the reference to the device, dev could be freed after the
READ_ONCE() but before device_is_registered() accesses
dev->kobj.state_in_sysfs.
> +}
> +
[ ... ]
> @@ -369,10 +374,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));
> -
> + WRITE_ONCE(device->dev, NULL);
[Severity: High]
Could this synchronously free the struct device while concurrent readers
still hold the raw pointer in roccat_disconnect() in drivers/hid/hid-roccat.c?
device_destroy() synchronously unregisters and drops the final reference to
the struct device, freeing it. Because roccat_device_available() doesn't
hold a reference or lock when checking device_is_registered(), this opens a
time-of-check to time-of-use (TOCTOU) race window.
> devices[minor] = NULL;
>
> if (device->open) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260916154733.78464-1-dmantipov@yandex.ru?part=2
next prev parent reply other threads:[~2026-09-16 15:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 15:47 [PATCH v4 1/4] HID: roccat: fix locking in roccat_connect() and roccat_disconnect() Dmitry Antipov
2026-09-16 15:47 ` [PATCH v4 2/4] HID: roccat: use device_is_registered() to check whether device is available Dmitry Antipov
2026-09-16 15:56 ` sashiko-bot [this message]
2026-09-16 15:47 ` [PATCH v4 3/4] HID: roccat: fix device access in roccat_release() Dmitry Antipov
2026-09-16 15:47 ` [PATCH v4 4/4] HID: roccat: use kref to manage device instances Dmitry Antipov
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=20260916155646.EC61B1F000FF@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