Skip to contentSkip to conversation

HID: intel-ish-hid: clamp HID device count to MAX_HID_DEVICES

PATCH Superseded Shen Yongchao 5 participants 10 messages Jul 30 – Aug 1 1 message not in the archive

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi Greg,

Quoted 2 lines

Why min_t()? Was this generated by a LLM? If so, you have to document that as well.

Yes, the patch was drafted with AI assistance; the vulnerability analysis, source-level verification, and reproducer work were done manually. I should have disclosed that -- thank you for asking.

And you are right about min_t(), it is unnecessarily obscure here. v2 below uses a plain if instead.

Regards,
Shen Yongchao

#2 lore raw

PATCH v2 1/1 HID: intel-ish-hid: clamp HID device count to MAX_HID_DEVICES

In reply to a message not in the archive

The HOSTIF_DM_ENUM_DEVICES response handler takes the HID device count from the first payload byte of the ISH firmware response (max 255) and stores it in hid_dev_count without any bounds check. This value propagates to num_hid_devices and is used to index five fixed-size arrays in struct ishtp_cl_data (MAX_HID_DEVICES = 32): report_descr[], report_descr_size[], hid_sensor_hubs[], hid_descr[], and hid_descr_size[].

If the firmware reports more than 32 devices, hid_ishtp_cl_init() writes past all five arrays, corrupting subsequent struct fields (including work_struct members with embedded function pointers) and potentially adjacent heap objects.

Clamp hid_dev_count to MAX_HID_DEVICES at the single point where it enters the driver (process_recv, ENUM_DEVICES branch), which covers both the probe and the reset paths.

This is a data-validation hardening fix: the ISH firmware is within the platform trust boundary (loaded via CSME).

This patch was drafted with AI assistance; the vulnerability analysis and source-level verification were done manually.

Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")
---
 drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hid/intel-ish-hid/ishtp-hid-client.c +2 -0
index 6d64008..XXXXXXX 100644
@@ -123,6 +123,8 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
 				break;
 			}
 			client_data->hid_dev_count = (unsigned int)*payload;
+			if (client_data->hid_dev_count > MAX_HID_DEVICES)
+				client_data->hid_dev_count = MAX_HID_DEVICES;
 			if (!client_data->hid_devices)
 				client_data->hid_devices = devm_kcalloc(
 						cl_data_to_dev(client_data),
#3 lore raw
Quoted 17 lines · Shen Yongchao

The HOSTIF_DM_ENUM_DEVICES response handler takes the HID device count from the first payload byte of the ISH firmware response (max 255) and stores it in hid_dev_count without any bounds check. This value propagates to num_hid_devices and is used to index five fixed-size arrays in struct ishtp_cl_data (MAX_HID_DEVICES = 32): report_descr[], report_descr_size[], hid_sensor_hubs[], hid_descr[], and hid_descr_size[].

If the firmware reports more than 32 devices, hid_ishtp_cl_init() writes past all five arrays, corrupting subsequent struct fields (including work_struct members with embedded function pointers) and potentially adjacent heap objects.

Clamp hid_dev_count to MAX_HID_DEVICES at the single point where it enters the driver (process_recv, ENUM_DEVICES branch), which covers both the probe and the reset paths.

Quoted 5 lines

This is a data-validation hardening fix: the ISH firmware is within the platform trust boundary (loaded via CSME).

This patch was drafted with AI assistance; the vulnerability analysis and source-level verification were done manually.

Great, please use the Assisted-by: tag as the documentation requries :)

thanks,

greg k-h

#4 lore raw
In reply to Shen Yongchao
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

Pre-existing issues:
- [High] Heap buffer overflow due to missing reallocation on repeated firmware enumeration.
- [High] Pointer arithmetic bug and integer underflow in HOSTIF_PUBLISH_INPUT_REPORT_LIST leads to massive out-of-bounds read.
- [High] Missing unregistration of HID devices on probe error path leads to Use-After-Free.
- [High] Dangling ISHTP event callback on probe error leads to Use-After-Free.
- [High] Missing cancellation of workqueues in the device remove path leads to Use-After-Free.
- [Medium] Out-of-bounds read in ENUM_DEVICES due to flawed bounds check.
--

--- Patch [1]: [PATCH v2] HID: intel-ish-hid: clamp HID device count to MAX_HID_DEVICES --- commit c49d3200c2984f75996b1adb9efa6e6cf870abe9
Author: Shen Yongchao <[email protected]>
Subject: HID: intel-ish-hid: clamp HID device count to MAX_HID_DEVICES

This patch addresses an out-of-bounds array write in the ISH HID client driver. It clamps the reported HID device count to MAX_HID_DEVICES during the HOSTIF_DM_ENUM_DEVICES response parsing, preventing firmware from overwriting fixed-size arrays within the client data structure.

drivers/hid/intel-ish-hid/ishtp-hid-client.c static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, · line 130

Quoted 13 lines
drivers/hid/intel-ish-hid/ishtp-hid-client.c +2 -0
index 6d64008f2ce05..6ea997932aeab 100644
@@ -123,6 +123,8 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
 				break;
 			}
 			client_data->hid_dev_count = (unsigned int)*payload;
+			if (client_data->hid_dev_count > MAX_HID_DEVICES)
+				client_data->hid_dev_count = MAX_HID_DEVICES;
 			if (!client_data->hid_devices)
 				client_data->hid_devices = devm_kcalloc(
 						cl_data_to_dev(client_data),

[Severity: High]
This is a pre-existing issue, but does this allocation logic leave us vulnerable if the firmware sends the HOSTIF_DM_ENUM_DEVICES packet multiple times?

If a reset occurs or multiple packets are sent, and the new hid_dev_count is larger than the previous one, the check for (!client_data->hid_devices) will skip reallocation.

The loop that follows will then copy the new, larger count of devices into the older, smaller buffer, which can corrupt adjacent heap memory.

[Severity: Medium]
This isn't a bug introduced by this patch, but is there a bounds checking flaw in the device enumeration loop?

drivers/hid/intel-ish-hid/ishtp-hid-client.c:process_recv() {
...

    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);

...
}

The check uses data_len (the absolute total message length) but compares it to an offset relative to payload. Since payload is already offset by the header size (6 bytes), this check permits reading out of bounds.

Also, it only verifies the start offset, missing the 9-byte size of the struct itself, which can allow uninitialized ring buffer memory to leak.

[Severity: High]
This is a pre-existing issue, but can this pointer arithmetic lead to a massive out-of-bounds read in the HOSTIF_PUBLISH_INPUT_REPORT_LIST handler?

drivers/hid/intel-ish-hid/ishtp-hid-client.c:process_recv() {
...

    payload_len = report_len - sizeof(struct hostif_msg_hdr);
    ...
    report += sizeof(*report) + payload_len;

...
}

If report_len is less than 6, payload_len underflows to a very large integer.

Furthermore, because report is a typed pointer to struct report (which is size 8), adding (sizeof(*report) + payload_len) multiplies that offset by 8.

This advances the pointer far past the message boundary, causing subsequent iterations to read arbitrary memory and pass it to hid_input_report().

[Severity: High]
This isn't a bug introduced by this patch, but does the initialization path leak HID devices on probe failure?

drivers/hid/intel-ish-hid/ishtp-hid-client.c:hid_ishtp_cl_init() {
...

    for (i = 0; i < client_data->num_hid_devices; ++i) {
        ...
        rv = ishtp_hid_probe(i, client_data);
        if (rv) {
            dev_err(...);
            goto err_cl_disconnect;
        }
    }

...
}

If ishtp_hid_probe() fails during the loop, it returns without unregistering the devices that succeeded in previous iterations.

When the probe fails, devres frees the client_data, but the leaked active HID devices retain dangling pointers to this freed memory via their driver_data, leading to a use-after-free when accessed.

[Severity: High]
This is a pre-existing issue, but is the event callback left dangling on probe errors?

drivers/hid/intel-ish-hid/ishtp-hid-client.c:hid_ishtp_cl_init() {
...

    ishtp_register_event_cb(client_data->cl_device, ish_cl_event_cb);

...
}

The callback is registered here but is not unregistered in the err_cl_disconnect path or the hid_ishtp_cl_probe() error path.

If operations like ishtp_enum_enum_devices() fail, probe aborts and client_data is freed. An incoming ISHTP message would then trigger the registered callback, dereferencing the freed client_data and causing a use-after-free.

[Severity: High]
This isn't a bug introduced by this patch, but are the workqueues properly canceled during device removal?

drivers/hid/intel-ish-hid/ishtp-hid-client.c:hid_ishtp_cl_remove() {
    struct ishtp_cl *hid_ishtp_cl = ishtp_get_drvdata(cl_device);
    struct ishtp_cl_data *client_data = ishtp_get_client_data(hid_ishtp_cl);
    ...
}

The remove function tears down the driver instance but omits stopping the embedded work items (client_data->work and client_data->resume_work) via cancel_work_sync().

Since client_data is devres-managed, it is freed shortly after remove() returns. If a reset or resume event occurs concurrently, the uncanceled works will execute using freed memory, resulting in a use-after-free.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#5 lore raw
In reply to Shen Yongchao

+Lixu

Quoted 20 lines · Shen Yongchao

The HOSTIF_DM_ENUM_DEVICES response handler takes the HID device count from the first payload byte of the ISH firmware response (max 255) and stores it in hid_dev_count without any bounds check.  This value propagates to num_hid_devices and is used to index five fixed-size arrays in struct ishtp_cl_data (MAX_HID_DEVICES = 32): report_descr[], report_descr_size[], hid_sensor_hubs[], hid_descr[], and hid_descr_size[].

If the firmware reports more than 32 devices, hid_ishtp_cl_init() writes past all five arrays, corrupting subsequent struct fields (including work_struct members with embedded function pointers) and potentially adjacent heap objects.

Clamp hid_dev_count to MAX_HID_DEVICES at the single point where it enters the driver (process_recv, ENUM_DEVICES branch), which covers both the probe and the reset paths.

This is a data-validation hardening fix: the ISH firmware is within the platform trust boundary (loaded via CSME).

Quoted 6 lines

This patch was drafted with AI assistance; the vulnerability analysis and source-level verification were done manually.

Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")

Missing

Assisted-by AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Thanks,
Srinivas

Quoted 24 lines

---
 drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 ++

 1 file changed, 2 insertions(+)
drivers/hid/intel-ish-hid/ishtp-hid-client.c +0 -0
index 6d64008..XXXXXXX 100644
@@ -123,6 +123,8 @@ static void process_recv(struct ishtp_cl
 *hid_ishtp_cl, void *recv_buf,
  				break;
  			}

  client_data->hid_dev_count = (unsigned int)*payload;

drivers/hid/intel-ish-hid/ishtp-hid-client.c +1 -0
+			if (client_data->hid_dev_count >

MAX_HID_DEVICES)

drivers/hid/intel-ish-hid/ishtp-hid-client.c +1 -0
+				client_data->hid_dev_count =

MAX_HID_DEVICES;
  if (!client_data->hid_devices) client_data->hid_devices = devm_kcalloc(
  cl_data_to_dev(clien t_data),

#6 lore raw

Thanks, +Lixu noted.

Corrected tag block:

This patch was drafted with AI assistance.

Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")
Assisted-by Hermes:kimi-k3

Let me know if you want it resent as a proper [PATCH v2].

Thanks,
Shen Yongchao

Quoted 245 lines

+Lixu

Quoted 96 lines · Shen Yongchao

The HOSTIF_DM_ENUM_DEVICES response handler takes the HID device

count from the first payload byte of the ISH firmware response

(max 255) and stores it in hid_dev_count without any bounds

check.  This value propagates to num_hid_devices and is used to

index five fixed-size arrays in struct ishtp_cl_data

(MAX_HID_DEVICES = 32): report_descr[], report_descr_size[],

hid_sensor_hubs[], hid_descr[], and hid_descr_size[].

If the firmware reports more than 32 devices, hid_ishtp_cl_init()

writes past all five arrays, corrupting subsequent struct fields

(including work_struct members with embedded function pointers)

and potentially adjacent heap objects.

Clamp hid_dev_count to MAX_HID_DEVICES at the single point where

it enters the driver (process_recv, ENUM_DEVICES branch), which

covers both the probe and the reset paths.

This is a data-validation hardening fix: the ISH firmware is

within the platform trust boundary (loaded via CSME).

This patch was drafted with AI assistance; the vulnerability

analysis and source-level verification were done manually.

Quoted 5 lines
Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")

Missing

Assisted-by AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Thanks,

Srinivas

Quoted 93 lines

---

 drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 ++

 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/hid/intel-ish-hid/ishtp-hid-client.c

index 6d64008..XXXXXXX 100644

--- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c

+++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c

(quoted diff) +0 -0
@@ -123,6 +123,8 @@ static void process_recv(struct ishtp_cl
 
 
 
 *hid_ishtp_cl, void *recv_buf,
 
 

  break;

  }

  client_data->hid_dev_count = (unsigned

int)*payload;

(quoted diff) +1 -0
+			if (client_data->hid_dev_count >

MAX_HID_DEVICES)

(quoted diff) +1 -0
+				client_data->hid_dev_count =

MAX_HID_DEVICES;

  if (!client_data->hid_devices)

  client_data->hid_devices =

devm_kcalloc(

  cl_data_to_dev(clien

t_data),

#7 lore raw
Quoted 4 lines · On Fri, Jul 31, 2026 at 09:46:43AM +0800, [email protected] wrote:

Thanks, +Lixu noted.

Corrected tag block:

Quoted 8 lines

This patch was drafted with AI assistance.

Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")
Assisted-by Hermes:kimi-k3

Let me know if you want it resent as a proper [PATCH v2].

That would be v3 :)

#8 lore raw
In reply to [email protected]
Quoted 4 lines · On Fri, 2026-07-31 at 09:46 +0800, [email protected] wrote:

Thanks, +Lixu noted.

Corrected tag block:

Quoted 9 lines

This patch was drafted with AI assistance.

Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")
Assisted-by Hermes:kimi-k3

Let me know if you want it resent as a proper [PATCH v2].

Yes with new version. Add Tested by tag also from Lixu.

Also some suggestions:
- Avoid top posting like this, you can add this part just after your existing tags.
- If the patch is long you can trim

- I think you use outlook to reply, there are some suggestions of email clients and other suggestions.
https://docs.kernel.org/process/email-clients.html

Also some other links:
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html

Thanks,
Srinivas

Quoted 252 lines

Thanks,
Shen Yongchao

Quoted 246 lines

+Lixu

Quoted 96 lines · Shen Yongchao

The HOSTIF_DM_ENUM_DEVICES response handler takes the HID device

count from the first payload byte of the ISH firmware response

(max 255) and stores it in hid_dev_count without any bounds

check.  This value propagates to num_hid_devices and is used to

index five fixed-size arrays in struct ishtp_cl_data

(MAX_HID_DEVICES = 32): report_descr[], report_descr_size[],

hid_sensor_hubs[], hid_descr[], and hid_descr_size[].

If the firmware reports more than 32 devices, hid_ishtp_cl_init()

writes past all five arrays, corrupting subsequent struct fields

(including work_struct members with embedded function pointers)

and potentially adjacent heap objects.

Clamp hid_dev_count to MAX_HID_DEVICES at the single point where

it enters the driver (process_recv, ENUM_DEVICES branch), which

covers both the probe and the reset paths.

This is a data-validation hardening fix: the ISH firmware is

within the platform trust boundary (loaded via CSME).

This patch was drafted with AI assistance; the vulnerability

analysis and source-level verification were done manually.

Quoted 5 lines
Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")

Missing

Assisted-by AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Thanks,

Srinivas

Quoted 94 lines

---

 drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 ++

 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/hid/intel-ish-hid/ishtp-hid-client.c

index 6d64008..XXXXXXX 100644

--- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c

+++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c

(quoted diff) +0 -0
@@ -123,6 +123,8 @@ static void process_recv(struct ishtp_cl
 
 
 
 *hid_ishtp_cl, void *recv_buf,
 
 

  break;

  }

  client_data->hid_dev_count = (unsigned

int)*payload;

(quoted diff) +1 -0
+			if (client_data->hid_dev_count >

MAX_HID_DEVICES)

(quoted diff) +1 -0
+				client_data->hid_dev_count =

MAX_HID_DEVICES;

  if (!client_data->hid_devices)

  client_data->hid_devices =

devm_kcalloc(

  cl_data_to_dev(c lien

t_data),

#9 lore raw
Quoted 41 lines · On Fri, 2026-07-31 at 09:46 +0800, [email protected] wrote:
Quoted 1 line

Let me know if you want it resent as a proper [PATCH v2].

Yes with new version. Add Tested by tag also from Lixu.

Also some suggestions:

- Avoid top posting like this, you can add this part just after your

existing tags.

- If the patch is long you can trim

- I think you use outlook to reply, there are some suggestions of email

clients and other suggestions.

https://docs.kernel.org/process/email-clients.html

Also some other links:

https://people.kernel.org/tglx/notes-about-netiquette

Quoted 8 lines

https://subspace.kernel.org/etiquette.html

Thanks,

Srinivas

Thanks for your review.
Patch v3 has been posted, including the Tested-by tag from Lixu, and the email quoting format has been fixed following your recommendations.

Shen Yongchao

Tested-by
#10 lore raw
In reply to srinivas pandruvada
Quoted 11 lines

-----Original Message-----
From: srinivas pandruvada <[email protected]>
Sent: Friday, July 31, 2026 2:11 AM
To: Shen Yongchao <[email protected]>; Greg Kroah-Hartman <[email protected]>; Zhang, Lixu <[email protected]>
Cc: Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v2] HID: intel-ish-hid: clamp HID device count to MAX_HID_DEVICES

+Lixu

Code-wise, the changes look good to me.

Thanks,
Lixu

Quoted 38 lines · Shen Yongchao
Quoted 1 line

The HOSTIF_DM_ENUM_DEVICES response handler takes the HID device

count

Quoted 19 lines

from the first payload byte of the ISH firmware response (max 255) and stores it in hid_dev_count without any bounds check.  This value propagates to num_hid_devices and is used to index five fixed-size arrays in struct ishtp_cl_data (MAX_HID_DEVICES = 32): report_descr[], report_descr_size[], hid_sensor_hubs[], hid_descr[], and hid_descr_size[].

If the firmware reports more than 32 devices, hid_ishtp_cl_init() writes past all five arrays, corrupting subsequent struct fields (including work_struct members with embedded function pointers) and potentially adjacent heap objects.

Clamp hid_dev_count to MAX_HID_DEVICES at the single point where it enters the driver (process_recv, ENUM_DEVICES branch), which covers both the probe and the reset paths.

This is a data-validation hardening fix: the ISH firmware is within the platform trust boundary (loaded via CSME).

Quoted 6 lines

This patch was drafted with AI assistance; the vulnerability analysis and source-level verification were done manually.

Fixes 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")

Missing

Assisted-by AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Thanks,
Srinivas