From: sashiko-bot@kernel.org
To: "Linkai Gong" <gonglinkai@kylinos.cn>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH] Input: cyapa - cap the PIP report length before the I2C read
Date: Thu, 03 Sep 2026 08:05:18 +0000 [thread overview]
Message-ID: <20260903080518.C9FE41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260903075026.1069672-1-gonglinkai@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the driver processes up to `touch_num` touch records from `report_data.touch_records` without verifying that the `report_len` read from the I2C device is actually large enough to contain them. If `report_len` is smaller than required but `touch_num` is non-zero, it reads uninitialized kernel stack memory and reports it to userspace as input events.
--
commit a3170cabcda3be9e64d6692bbb6c52bf82b02d07
Author: Linkai Gong <gonglinkai@kylinos.cn>
Input: cyapa - cap the PIP report length before the I2C read
This commit fixes an issue where the PIP report length could exceed the
size of the receiving buffer. It clamps the report length to the size of the
report_data structure and bounds the number of touch records.
> diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
> index 59f6e97d54827..0c8bc37ab3fd4 100644
> --- a/drivers/input/mouse/cyapa_gen5.c
> +++ b/drivers/input/mouse/cyapa_gen5.c
> @@ -2753,6 +2753,8 @@ static void cyapa_pip_report_touches(struct cyapa *cyapa,
>
> touch_num = report_data->report_head[PIP_NUMBER_OF_TOUCH_OFFSET] &
> PIP_NUMBER_OF_TOUCH_MASK;
> + if (touch_num > ARRAY_SIZE(report_data->touch_records))
> + touch_num = ARRAY_SIZE(report_data->touch_records);
>
> for (i = 0; i < touch_num; i++)
> cyapa_pip_report_slot_data(cyapa,
> &report_data->touch_records[i]);
[Severity: High]
This isn't a bug introduced by this patch, but does this loop potentially
process uninitialized stack memory?
If a malfunctioning or malicious I2C device provides a small report_len
(e.g., 7 bytes) but a non-zero touch_num in the header, the loop iterates
up to touch_num times.
Because cyapa_pip_irq_handler() allocates an uninitialized stack buffer
for report_data and only reads report_len bytes into it:
int cyapa_pip_irq_handler(struct cyapa *cyapa)
{
struct cyapa_pip_report_data report_data;
[ ... ]
ret = cyapa_i2c_pip_read(cyapa, (u8 *)&report_data, report_len);
}
This leaves the remainder of the touch_records array uninitialized.
Processing these records here could leak uninitialized kernel stack memory
and cause erratic phantom input events to be reported to userspace.
Should there be an additional check to verify that report_len is actually
large enough to contain touch_num records?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260903075026.1069672-1-gonglinkai@kylinos.cn?part=1
prev parent reply other threads:[~2026-09-03 8:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 7:50 [PATCH] Input: cyapa - cap the PIP report length before the I2C read Linkai Gong
2026-09-03 8:05 ` 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=20260903080518.C9FE41F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=gonglinkai@kylinos.cn \
--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