From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380111; b=hzB8bpTW/lr/KgToyCLBKkvObaD3SCxD1V3jr/hRlmGXm00S3ajnwIVRY1tFymEKQ6Z/ UT7rR4JJmM3e9CPdG6uoc4sU+D/8h9///DdD4QBZCrjHLaFZhojPh7U61GZ1yRLNRLolk BLsyeVQ/t0RsL1/1QcYCg3AM2KJAcSX5OcOWmx0F5npErUTDUbSrZuqzDYE/6bqgsRwXd 3/+vSS+g8z/+WrAzhcCpEiZqaZ3WUwGCYyXGZiy1H1RXG4FiZEbCffBICR39ttS70f4g5 Hi1WLA//HIhcunFg5AnZlGtDlI906H5i2cFdDVdG8cuqgk+Fseb7OFrSEI9fTHlVvNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380111; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=6jgb2Z4xhsoUPzsdJBJfFkcjCIKrBrTF3jsRlNXXvsg=; b=M9+jUWFsPeW21gW9Vrvu+HKRZ5mUn2eLYb3YgTElNpj+8S9BhRBsSCObEnnVHlMS7bob LGFax5SrLNz67AVb0xUuoIFdIDpgHFLPO+db6z3AJbhTCAPzoH3DrAWeWDy6ypyCjWX7L Hvojk6I9Er4kGjduzw+v6HXWHWsDlT/Fi49LCPvtu9Vk6+l7Ctd1Z7lXt8abCL1sIDS0D HAQfrrN2qygRxBGfzpE5L7lAYUlz+HnUnDqyWT2wk511SDA6e4SnuWCdk5pcYh+CpwBBA 0Fiyt8rYgkMxR3/baAUp3wxzd9WHrHr8B02A+TEsDC756Cjr0bhnIv4vOAZXATd3+5g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ZDoOOmqJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC033606A322; Fri, 4 Dec 2026 10:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ZDoOOmqJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4464D1F000C2; Fri, 4 Dec 2026 10:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380111; bh=6jgb2Z4xhsoUPzsdJBJfFkcjCIKrBrTF3jsRlNXXvsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZDoOOmqJj8xYItKK8DJdBudJAAwZQVGYluZVK9zW+LrZt2XhE5eXJ1BkXXYsQRUzq PKB9MUGRfVEaLsFEEODhbxhz2WCkgNjdiov/u6lV31SPzVQE7bgKsGq1JNllrNrO3E 4e4aVNdgIagFNiu/LyEtjrpjord8GBU5SqEsHiRc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+abcedffc9201f2bb66c2@syzkaller.appspotmail.com, Danish Khateeb , Chen Changcheng , Jiri Kosina , Sasha Levin Subject: [PATCH 7.3 129/742] HID: corsair: use disable_work_sync() to tear down the LED workers Date: Fri, 4 Dec 2026 18:59:53 +0900 Message-ID: <20261204100638.547283565@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Danish Khateeb [ Upstream commit cc8d022e8679e34b4892fa6c0a3fa2db917a6283 ] Tearing down the K90 LEDs races with their brightness workers in two different ways, and swapping cancel_work_sync() and led_classdev_unregister() around only trades one for the other. Cancelling before the unregister, as k90_cleanup_backlight() and k90_cleanup_macro_functions() have done since commit eb51c9f8cb4f ("HID: corsair: cancel worker before unregistering LED to fix use-after-free"), leaves led_classdev_unregister() free to re-arm the worker: it calls led_set_brightness(led_cdev, LED_OFF), which reaches k90_brightness_set() and schedule_work()s the item again. The structure holding that work is then freed while it is still linked into the worklist: BUG: KASAN: slab-use-after-free in __list_add_valid_or_report+0x186/0x210 Read of size 8 at addr ffff888102a1ead0 by task kworker/0:1/11 __queue_work+0xade/0x1350 queue_work_on+0xb6/0xc0 led_classdev_unregister+0x26b/0x340 corsair_remove+0x1c2/0x2d0 hid_device_remove+0xba/0x1e0 usbhid_disconnect+0xa0/0xe0 Allocated by task 129: corsair_probe+0x560/0xd50 Freed by task 11: corsair_remove+0xec/0x2d0 Cancelling after the unregister avoids that, but reintroduces precisely the use-after-free that commit set out to fix: a worker that has already tested led->removed and found it false goes on to dereference led->cdev.dev, which led_classdev_unregister() has meanwhile freed via device_unregister(). Use disable_work_sync(), which provides both halves at once. It waits for a worker that is already executing, so nothing can be sitting between the led->removed test and the led->cdev.dev dereference when the device goes away, and it makes the subsequent schedule_work() from the LED_OFF callback fail rather than queue, so nothing is left on the worklist to be freed. The ordering then stops mattering. The removed flag is left alone; it is redundant for these paths now but harmless. The fail_sysfs error path in k90_init_macro_functions() unregisters before cancelling, and so still carries the dereference-after-free that was fixed in the teardown paths, so convert it too. Fixes: eb51c9f8cb4f ("HID: corsair: cancel worker before unregistering LED to fix use-after-free") Reported-by: syzbot+abcedffc9201f2bb66c2@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=abcedffc9201f2bb66c2 Assisted-by: LLM Signed-off-by: Danish Khateeb Reviewed-by: Chen Changcheng Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-corsair.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-corsair.c b/drivers/hid/hid-corsair.c index 278c6efb565df..f966005d69dd6 100644 --- a/drivers/hid/hid-corsair.c +++ b/drivers/hid/hid-corsair.c @@ -507,8 +507,8 @@ static int k90_init_macro_functions(struct hid_device *dev) fail_sysfs: k90->record_led.removed = true; + disable_work_sync(&k90->record_led.work); led_classdev_unregister(&k90->record_led.cdev); - cancel_work_sync(&k90->record_led.work); fail_record_led: kfree(k90->record_led.cdev.name); fail_record_led_alloc: @@ -524,7 +524,7 @@ static void k90_cleanup_backlight(struct hid_device *dev) if (drvdata->backlight) { drvdata->backlight->removed = true; - cancel_work_sync(&drvdata->backlight->work); + disable_work_sync(&drvdata->backlight->work); led_classdev_unregister(&drvdata->backlight->cdev); kfree(drvdata->backlight->cdev.name); kfree(drvdata->backlight); @@ -540,7 +540,7 @@ static void k90_cleanup_macro_functions(struct hid_device *dev) sysfs_remove_group(&dev->dev.kobj, &k90_attr_group); k90->record_led.removed = true; - cancel_work_sync(&k90->record_led.work); + disable_work_sync(&k90->record_led.work); led_classdev_unregister(&k90->record_led.cdev); kfree(k90->record_led.cdev.name); -- 2.53.0