From: Chen Changcheng <ccc194101@163.com>
To: ccc194101@163.com
Cc: bentiss@kernel.org, chenchangcheng@kylinos.cn,
jeffinphilip14@gmail.com, jikos@kernel.org,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+0a031a76585d1c7e737d@syzkaller.appspotmail.com
Subject: [PATCH] HID: corsair: do not re-schedule LED worker after it has been cancelled
Date: Mon, 17 Aug 2026 15:28:31 +0800 [thread overview]
Message-ID: <20260817072831.139954-1-ccc194101@163.com> (raw)
In-Reply-To: <20260817072354.139154-1-ccc194101@163.com>
From: Chen Changcheng <chenchangcheng@kylinos.cn>
Commit eb51c9f8cb4f0 ("HID: corsair: cancel worker before unregistering
LED to fix use-after-free") moved cancel_work_sync() ahead of
led_classdev_unregister() in k90_cleanup_backlight() and
k90_cleanup_macro_functions(). led_classdev_unregister() internally
calls led_set_brightness(LED_OFF), which reaches the driver's
k90_brightness_set() callback. Since that callback schedules the worker
unconditionally, the worker was re-queued after cancel_work_sync() had
drained it, and the subsequent kfree() freed a still-active work_struct:
ODEBUG: free active (active state 0) object type: work_struct
hint: k90_record_led_work
The removed flag check inside the worker itself only stops it from
dereferencing freed memory once it runs; it cannot prevent the re-queue.
Fix this by making k90_brightness_set() a no-op once removed is set, so
the LED_OFF update issued from led_classdev_unregister() can no longer
re-schedule the worker after it has been cancelled. Also apply the
cancel-before-unregister ordering to the probe error path
(k90_init_macro_functions() fail_sysfs) for consistency.
Fixes: eb51c9f8cb4f0 ("HID: corsair: cancel worker before unregistering LED to fix use-after-free")
Reported-by: syzbot+0a031a76585d1c7e737d@syzkaller.appspotmail.com
Signed-off-by: Chen Changcheng <chenchangcheng@kylinos.cn>
---
drivers/hid/hid-corsair.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-corsair.c b/drivers/hid/hid-corsair.c
index 278c6efb565d..73b3c1ff78c6 100644
--- a/drivers/hid/hid-corsair.c
+++ b/drivers/hid/hid-corsair.c
@@ -194,6 +194,9 @@ static void k90_brightness_set(struct led_classdev *led_cdev,
{
struct k90_led *led = container_of(led_cdev, struct k90_led, cdev);
+ if (led->removed)
+ return;
+
led->brightness = brightness;
schedule_work(&led->work);
}
@@ -507,8 +510,8 @@ static int k90_init_macro_functions(struct hid_device *dev)
fail_sysfs:
k90->record_led.removed = true;
- led_classdev_unregister(&k90->record_led.cdev);
cancel_work_sync(&k90->record_led.work);
+ led_classdev_unregister(&k90->record_led.cdev);
fail_record_led:
kfree(k90->record_led.cdev.name);
fail_record_led_alloc:
--
2.25.1
next prev parent reply other threads:[~2026-08-17 7:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 9:19 [PATCH] HID: corsair: fix use-after-free by reordering remove sequence Chen Changcheng
2026-07-27 1:34 ` [PATCH 0/2] HID: corsair: fix two use-after-free bugs on device removal Chen Changcheng
2026-07-27 1:34 ` [PATCH 1/2] HID: corsair: fix use-after-free by reordering remove sequence Chen Changcheng
2026-07-27 1:35 ` [PATCH 2/2] HID: corsair: cancel worker before unregistering LED to fix use-after-free Chen Changcheng
2026-08-15 18:12 ` [PATCH 0/2] HID: corsair: fix two use-after-free bugs on device removal Jeffin Philip
2026-08-17 7:23 ` Chen Changcheng
2026-08-17 7:28 ` Chen Changcheng [this message]
2026-08-03 19:22 ` Jiri Kosina
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=20260817072831.139954-1-ccc194101@163.com \
--to=ccc194101@163.com \
--cc=bentiss@kernel.org \
--cc=chenchangcheng@kylinos.cn \
--cc=jeffinphilip14@gmail.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+0a031a76585d1c7e737d@syzkaller.appspotmail.com \
/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
all inboxes | Powered by JetHome®