* [PATCH v3 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response
2026-12-05 16:07 [PATCH v3 0/2] HID: intel-ish-hid: Size the buffers for a later, larger response Maoyi Xie via B4 Relay
@ 2026-12-05 16:07 ` Maoyi Xie via B4 Relay
2026-12-05 16:07 ` [PATCH v3 2/2] HID: intel-ish-hid: Allocate hid_devices for MAX_HID_DEVICES entries Maoyi Xie via B4 Relay
1 sibling, 0 replies; 3+ messages in thread
From: Maoyi Xie via B4 Relay @ 2026-12-05 16:07 UTC (permalink / raw)
To: Jiri Kosina, Srinivas Pandruvada
Cc: Maoyi Xie, linux-input, Benjamin Tissoires, Zhang Lixu
From: Maoyi Xie <maoyixie.tju@gmail.com>
process_recv() allocates hid_descr[i] and report_descr[i] only when they
are NULL. It then copies each response into them with the length of
that response. After an ISH reset, a longer descriptor for the same
index can overflow the buffer allocated for the first response. A
second, longer response to one request does the same.
Size the buffer to the received length with devm_krealloc() before the
copy. Ignore a response whose done flag is already set.
ishtp_hid_parse() may be reading the report descriptor at that point.
Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under AddressSanitizer. Not tested on
hardware.
Fixes: 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
Reviewed-by: Zhang Lixu <lixu.zhang@intel.com>
Tested-by: Zhang Lixu <lixu.zhang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
v3:
- No change except the new tags.
I used an LLM to help write the harness and this patch.
---
drivers/hid/intel-ish-hid/ishtp-hid-client.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
index 4a56fb3eb366..d521c520178b 100644
--- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c
+++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
@@ -68,6 +68,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
{
struct hostif_msg *recv_msg;
unsigned char *payload;
+ unsigned char *descr;
struct device_info *dev_info;
int i, j;
size_t payload_len, total_len, cur_pos, raw_len, msg_len;
@@ -170,11 +171,13 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
break;
}
- 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]) {
+ if (client_data->hid_descr_done)
+ break;
+ descr = devm_krealloc(cl_data_to_dev(client_data),
+ client_data->hid_descr[curr_hid_dev],
+ payload_len, GFP_KERNEL);
+ if (descr) {
+ client_data->hid_descr[curr_hid_dev] = descr;
memcpy(client_data->hid_descr[curr_hid_dev],
payload, payload_len);
client_data->hid_descr_size[curr_hid_dev] =
@@ -195,11 +198,13 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
ish_hw_reset(ishtp_get_ishtp_device(hid_ishtp_cl));
break;
}
- if (!client_data->report_descr[curr_hid_dev])
- client_data->report_descr[curr_hid_dev] =
- devm_kmalloc(cl_data_to_dev(client_data),
- payload_len, GFP_KERNEL);
- if (client_data->report_descr[curr_hid_dev]) {
+ if (client_data->report_descr_done)
+ break;
+ descr = devm_krealloc(cl_data_to_dev(client_data),
+ client_data->report_descr[curr_hid_dev],
+ payload_len, GFP_KERNEL);
+ if (descr) {
+ client_data->report_descr[curr_hid_dev] = descr;
memcpy(client_data->report_descr[curr_hid_dev],
payload,
payload_len);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v3 2/2] HID: intel-ish-hid: Allocate hid_devices for MAX_HID_DEVICES entries
2026-12-05 16:07 [PATCH v3 0/2] HID: intel-ish-hid: Size the buffers for a later, larger response Maoyi Xie via B4 Relay
2026-12-05 16:07 ` [PATCH v3 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response Maoyi Xie via B4 Relay
@ 2026-12-05 16:07 ` Maoyi Xie via B4 Relay
1 sibling, 0 replies; 3+ messages in thread
From: Maoyi Xie via B4 Relay @ 2026-12-05 16:07 UTC (permalink / raw)
To: Jiri Kosina, Srinivas Pandruvada
Cc: Maoyi Xie, linux-input, Benjamin Tissoires, Zhang Lixu
From: Maoyi Xie <maoyixie.tju@gmail.com>
process_recv() allocates hid_devices only when it is NULL, with the
count of the first ENUM_DEVICES response. It then copies as many
entries as each response announces. A later response with a larger
count, for example after an ISH reset, can write past the array.
Allocate the array once for MAX_HID_DEVICES entries, the size of the
other per-device arrays. The array is never reallocated, because
hid_ishtp_cl_init() and the request paths read it without a lock.
Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under AddressSanitizer. Not tested on
hardware.
Fixes: 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
v3:
- Allocate MAX_HID_DEVICES entries instead of U8_MAX, as Zhang Lixu
suggested.
- Rebase on hid.git for-next.
- Change the subject to name MAX_HID_DEVICES.
I used an LLM to help write the harness and this patch.
---
drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
index d521c520178b..47cc2fb71810 100644
--- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c
+++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
@@ -128,7 +128,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
if (!client_data->hid_devices)
client_data->hid_devices = devm_kzalloc_objs(cl_data_to_dev(client_data),
struct device_info,
- client_data->hid_dev_count);
+ MAX_HID_DEVICES);
if (!client_data->hid_devices) {
dev_err(cl_data_to_dev(client_data),
"Mem alloc failed for hid device info\n");
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread