Forwarded: [PATCH] HID: roccat: fix use-after-free in roccat_disconnect()

From: syzbot

Date: Wed Sep 02 2026 - 19:29:55 EST


For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.

***

Subject: [PATCH] HID: roccat: fix use-after-free in roccat_disconnect()
Author: kartikey406@xxxxxxxxx

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master



roccat_disconnect() dropped devices_lock between reading device->exist
and later checking device->open to decide whether to free the device.
This let a concurrent roccat_release() see exist == 0 and free the
device first, so roccat_disconnect()'s later device->open check ran on
freed memory.

Fix this by performing the whole lookup, exist/devices[] update, and
free-or-keep decision inside a single devices_lock critical section,
matching what roccat_release() already does.

Reported-by: syzbot+c492a9e154f81127551f@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=c492a9e154f81127551f
Signed-off-by: Deepanshu Kartikey <kartikey406@xxxxxxxxx>
---
drivers/hid/hid-roccat.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 4f15eb951039..984f7c334f14 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c
@@ -369,15 +369,12 @@ void roccat_disconnect(int minor)

mutex_lock(&devices_lock);
device = devices[minor];
- mutex_unlock(&devices_lock);

device->exist = 0; /* TODO exist maybe not needed */

device_destroy(device->dev->class, MKDEV(roccat_major, minor));

- mutex_lock(&devices_lock);
devices[minor] = NULL;
- mutex_unlock(&devices_lock);

if (device->open) {
hid_hw_close(device->hid);
@@ -385,6 +382,8 @@ void roccat_disconnect(int minor)
} else {
roccat_free_device(device);
}
+
+ mutex_unlock(&devices_lock);
}
EXPORT_SYMBOL_GPL(roccat_disconnect);

--
2.43.0