From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3 4/4] HID: roccat: use kref to manage device instances
Date: Wed, 16 Sep 2026 08:17:30 +0000 [thread overview]
Message-ID: <20260916081731.27B411F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260916080013.56388-4-dmantipov@yandex.ru>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid: roccat: UaF in roccat_device_available() due to unlocked device->dev access
--
commit 8a69ab520bd366b55b30a21617d1af38b7f66c41
Author: Dmitry Antipov <dmantipov@yandex.ru>
HID: roccat: use kref to manage device instances
This commit introduces a kref-based lifecycle for roccat_device instances
to resolve memory leaks and use-after-free issues between open/release
and connect/disconnect pairs. The device slot is now released in
roccat_free_device() instead of roccat_disconnect().
Link: https://sashiko.dev/#/patchset/20260902094551.200587-1-dmantipov@yandex.ru?part=2
> diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
> index 1e1a76c453bd2..bdf8857509294 100644
> --- a/drivers/hid/hid-roccat.c
> +++ b/drivers/hid/hid-roccat.c
[ ... ]
> @@ -366,18 +376,20 @@ void roccat_disconnect(int minor)
>
> mutex_lock(&devices_lock);
> device = devices[minor];
> + if (WARN_ON(!device))
> + goto out;
>
> - device_destroy(device->dev->class, MKDEV(roccat_major, minor));
> - device->dev = NULL;
> - devices[minor] = NULL;
> + if (!WARN_ON(!roccat_device_available(device))) {
> + device_destroy(device->dev->class, MKDEV(roccat_major, minor));
> + device->dev = NULL;
> + }
[Severity: High]
Can an unlocked reader racing with this code trigger a use-after-free?
If a userspace process calls roccat_read() or roccat_poll() on the device
node concurrently with roccat_disconnect(), they will invoke
roccat_device_available().
Since those read and poll paths are unlocked, a thread could see
device->dev as non-NULL in roccat_device_available():
drivers/hid/hid-roccat.c:roccat_device_available() {
return device->dev ? device_is_registered(device->dev) : false;
}
If it is preempted right after the ternary check but before calling
device_is_registered(), and this roccat_disconnect() code then runs,
destroying device->dev and setting it to NULL, the reader thread will
resume and dereference the freed pointer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260916080013.56388-1-dmantipov@yandex.ru?part=4
prev parent reply other threads:[~2026-09-16 8:17 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
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 [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=20260916081731.27B411F000FF@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 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.