From: sashiko-bot@kernel.org
To: "Maoyi Xie" <maoyixie.tju@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 2/2] HID: intel-ish-hid: Reallocate hid_devices for a larger device count
Date: Mon, 23 Nov 2026 09:50:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-229009@kernel.org> (raw)
In-Reply-To: <20261123092816.2200718-3-maoyixie.tju@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: intel-ish-hid: use-after-free in process_recv() on
hid_devices realloc
--
commit 354365a28c1b9e56e376d6cd317766efa118e7ec
Author: Maoyi Xie <maoyixie.tju@gmail.com>
HID: intel-ish-hid: Reallocate hid_devices for a larger device count
This commit uses devm_krealloc_array() in process_recv() to resize
client_data->hid_devices when a HOSTIF_DM_ENUM_DEVICES response announces
more devices than previously allocated.
> diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> index 24f4032d6dfe1..864a06a7bd3ff 100644
> --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> @@ -70,6 +70,8 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
> unsigned char *payload;
> unsigned char *descr;
> struct device_info *dev_info;
> + struct device_info *devices;
> + unsigned int count;
> int i, j;
> size_t payload_len, total_len, cur_pos, raw_len, msg_len;
> int report_type;
> @@ -124,19 +126,21 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf,
> }
> if (client_data->init_done)
> break;
> - client_data->hid_dev_count = (unsigned int)*payload;
> - if (!client_data->hid_devices)
> - client_data->hid_devices = devm_kcalloc(
> - cl_data_to_dev(client_data),
> - client_data->hid_dev_count,
> - sizeof(struct device_info),
> - GFP_KERNEL);
> - if (!client_data->hid_devices) {
> + count = *payload;
> + devices = client_data->hid_devices;
> + if (count || !devices)
> + devices = devm_krealloc_array(cl_data_to_dev(client_data),
> + devices, count,
> + sizeof(struct device_info),
> + GFP_KERNEL | __GFP_ZERO);
> + if (!devices) {
> dev_err(cl_data_to_dev(client_data),
> "Mem alloc failed for hid device info\n");
> wake_up_interruptible(&client_data->init_wait);
> break;
> }
> + client_data->hid_devices = devices;
> + client_data->hid_dev_count = count;
[Severity: Medium]
Can reallocating client_data->hid_devices on a second
HOSTIF_DM_ENUM_DEVICES response cause a use-after-free in
hid_ishtp_cl_init()?
After the first response sets client_data->enum_devices_done and wakes
client_data->init_wait, hid_ishtp_cl_init() proceeds to read
client_data->hid_devices[] across descriptor queries and
ishtp_hid_probe() while client_data->init_done is still false:
CPU0 CPU1
hid_ishtp_cl_init() process_recv()
ishtp_enum_enum_devices()
case HOSTIF_DM_ENUM_DEVICES:
devm_krealloc_array(...)
enum_devices_done = true
wake_up_interruptible(...)
for (i = 0; i < num_hid_devices; ++i)
ishtp_get_hid_descriptor(i)
case HOSTIF_DM_ENUM_DEVICES:
devm_krealloc_array(...)
/* frees old hid_devices */
client_data->hid_devices[i].dev_id <-- use-after-free
client_data->init_done = 1
Because HOSTIF_DM_ENUM_DEVICES only checks client_data->init_done and not
client_data->enum_devices_done, a second response with a larger count
frees the old client_data->hid_devices buffer without synchronization
while hid_ishtp_cl_init() is still iterating over it.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123092816.2200718-1-maoyixie.tju@gmail.com?part=2
prev parent reply other threads:[~2026-11-23 9:50 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 ` [PATCH 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response Maoyi Xie
2026-11-23 9:42 ` 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 [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=sashiko-outbox-229009@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=maoyixie.tju@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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.