All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Jiri Kosina <jikos@kernel.org>
Cc: Benjamin Tissoires <bentiss@kernel.org>,
	linux-input@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count
Date: Wed, 25 Nov 2026 17:06:33 +0800	[thread overview]
Message-ID: <20261125090633.1385386-3-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261125090633.1385386-1-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.

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


  parent reply	other threads:[~2026-11-25  9:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Maoyi Xie [this message]
2026-12-04  6:42   ` [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count Zhang Lixu

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=20261125090633.1385386-3-maoyixie.tju@gmail.com \
    --to=maoyixie.tju@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.