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