From: Jiale Yao <yaojiale02@163.com>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
David Barksdale <dbarksdale@uplogix.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jiale Yao <yaojiale02@163.com>, stable@vger.kernel.org
Subject: [PATCH 03/10] HID: cp2112: validate response report lengths
Date: Thu, 24 Sep 2026 22:44:06 +0800 [thread overview]
Message-ID: <20260924144414.1192037-4-yaojiale02@163.com> (raw)
In-Reply-To: <20260924144414.1192037-1-yaojiale02@163.com>
The HID core invokes raw_event callbacks before validating the report
length. cp2112_raw_event() reads every field of a transfer status response
without checking size. For a data response, it reads the length at offset
two and copies that many bytes from offset three, again without ensuring
that the input report contains them.
Require a complete transfer status structure. For data responses, first
require the header and then ensure the clamped payload length fits in the
received report before copying it.
Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init
sequence") added the same kind of raw_event length validation to hid-asus.
Fixes: e932d8178667 ("HID: add hid-cp2112 driver")
Cc: stable@vger.kernel.org
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
drivers/hid/hid-cp2112.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 04379db93571..6b938f75e72f 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -1430,6 +1430,9 @@ static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report,
switch (data[0]) {
case CP2112_TRANSFER_STATUS_RESPONSE:
+ if (size < sizeof(*xfer))
+ return 0;
+
hid_dbg(hdev, "xfer status: %02x %02x %04x %04x\n",
xfer->status0, xfer->status1,
be16_to_cpu(xfer->retries), be16_to_cpu(xfer->length));
@@ -1463,11 +1466,16 @@ static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report,
atomic_set(&dev->xfer_avail, 1);
break;
case CP2112_DATA_READ_RESPONSE:
+ if (size < 3)
+ return 0;
+
hid_dbg(hdev, "read response: %02x %02x\n", data[1], data[2]);
dev->read_length = data[2];
if (dev->read_length > sizeof(dev->read_data))
dev->read_length = sizeof(dev->read_data);
+ if (dev->read_length > size - 3)
+ return 0;
memcpy(dev->read_data, &data[3], dev->read_length);
atomic_set(&dev->read_avail, 1);
@@ -1494,4 +1502,3 @@ module_hid_driver(cp2112_driver);
MODULE_DESCRIPTION("Silicon Labs HID USB to SMBus master bridge");
MODULE_AUTHOR("David Barksdale <dbarksdale@uplogix.com>");
MODULE_LICENSE("GPL");
-
--
2.34.1
next prev parent reply other threads:[~2026-09-24 14:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 14:44 [PATCH 00/10] HID: validate short reports in raw_event callbacks Jiale Yao
2026-09-24 14:44 ` [PATCH 01/10] HID: alps: reject short input reports Jiale Yao
2026-09-24 14:44 ` [PATCH 02/10] HID: cougar: reject short special-key reports Jiale Yao
2026-09-24 14:44 ` Jiale Yao [this message]
2026-09-24 14:44 ` [PATCH 04/10] HID: elo: reject short touchscreen reports Jiale Yao
2026-09-24 14:44 ` [PATCH 05/10] HID: logitech-dj: validate unnumbered keyboard reports Jiale Yao
2026-09-24 14:44 ` [PATCH 06/10] HID: mcp2200: validate READ_ALL response length Jiale Yao
2026-09-24 14:44 ` [PATCH 07/10] HID: mcp2221: validate response report length Jiale Yao
2026-09-24 14:44 ` [PATCH 08/10] HID: prodikeys: validate fixed-format MIDI reports Jiale Yao
2026-09-24 14:44 ` [PATCH 09/10] HID: pxrc: reject short input reports Jiale Yao
2026-09-24 14:44 ` [PATCH 10/10] HID: zydacron: validate key report length Jiale Yao
-- strict thread matches above, loose matches on Subject: below --
2026-09-24 14:13 [PATCH 00/10] HID: validate short reports in raw_event callbacks Jiale Yao
2026-09-24 14:13 ` [PATCH 03/10] HID: cp2112: validate response report lengths Jiale Yao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924144414.1192037-4-yaojiale02@163.com \
--to=yaojiale02@163.com \
--cc=bentiss@kernel.org \
--cc=dbarksdale@uplogix.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®