]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
HID: core: do not allow parsing 0-sized reports
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 1 Apr 2026 06:04:13 +0000 (23:04 -0700)
committerJiri Kosina <jkosina@suse.com>
Thu, 9 Apr 2026 15:59:54 +0000 (17:59 +0200)
Commit d7db259bd6df ("HID: core: factor out hid_parse_collections()")
reworked collection parsing code and inadvertently allowed returning
"success" when parsing 0-sized reports where old code returned -EINVAL.

Restore the original behavior by doing an explicit check.

Note that the error message now differs from the generic "item fetching
failed at offset %u/%u" that is now used only for non-empty descriptors.

Fixes: d7db259bd6df ("HID: core: factor out hid_parse_collections()")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
drivers/hid/hid-core.c

index 49775e3624ef2dbce3253fb328d29a07f959f02d..61bc42c44909afe8d623da8dfb96e9f0fb729190 100644 (file)
@@ -1272,6 +1272,11 @@ static int hid_parse_collections(struct hid_device *device)
                device->collection[i].parent_idx = -1;
 
        ret = -EINVAL;
+       if (start == end) {
+               hid_err(device, "rejecting 0-sized report descriptor\n");
+               goto out;
+       }
+
        while ((next = fetch_item(start, end, &item)) != NULL) {
                start = next;