Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Even Xu" <even.xu@intel.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 1/2] HID: Intel-thc-hid: Intel-quicki2c: Use hid_safe_input_report()
Date: Tue, 22 Sep 2026 03:03:44 +0000	[thread overview]
Message-ID: <20260922030345.531FE1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922025437.940072-2-even.xu@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid: intel-quicki2c: OOB memory access due to unadjusted buffer size in hid_safe_input_report()
--

commit fd2fb2220e67b32415f7045570713d7e64755020
Author: Even Xu <even.xu@intel.com>

HID: Intel-thc-hid: Intel-quicki2c: Use hid_safe_input_report()

This commit replaces the deprecated hid_input_report() with
hid_safe_input_report(). It tracks the allocated size of the input buffer and
passes it along to allow hid-core to validate the reported data length against
the actual buffer size.

> diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> index 0d2ad7bc3648a..6cf19dac8e181 100644
> --- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
> @@ -315,7 +315,7 @@ static int handle_input_report(struct quicki2c_device *qcdev)
>  		if (qcdev->state != QUICKI2C_ENABLED)
>  			continue;
>  
> -		quicki2c_hid_send_report(qcdev, pkt->data,
> +		quicki2c_hid_send_report(qcdev, pkt->data, qcdev->input_len,
>  					 HIDI2C_DATA_LEN(le16_to_cpu(pkt->len)));

[Severity: High]
Does this code pass the unadjusted buffer size when pkt->data is offset by 2
bytes from the start of the buffer?

The buffer qcdev->input_buf is dynamically allocated to qcdev->input_len
bytes.

Since pkt is mapped to qcdev->input_buf, pkt->data is offset by
HIDI2C_LENGTH_LEN (2 bytes) from the start of the allocation.

Passing the full qcdev->input_len overstates the remaining capacity for
pkt->data by 2 bytes.

[ ... ]

> diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
> index 8075992e8732e..1a220a50d934c 100644
> --- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
> +++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
[ ... ]
> @@ -157,16 +157,18 @@ void quicki2c_hid_remove(struct quicki2c_device *qcdev)
>   *
>   * @qcdev: point to quicki2c device
>   * @data: point to input report data buffer
> + * @buf_size: the allocated size of the input report data buffer
>   * @data_len: the length of input report data
>   *
>   * Return: 0 on success, non zero on error.
>   */
>  int quicki2c_hid_send_report(struct quicki2c_device *qcdev,
> -			     void *data, size_t data_len)
> +			     void *data, size_t buf_size, size_t data_len)
>  {
>  	int ret;
>  
> -	ret = hid_input_report(qcdev->hid_dev, HID_INPUT_REPORT, data, data_len, 1);
> +	ret = hid_safe_input_report(qcdev->hid_dev, HID_INPUT_REPORT, data,
> +				    buf_size, data_len, 1);

[Severity: High]
Can passing this unadjusted buf_size to hid_safe_input_report() lead to an
out-of-bounds access?

If a device sends a pkt->len such that HIDI2C_DATA_LEN(pkt->len) equals
qcdev->input_len, hid_safe_input_report() will trust the data length since it
does not exceed the provided buf_size.

This would neutralize the core's bounds checks, allowing the core to read or
zero-pad 2 bytes past the end of the qcdev->input_buf allocation.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922025437.940072-1-even.xu@intel.com?part=1

  reply	other threads:[~2026-09-22  3:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  2:54 [PATCH 0/2] HID: Intel-thc-hid: Use hid_safe_input_report() Even Xu
2026-09-22  2:54 ` [PATCH 1/2] HID: Intel-thc-hid: Intel-quicki2c: " Even Xu
2026-09-22  3:03   ` sashiko-bot [this message]
2026-09-22  2:54 ` [PATCH 2/2] HID: Intel-thc-hid: Intel-quickspi: " Even Xu
2026-09-22  3:05   ` sashiko-bot
2026-09-23 16:50 ` [PATCH 0/2] HID: Intel-thc-hid: " Jiri Kosina
2026-09-23 23:55   ` Xu, Even

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=20260922030345.531FE1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=even.xu@intel.com \
    --cc=linux-input@vger.kernel.org \
    --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