* [PATCH v2 0/2] HID: intel-ish-hid: Size the buffers for a later, larger response
@ 2026-11-25 9:06 Maoyi Xie
2026-11-25 9:06 ` [PATCH v2 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response Maoyi Xie
2026-11-25 9:06 ` [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count Maoyi Xie
0 siblings, 2 replies; 6+ messages in thread
From: Maoyi Xie @ 2026-11-25 9:06 UTC (permalink / raw)
To: Srinivas Pandruvada, Jiri Kosina; +Cc: Benjamin Tissoires, linux-input, stable
Both patches fix buffers in process_recv() that are allocated for the
first firmware response and then reused for later, larger ones.
A pending patch [1] limits hid_dev_count to MAX_HID_DEVICES, and it is
still needed with this series. Patch 2 does not depend on [1], so it
allocates U8_MAX entries (2295 bytes). With [1] applied first,
MAX_HID_DEVICES entries would be enough.
The series is based on hid.git for-7.4/upstream-fixes. In mainline,
patch 2 conflicts with the treewide devm_kmalloc_obj() conversion
(4dd10fbbeb9c). I can send a version for mainline if you prefer.
I used an LLM to help write the harness and these patches.
Changes in v2:
- Patch 1 ignores a response whose done flag is already set.
- Patch 2 allocates hid_devices once for the largest count and does
not reallocate it. The subject of patch 2 and of this letter changed
with that.
- Both changes follow the Sashiko review of v1.
- v1: https://lore.kernel.org/linux-input/20261123092816.2200718-1-maoyixie.tju@gmail.com/
[1] https://lore.kernel.org/all/tencent_130404E5ABECE66E8D0E70D8E6892C751C0A@qq.com/
Maoyi Xie (2):
HID: intel-ish-hid: Reallocate the descriptor buffers for a longer
response
HID: intel-ish-hid: Allocate hid_devices for the largest device count
drivers/hid/intel-ish-hid/ishtp-hid-client.c | 27 ++++++++++++--------
1 file changed, 16 insertions(+), 11 deletions(-)
base-commit: 10bc1d627c297097cfdc099377f8a13efdfffd86
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response 2026-11-25 9:06 [PATCH v2 0/2] HID: intel-ish-hid: Size the buffers for a later, larger response Maoyi Xie @ 2026-11-25 9:06 ` Maoyi Xie 2026-12-04 5:52 ` Zhang Lixu 2026-11-25 9:06 ` [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count Maoyi Xie 1 sibling, 1 reply; 6+ messages in thread From: Maoyi Xie @ 2026-11-25 9:06 UTC (permalink / raw) To: Srinivas Pandruvada, Jiri Kosina; +Cc: Benjamin Tissoires, linux-input, stable 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> --- v2: - Ignore a response whose done flag is already set (Sashiko review). - Shorten the commit message. v1: https://lore.kernel.org/linux-input/20261123092816.2200718-2-maoyixie.tju@gmail.com/ 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 ec5e8afe77bd..d1eccdc37e7a 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; @@ -172,11 +173,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] = @@ -197,11 +200,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] 6+ messages in thread
* Re: [PATCH v2 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response 2026-11-25 9:06 ` [PATCH v2 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response Maoyi Xie @ 2026-12-04 5:52 ` Zhang Lixu 2026-12-04 19:02 ` Srinivas Pandruvada 0 siblings, 1 reply; 6+ messages in thread From: Zhang Lixu @ 2026-12-04 5:52 UTC (permalink / raw) To: Maoyi Xie Cc: Srinivas Pandruvada, Jiri Kosina, Benjamin Tissoires, linux-input On Wed, Nov 25, 2026 at 05:06:32PM +0800, Maoyi Xie wrote: > 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> Looks good to me. Tested on Intel PTL ISH hardware across repeated firmware resets, module reload. Reviewed-by: Zhang Lixu <lixu.zhang@intel.com> Tested-by: Zhang Lixu <lixu.zhang@intel.com> > --- > v2: > - Ignore a response whose done flag is already set (Sashiko review). > - Shorten the commit message. > v1: https://lore.kernel.org/linux-input/20261123092816.2200718-2-maoyixie.tju@gmail.com/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response 2026-12-04 5:52 ` Zhang Lixu @ 2026-12-04 19:02 ` Srinivas Pandruvada 0 siblings, 0 replies; 6+ messages in thread From: Srinivas Pandruvada @ 2026-12-04 19:02 UTC (permalink / raw) To: Zhang Lixu, Maoyi Xie; +Cc: Jiri Kosina, Benjamin Tissoires, linux-input On Fri, 2026-12-04 at 13:52 +0800, Zhang Lixu wrote: > On Wed, Nov 25, 2026 at 05:06:32PM +0800, Maoyi Xie wrote: > > 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> > > Looks good to me. Tested on Intel PTL ISH hardware across repeated > firmware resets, module reload. > > 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> > > --- > > v2: > > - Ignore a response whose done flag is already set (Sashiko > > review). > > - Shorten the commit message. > > v1: > > https://lore.kernel.org/linux-input/20261123092816.2200718-2-maoyixie.tju@gmail.com/ ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count 2026-11-25 9:06 [PATCH v2 0/2] HID: intel-ish-hid: Size the buffers for a later, larger response Maoyi Xie 2026-11-25 9:06 ` [PATCH v2 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response Maoyi Xie @ 2026-11-25 9:06 ` Maoyi Xie 2026-12-04 6:42 ` Zhang Lixu 1 sibling, 1 reply; 6+ messages in thread From: Maoyi Xie @ 2026-11-25 9:06 UTC (permalink / raw) To: Srinivas Pandruvada, Jiri Kosina; +Cc: Benjamin Tissoires, linux-input, stable 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. The count is one byte. Allocate the array once for U8_MAX entries. 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> --- v2: - Allocate the array once for the largest count and do not reallocate it (Sashiko review). - The subject changed with that. - Shorten the commit message. v1: https://lore.kernel.org/linux-input/20261123092816.2200718-3-maoyixie.tju@gmail.com/ 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 d1eccdc37e7a..0837af243904 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_kcalloc( cl_data_to_dev(client_data), - client_data->hid_dev_count, + U8_MAX, sizeof(struct device_info), GFP_KERNEL); if (!client_data->hid_devices) { -- 2.34.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count 2026-11-25 9:06 ` [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count Maoyi Xie @ 2026-12-04 6:42 ` Zhang Lixu 0 siblings, 0 replies; 6+ messages in thread From: Zhang Lixu @ 2026-12-04 6:42 UTC (permalink / raw) To: Maoyi Xie Cc: Srinivas Pandruvada, Jiri Kosina, Benjamin Tissoires, linux-input On Wed, Nov 25, 2026 at 05:06:33PM +0800, Maoyi Xie wrote: > 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. > > The count is one byte. Allocate the array once for U8_MAX entries. 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> > --- > v2: > - Allocate the array once for the largest count and do not reallocate > it (Sashiko review). > - The subject changed with that. > - Shorten the commit message. > v1: https://lore.kernel.org/linux-input/20261123092816.2200718-3-maoyixie.tju@gmail.com/ > > 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 d1eccdc37e7a..0837af243904 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_kcalloc( > cl_data_to_dev(client_data), > - client_data->hid_dev_count, > + U8_MAX, Personally, I'd prefer MAX_HID_DEVICES over U8_MAX here, even without [1]. hid_devices[] is indexed 1:1 with report_descr[], hid_descr[], and hid_sensor_hubs[] in struct ishtp_cl_data, all of which are sized to MAX_HID_DEVICES, and ISH firmware keeps the enumerated count within MAX_HID_DEVICES as well. Thanks, Lixu > sizeof(struct device_info), > GFP_KERNEL); > if (!client_data->hid_devices) { > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-04 19:03 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-25 9:06 [PATCH v2 0/2] HID: intel-ish-hid: Size the buffers for a later, larger response Maoyi Xie 2026-11-25 9:06 ` [PATCH v2 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response Maoyi Xie 2026-12-04 5:52 ` Zhang Lixu 2026-12-04 19:02 ` Srinivas Pandruvada 2026-11-25 9:06 ` [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count Maoyi Xie 2026-12-04 6:42 ` Zhang Lixu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox