From: sashiko-bot@kernel.org
To: "Shen Yongchao" <grayhat@foxmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2 2/4] HID: intel-ish-hid: bound report_list iteration to message size
Date: Thu, 30 Jul 2026 13:08:16 +0000 [thread overview]
Message-ID: <20260730130817.4F0781F000E9@smtp.kernel.org> (raw)
In-Reply-To: <tencent_9DD5BCA4258383AEA05715975CA7D16C0E07@qq.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Outer loop variables used for message parsing are clobbered inside the inner sub-report processing loop, permanently desynchronizing the outer ISHTP message parser.
- [High] Processing duplicate initialization responses (e.g., HOSTIF_GET_HID_DESCRIPTOR) before `init_done` is set leads to a heap buffer overflow.
- [High] In the HOSTIF_DM_ENUM_DEVICES case, the driver suffers from out-of-bounds reads because it improperly uses `data_len` instead of `payload_len` for loop boundaries.
--
--- Patch [2]: [PATCH v2 2/4] HID: intel-ish-hid: bound report_list iteration to message size ---
commit d383335a5cf9c011bbef2b75bc812227c6cc17cc
Author: Shen Yongchao <grayhat@foxmail.com>
HID: intel-ish-hid: bound report_list iteration to message size
The commit introduces bounds checking in the ISH HID client's report parsing
loop. It ensures the iteration does not proceed past the message buffer by
calculating a list_end pointer and verifying the next report falls within the
valid payload.
> diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> index ba52e185ce051..6609130ce63e1 100644
> --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> @@ -75,6 +75,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
> struct report_list *reports_list;
> struct report *report;
> u8 *pos;
> + u8 *list_end;
> size_t report_len;
> struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
> int curr_hid_dev = client_data->cur_hid_dev;
[ ... ]
> @@ -282,8 +283,12 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
> report_type = HID_INPUT_REPORT;
> reports_list = (struct report_list *)payload;
> pos = (u8 *)reports_list->reports;
> + list_end = (u8 *)payload + payload_len;
>
> for (j = 0; j < reports_list->num_of_reports; j++) {
> + if (pos + sizeof(struct report) > list_end)
> + break;
> +
> report = (struct report *)pos;
> recv_msg = container_of(&report->msg,
> struct hostif_msg, hdr);
[Severity: High]
This is a pre-existing issue, but could we trigger a heap buffer overflow in
HOSTIF_GET_HID_DESCRIPTOR?
drivers/hid/intel-ish-hid/ishtp-hid-client.c:process_recv() {
...
case HOSTIF_GET_HID_DESCRIPTOR:
...
if (!client_data->hid_descr[curr_hid_dev])
client_data->hid_descr[curr_hid_dev] =
devm_kmalloc(cl_data_to_dev(client_data),
payload_len, GFP_KERNEL);
if (client_data->hid_descr[curr_hid_dev]) {
memcpy(client_data->hid_descr[curr_hid_dev],
payload, payload_len);
...
}
If the firmware sends two HOSTIF_GET_HID_DESCRIPTOR responses back-to-back
before initialization finishes, the first response allocates the buffer with its
payload_len.
If the second response has a larger payload_len, it skips reallocation since
the pointer is no longer NULL, but then executes the memcpy() with the new
larger payload_len.
Can this overwrite the previously allocated buffer?
[Severity: High]
This is also a pre-existing issue, but I noticed a potential out-of-bounds read
in the HOSTIF_DM_ENUM_DEVICES case:
drivers/hid/intel-ish-hid/ishtp-hid-client.c:process_recv() {
...
case HOSTIF_DM_ENUM_DEVICES:
...
for (i = 0; i < client_data->hid_dev_count; ++i) {
...
if (1 + sizeof(struct device_info) * i >=
data_len)
break;
dev_info = (struct device_info *)(payload + 1 +
sizeof(struct device_info) * i);
if (client_data->hid_devices)
memcpy(client_data->hid_devices + i,
dev_info,
sizeof(struct device_info));
}
...
}
Does the check `1 + sizeof(struct device_info) * i >= data_len` use the wrong
boundary?
Since data_len is the total size of the receive buffer, but the payload is
offset by cur_pos and the message header size, it seems this check could allow
reading past the end of the receive buffer if payload_len is small but
hid_dev_count is large.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260730115600.218172-1-grayhat@foxmail.com?part=2
next prev parent reply other threads:[~2026-07-30 13:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260730115600.218172-1-grayhat@foxmail.com>
2026-07-30 12:52 ` [PATCH v2 1/4] HID: intel-ish-hid: fix report_list iterator pointer arithmetic Shen Yongchao
2026-07-30 13:17 ` sashiko-bot
2026-07-30 18:08 ` srinivas pandruvada
2026-07-30 12:52 ` [PATCH v2 2/4] HID: intel-ish-hid: bound report_list iteration to message size Shen Yongchao
2026-07-30 13:08 ` sashiko-bot [this message]
2026-07-30 12:52 ` [PATCH v2 3/4] HID: intel-ish-hid: prevent size_t underflow in report_list parsing Shen Yongchao
2026-07-30 13:11 ` sashiko-bot
2026-07-30 12:52 ` [PATCH v2 4/4] HID: intel-ish-hid: add full entry bounds check to " Shen Yongchao
2026-07-30 13:09 ` 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=20260730130817.4F0781F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=grayhat@foxmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.