HID: holtek: fix slab-out-of-bounds Write in holtek_kbd_input_event
authorMa Ke <make_ruc2021@163.com>
Mon, 18 Sep 2023 02:40:59 +0000 (10:40 +0800)
committerJiri Kosina <jkosina@suse.cz>
Mon, 18 Sep 2023 15:13:01 +0000 (17:13 +0200)
There is a slab-out-of-bounds Write bug in hid-holtek-kbd driver.
The problem is the driver assumes the device must have an input
but some malicious devices violate this assumption.

Fix this by checking hid_device's input is non-empty before its usage.

Signed-off-by: Ma Ke <make_ruc2021@163.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-holtek-kbd.c

index 403506b9697e75a3c2ac9042299bac8e1e2d342e..b346d68a06f5a992b4aab6fc1d8e02a40f89dd52 100644 (file)
@@ -130,6 +130,10 @@ static int holtek_kbd_input_event(struct input_dev *dev, unsigned int type,
                return -ENODEV;
 
        boot_hid = usb_get_intfdata(boot_interface);
+       if (list_empty(&boot_hid->inputs)) {
+               hid_err(hid, "no inputs found\n");
+               return -ENODEV;
+       }
        boot_hid_input = list_first_entry(&boot_hid->inputs,
                struct hid_input, list);