From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Guanglei Zhu <zhugl3@xiaopeng.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
liuc63@xiaopeng.com, stable@vger.kernel.org
Subject: Re: [PATCH] Input: cyapa_gen3 - clamp the reported finger count to the array
Date: Wed, 04 Nov 2026 12:09:43 -0800 [thread overview]
Message-ID: <14c52f5f176b8fc6aadaa31c9f4715c0@gmail.com> (raw)
In-Reply-To: <20261103084135.426629-8-zhugl3@xiaopeng.com>
Hi Guanglei,
On Tue, Nov 03, 2026 at 04:41:35PM +0800, Guanglei Zhu wrote:
> The finger count is taken from the top nibble of a status byte the
> trackpad firmware fills in, and used to walk the touch array:
>
> num_fingers = (data->finger_btn >> 4) & 0x0f;
> for (i = 0; i < num_fingers; i++) {
> const struct cyapa_touch *touch = &data->touches[i];
>
> The nibble allows up to fifteen fingers, but the array holds the
> five touches the chip is documented to report, so a firmware that
> counts beyond that makes the driver report coordinates read from
> the stack past the register block.
>
> Clamp the finger count to the size of the array.
>
> Fixes: 9f1cd857518f ("Input: cyapa - re-design driver to support multi-trackpad in one driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
> ---
> drivers/input/mouse/cyapa_gen3.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
> index fc3fb954523b..fda807a4c141 100644
> --- a/drivers/input/mouse/cyapa_gen3.c
> +++ b/drivers/input/mouse/cyapa_gen3.c
> @@ -1149,7 +1149,8 @@ static int cyapa_gen3_event_process(struct cyapa *cyapa,
> int num_fingers;
> int i;
>
> - num_fingers = (data->finger_btn >> 4) & 0x0f;
> + num_fingers = min((data->finger_btn >> 4) & 0x0f,
> + ARRAY_SIZE(data->touches));
> for (i = 0; i < num_fingers; i++) {
> const struct cyapa_touch *touch = &data->touches[i];
> /* Note: touch->id range is 1 to 15; slots are 0 to 14. */
If the packet reports more than 5 fingers (for example, if an I2C read
glitches and returns 0xff bytes, which would otherwise pass the bit
checks for OP_STATUS_SRC, CYAPA_DEV_NORMAL, and OP_DATA_VALID), the
packet is corrupted and we should not clamp the count and report 5 bogus
touches to userspace.
Instead, please reject packets reporting more than GEN3_MAX_FINGERS
with -EINVAL during the header validation in cyapa_gen3_irq_handler()
and cyapa_gen3_try_poll_handler() (or in cyapa_gen3_event_process()),
so the driver treats it as an invalid state and reinitializes the
device. While at it, please also use GEN3_MAX_FINGERS to size
data->touches[] in struct cyapa_reg_data, and either fix
GEN3_FINGER_NUM() to mask with 0x0f and use it, or drop the unused
macro.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-11-04 20:09 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:41 [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: joydev - avoid signed overflow in the broken-axis correction Guanglei Zhu
2026-11-03 8:48 ` sashiko-bot
2026-11-03 8:55 ` [PATCH v2] " Guanglei Zhu
2026-11-04 3:38 ` Dmitry Torokhov
2026-11-04 5:50 ` [PATCH v3] " Guanglei Zhu
2026-11-04 6:02 ` Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: adi - bound the two-stream packet merge Guanglei Zhu
2026-11-03 8:55 ` sashiko-bot
2026-11-03 11:17 ` [PATCH v2] " Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: db9 - enlarge the Saturn multitap packet buffer Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: lpc32xx-keys - reject matrices bigger than the hardware has Guanglei Zhu
2026-11-03 18:54 ` Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
2026-11-04 6:25 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: mt6779-keypad - check the reported row and column Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: tegra-kbc - check the pin numbers from the device tree Guanglei Zhu
2026-11-04 17:08 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: cyapa_gen3 - clamp the reported finger count to the array Guanglei Zhu
2026-11-04 20:09 ` Dmitry Torokhov [this message]
2026-11-03 18:45 ` [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
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=14c52f5f176b8fc6aadaa31c9f4715c0@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuc63@xiaopeng.com \
--cc=stable@vger.kernel.org \
--cc=zhugl3@xiaopeng.com \
/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