This is a note to let you know that I've just added the patch titled HID: asus: use spinlock to safely schedule workers to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: hid-asus-use-spinlock-to-safely-schedule-workers.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 4ab3a086d10eeec1424f2e8a968827a6336203df Mon Sep 17 00:00:00 2001 From: Pietro Borrello <borrello@xxxxxxxxxxxxxxxx> Date: Sun, 12 Feb 2023 19:00:03 +0000 Subject: HID: asus: use spinlock to safely schedule workers From: Pietro Borrello <borrello@xxxxxxxxxxxxxxxx> commit 4ab3a086d10eeec1424f2e8a968827a6336203df upstream. Use spinlocks to deal with workers introducing a wrapper asus_schedule_work(), and several spinlock checks. Otherwise, asus_kbd_backlight_set() may schedule led->work after the structure has been freed, causing a use-after-free. Fixes: af22a610bc38 ("HID: asus: support backlight on USB keyboards") Signed-off-by: Pietro Borrello <borrello@xxxxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/20230125-hid-unregister-leds-v4-5-7860c5763c38@xxxxxxxxxxxxxxxx Signed-off-by: Benjamin Tissoires <benjamin.tissoires@xxxxxxxxxx> Signed-off-by: Stefan Ghinea <stefan.ghinea@xxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/hid/hid-asus.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -491,6 +491,16 @@ static int rog_nkey_led_init(struct hid_ return ret; } +static void asus_schedule_work(struct asus_kbd_leds *led) +{ + unsigned long flags; + + spin_lock_irqsave(&led->lock, flags); + if (!led->removed) + schedule_work(&led->work); + spin_unlock_irqrestore(&led->lock, flags); +} + static void asus_kbd_backlight_set(struct led_classdev *led_cdev, enum led_brightness brightness) { @@ -502,7 +512,7 @@ static void asus_kbd_backlight_set(struc led->brightness = brightness; spin_unlock_irqrestore(&led->lock, flags); - schedule_work(&led->work); + asus_schedule_work(led); } static enum led_brightness asus_kbd_backlight_get(struct led_classdev *led_cdev) @@ -526,9 +536,6 @@ static void asus_kbd_backlight_work(stru int ret; unsigned long flags; - if (led->removed) - return; - spin_lock_irqsave(&led->lock, flags); buf[4] = led->brightness; spin_unlock_irqrestore(&led->lock, flags); Patches currently in stable-queue which might be from borrello@xxxxxxxxxxxxxxxx are queue-6.1/hid-asus-use-spinlock-to-protect-concurrent-accesses.patch queue-6.1/hid-asus-use-spinlock-to-safely-schedule-workers.patch