From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Jiri Kosina <jikos@kernel.org>
Cc: Pengpeng <pengpeng@iscas.ac.cn>,
Benjamin Tissoires <bentiss@kernel.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] HID: mcp2200: validate input report length
Date: Mon, 6 Jul 2026 17:09:32 +0800 [thread overview]
Message-ID: <20260706090932.75673-1-pengpeng@iscas.ac.cn> (raw)
From: Pengpeng <pengpeng@iscas.ac.cn>
mcp2200_raw_event() dispatches on the first byte of the HID input
report and overlays the READ_ALL response structure on the same buffer.
The HID core passes the actual report size to the callback, so validate
that the command byte and READ_ALL response fields are present before
reading them.
Reject truncated reports for the pending command instead of reading
beyond the current input report payload.
Signed-off-by: Pengpeng <pengpeng@iscas.ac.cn>
---
drivers/hid/hid-mcp2200.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/hid/hid-mcp2200.c b/drivers/hid/hid-mcp2200.c
index dafdd5b4a079..d2f45892dc22 100644
--- a/drivers/hid/hid-mcp2200.c
+++ b/drivers/hid/hid-mcp2200.c
@@ -299,8 +299,19 @@ static int mcp2200_raw_event(struct hid_device *hdev, struct hid_report *report,
struct mcp2200 *mcp = hid_get_drvdata(hdev);
struct mcp_read_all_resp *all_resp;
+ if (size < 1) {
+ mcp->status = -EINVAL;
+ complete(&mcp->wait_in_report);
+ return 0;
+ }
+
switch (data[0]) {
case READ_ALL:
+ if (size < sizeof(*all_resp)) {
+ mcp->status = -EINVAL;
+ break;
+ }
+
all_resp = (struct mcp_read_all_resp *) data;
mcp->status = 0;
mcp->gpio_inval = all_resp->io_port_val_bmap;
--
2.43.0
next reply other threads:[~2026-07-06 9:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 9:09 Pengpeng Hou [this message]
2026-07-06 9:19 ` [PATCH] HID: mcp2200: validate input report length sashiko-bot
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=20260706090932.75673-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@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