]> git.hungrycats.org Git - linux/commitdiff
HID: mcp2200: validate READ_ALL response length
authorJiale Yao <yaojiale02@163.com>
Thu, 24 Sep 2026 14:44:09 +0000 (22:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:10:50 +0000 (12:10 -0500)
commit 26ce0e6bf0b27fc6a2f490f38555dfd0a27c9605 upstream.

The HID core invokes raw_event callbacks before validating the report
length.  mcp2200_raw_event() casts a READ_ALL response to struct
mcp_read_all_resp and reads fields through offset ten without checking that
the response contains the structure.

A one-byte READ_ALL response reproduced the issue under KASAN:

  BUG: KASAN: slab-out-of-bounds in mcp2200_raw_event+0x24b/0x3a0
  Read of size 1 by task hidtrigger/89
  Call Trace:
   mcp2200_raw_event+0x24b/0x3a0
   kasan_report+0x139/0x170

Reject an incomplete READ_ALL response with a protocol error before reading
its fields.  The common completion path then wakes the command waiter with
the error instead of leaving it to time out.

Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init
sequence") added the same kind of raw_event length validation to hid-asus.

Fixes: 740329d7120f ("HID: mcp2200: added driver for GPIOs of MCP2200")
Cc: stable@vger.kernel.org
Signed-off-by: Jiale Yao <yaojiale02@163.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hid/hid-mcp2200.c

index dafdd5b4a0797b64e61a83af9855d51b0f0899ab..c6fd5fb5d57854b5f8de35231356c71bd313f9b8 100644 (file)
@@ -301,6 +301,11 @@ static int mcp2200_raw_event(struct hid_device *hdev, struct hid_report *report,
 
        switch (data[0]) {
        case READ_ALL:
+               if (size < sizeof(*all_resp)) {
+                       mcp->status = -EPROTO;
+                       break;
+               }
+
                all_resp = (struct mcp_read_all_resp *) data;
                mcp->status = 0;
                mcp->gpio_inval = all_resp->io_port_val_bmap;