From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 2/4] HID: roccat: fix device access in roccat_release()
Date: Mon, 14 Sep 2026 12:44:55 +0000 [thread overview]
Message-ID: <20260914124455.8B7A71F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914120240.1625442-2-dmantipov@yandex.ru>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [Critical] HID roccat sub-drivers free their private driver data before calling hid_hw_stop(), causing a Use-After-Free in the raw_event callback.
- [High] roccat_report_event() accesses devices[minor] locklessly and does not check for NULL, leading to a NULL pointer dereference during device disconnect.
- [High] roccat_report_event() acquires sleepable mutexes from an atomic interrupt context.
--
commit a846f43d2e5b4bec36ac11b09237b5b9c9ebabb4
Author: Dmitry Antipov <dmantipov@yandex.ru>
HID: roccat: fix device access in roccat_release()
In roccat_release(), access the device using file-specific reader data rather
than global array, thus preventing the case when original device was
disconnected and a new device has connected using the same slot indexed by minor
number.
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 5deb6da8d4f74..007778922c21a 100644
> --- a/drivers/hid/hid-roccat.c
> +++ b/drivers/hid/hid-roccat.c
[ ... ]
> int roccat_report_event(int minor, u8 const *data)
> {
> struct roccat_device *device;
> struct roccat_reader *reader;
> struct roccat_report *report;
> uint8_t *new_value;
>
> device = devices[minor];
>
> new_value = kmemdup(data, device->report_size, GFP_ATOMIC);
[Severity: High]
This isn't a bug introduced by this patch, but does roccat_report_event()
access devices[minor] locklessly and without checking for NULL?
If a device is disconnected, roccat_disconnect() sets devices[minor] = NULL
and drops the device reference. Because sub-drivers like hid-roccat-kone fail
to call hid_hw_stop() before roccat_disconnect(), incoming USB interrupts can
still trigger roccat_report_event() concurrently.
Could this lead to a NULL pointer dereference when kmemdup() accesses
device->report_size?
> if (!new_value)
> return -ENOMEM;
>
> mutex_lock(&device->readers_lock);
> mutex_lock(&device->cbuf_lock);
[Severity: High]
This is a pre-existing issue, but does this code acquire sleepable mutexes from
an atomic interrupt context?
roccat_report_event() is called by raw_event callbacks in HID sub-drivers,
which execute in atomic interrupt context (URB completion handlers like
usbhid_irq_in).
Can calling mutex_lock() here cause a "scheduling while atomic" panic, or
a deadlock if the lock is contended?
> drivers/hid/hid-roccat-kone.c:
> static void kone_remove_specials(struct hid_device *hdev)
> {
> struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
> struct kone_device *kone;
>
> if (intf->cur_altsetting->desc.bInterfaceProtocol
> == USB_INTERFACE_PROTOCOL_MOUSE) {
> kone = hid_get_drvdata(hdev);
> if (kone->roccat_claimed)
> roccat_disconnect(kone->chrdev_minor);
> kfree(hid_get_drvdata(hdev));
> }
> }
>
> static void kone_remove(struct hid_device *hdev)
> {
> kone_remove_specials(hdev);
> hid_hw_stop(hdev);
> }
[Severity: Critical]
This isn't a bug introduced by this patch, but do HID roccat sub-drivers free
their private driver data before calling hid_hw_stop()?
During device unbinding/removal, kone_remove_specials() is called which frees
the driver data with kfree(hid_get_drvdata(hdev)). However, hid_hw_stop() is
called after this free.
Since hid_hw_stop() is responsible for stopping hardware interrupts, an incoming
USB report can trigger kone_raw_event() concurrently:
drivers/hid/hid-roccat-kone.c:kone_raw_event() {
struct kone_device *kone = hid_get_drvdata(hdev);
...
if (kone == NULL)
return 0;
...
if (kone->roccat_claimed)
kone_report_to_chrdev(kone, event);
}
Can this result in a Use-After-Free memory corruption when the raw_event
callback dereferences the freed driver data?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914120240.1625442-1-dmantipov@yandex.ru?part=2
next prev parent reply other threads:[~2026-09-14 12:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 12:02 [PATCH v2 1/4] HID: roccat: fix locking in roccat_connect() and roccat_disconnect() Dmitry Antipov
2026-09-14 12:02 ` [PATCH v2 2/4] HID: roccat: fix device access in roccat_release() Dmitry Antipov
2026-09-14 12:44 ` sashiko-bot [this message]
2026-09-14 12:02 ` [PATCH v2 3/4] HID: roccat: examine readers to check whether the device is opened Dmitry Antipov
2026-09-14 12:53 ` sashiko-bot
2026-09-14 12:02 ` [PATCH v2 4/4] HID: roccat: use kref to manage device instances Dmitry Antipov
2026-09-14 13:07 ` sashiko-bot
2026-09-14 12:26 ` [PATCH v2 1/4] HID: roccat: fix locking in roccat_connect() and roccat_disconnect() 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=20260914124455.8B7A71F000FF@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.