summaryrefslogtreecommitdiff
path: root/tools/perf/scripts/python
diff options
context:
space:
mode:
authorAndreas Claesson <andreas@aclaesson.com>2026-11-09 19:55:52 +0000
committerJiri Kosina <jkosina@suse.com>2026-11-19 21:30:39 +0100
commite624a56578e551b77ee66eef74dc2efcd42deb08 (patch)
treef29167e2a7c85327a31fbf893df68cde56a04dfa /tools/perf/scripts/python
parent5c4595963229397da8bd362ea93266197b16c7ab (diff)
HID: corsair: cancel LED work again after unregistering the LED
Commit eb51c9f8cb4f ("HID: corsair: cancel worker before unregistering LED to fix use-after-free") moved cancel_work_sync() in front of led_classdev_unregister() in k90_cleanup_backlight() and k90_cleanup_macro_functions(). led_classdev_unregister() turns the LED off unless LED_RETAIN_AT_SHUTDOWN is set. That calls k90_brightness_set(), which unconditionally does schedule_work() on the same work item. The work is therefore queued again after it was cancelled, and the structure that embeds it is freed right afterwards: k90_cleanup_macro_functions() cancel_work_sync(&k90->record_led.work) led_classdev_unregister(&k90->record_led.cdev) led_set_brightness(LED_OFF) k90_brightness_set() schedule_work(&led->work) <-- re-queued kfree(k90) <-- frees the queued work_struct When the work later runs, the workqueue dereferences the freed work_struct and k90_record_led_work() reads led->removed from freed memory. A USB device that enumerates as a K90 and is then unplugged triggers this reliably. With CONFIG_DEBUG_OBJECTS_WORK it shows up as: ODEBUG: free active (active state 0) object: ffff88803b8772c8 object type: work_struct hint: k90_record_led_work+0x0/0x1e0 WARNING: lib/debugobjects.c:632 at debug_print_object+0xec/0x230 Workqueue: usb_hub_wq hub_event Call Trace: debug_check_no_obj_freed+0x2e3/0x450 lib/debugobjects.c:1201 kfree+0x13e/0x650 mm/slub.c:6923 k90_cleanup_macro_functions drivers/hid/hid-corsair.c:547 [inline] corsair_remove+0xfd/0x260 drivers/hid/hid-corsair.c:602 hid_device_remove+0xc5/0x1c0 drivers/hid/hid-core.c:2897 ... usbhid_disconnect+0x9f/0xc0 drivers/hid/usbhid/hid-core.c:1486 (with ODEBUG enabled, work_fixup_free() cancels the work and hides the use-after-free. Without it, the freed work item is executed.) Keep the existing cancel_work_sync() before unregistering, which waits for a worker that may already be past the 'removed' check, and cancel the work once more after led_classdev_unregister() so the work queued by the LED-off request is gone before the memory is freed. A re-queued work that manages to run before the second cancel still sees 'removed == true' while the structure is alive and returns early. Fixes: eb51c9f8cb4f ("HID: corsair: cancel worker before unregistering LED to fix use-after-free") Cc: stable@vger.kernel.org Signed-off-by: Andreas Claesson <andreas@aclaesson.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions