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 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response
Date: Mon, 23 Nov 2026 17:28:15 +0800	[thread overview]
Message-ID: <20261123092816.2200718-2-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261123092816.2200718-1-maoyixie.tju@gmail.com>

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. After an empty
first response, the next copy writes at ZERO_SIZE_PTR.

Size the buffer to the received length with devm_krealloc() before the
copy.

Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under AddressSanitizer, which reports
none of these writes with this patch. Not tested on hardware, only
compile-tested with W=1 on hid.git for-7.4/upstream-fixes.

Fixes: 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <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 | 21 ++++++++++----------
 1 file changed, 11 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..24f4032d6dfe 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,11 @@ 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]) {
+			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 +198,11 @@ 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])  {
+			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


  reply	other threads:[~2026-11-23  9:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  9:28 [PATCH 0/2] HID: intel-ish-hid: Reallocate buffers for a later, larger response Maoyi Xie
2026-11-23  9:28 ` Maoyi Xie [this message]
2026-11-23  9:42   ` [PATCH 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response sashiko-bot
2026-11-23  9:28 ` [PATCH 2/2] HID: intel-ish-hid: Reallocate hid_devices for a larger device count Maoyi Xie
2026-11-23  9:50   ` sashiko-bot

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=20261123092816.2200718-2-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.