From: Maoyi Xie via B4 Relay <devnull+maoyixie.tju.gmail.com@kernel.org>
To: Jiri Kosina <jikos@kernel.org>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Maoyi Xie <maoyixie.tju@gmail.com>,
linux-input@vger.kernel.org,
Benjamin Tissoires <bentiss@kernel.org>,
Zhang Lixu <lixu.zhang@intel.com>
Subject: [PATCH v3 2/2] HID: intel-ish-hid: Allocate hid_devices for MAX_HID_DEVICES entries
Date: Sun, 06 Dec 2026 00:07:04 +0800 [thread overview]
Message-ID: <20261206-ishtp-hid-buffers-v3-2-1dff00637cb7@gmail.com> (raw)
In-Reply-To: <20261206-ishtp-hid-buffers-v3-0-1dff00637cb7@gmail.com>
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
prev parent reply other threads:[~2026-12-05 16:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20261206-ishtp-hid-buffers-v3-2-1dff00637cb7@gmail.com \
--to=devnull+maoyixie.tju.gmail.com@kernel.org \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=maoyixie.tju@gmail.com \
--cc=srinivas.pandruvada@linux.intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox