Linux Input/HID development
 help / color / mirror / Atom feed
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 1/2] HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response
Date: Mon, 23 Nov 2026 09:42:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-228999@kernel.org> (raw)
In-Reply-To: <20261123092816.2200718-2-maoyixie.tju@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: intel-ish-hid: UAF race in process_recv() on duplicate
  report descriptor
--

commit 024e9922cb6a61e316edcda24a29fa99a9eae537
Author: Maoyi Xie <maoyixie.tju@gmail.com>

HID: intel-ish-hid: Reallocate the descriptor buffers for a longer response

This commit replaces the one-time devm_kmalloc() calls for hid_descr[i]
and report_descr[i] in process_recv() with devm_krealloc() so each buffer
is resized to the received payload length before copying.

> diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> index ec5e8afe77bd4..24f4032d6dfe1 100644
> --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c
> +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c
[ ... ]
> @@ -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);

[Severity: Medium]
Can a second HOSTIF_GET_REPORT_DESCRIPTOR response cause a use-after-free
on client_data->report_descr[curr_hid_dev] in ishtp_hid_parse()?

During initial probe, hid_ishtp_cl_init() wakes up as soon as the first
response sets report_descr_done and immediately calls ishtp_hid_probe()
while cur_hid_dev is still i and init_done is still false.  If a second,
longer (or zero-length) response arrives before cur_hid_dev advances,
devm_krealloc() frees the old buffer while hid_parse_report() is reading
it:

CPU0 (probe)                      CPU1 (unbound_wq)
hid_ishtp_cl_init()
  ishtp_get_report_descriptor()
                                  process_recv()
                                    report_descr[i] = descr
                                    report_descr_done = true
                                    wake_up_interruptible(&init_wait)
  ishtp_hid_probe()
    ...
      ishtp_hid_parse()
        hid_parse_report(...,
          report_descr[i], ...)
                                  process_recv()
                                    devm_krealloc(..., report_descr[i], ...)
                                      free_dr(old_dr)
          kmemdup(start, size, ...)  <-- use-after-free

Ignoring or rejecting duplicate responses when report_descr_done (and
hid_descr_done for HOSTIF_GET_HID_DESCRIPTOR) is already true would avoid
reallocating the buffer while the waiter is using it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123092816.2200718-1-maoyixie.tju@gmail.com?part=1

  reply	other threads:[~2026-11-23  9:42 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 [this message]
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=sashiko-outbox-228999@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox