Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jianing Li" <m13940358460@163.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2] Input: hynitron_cstxxx: validate touch count and finger IDs
Date: Tue, 04 Aug 2026 03:21:12 +0000	[thread overview]
Message-ID: <20260804032114.46D491F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804031339.2379-1-m13940358460@163.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver passes stack-allocated buffers directly to I2C transfer functions, which violates DMA mapping rules and can cause kernel panics or data corruption.
--

--- Patch [1]: [PATCH v2] Input: hynitron_cstxxx: validate touch count and finger IDs ---
commit cf5d1ec7af0f8cb9ee23a1f75f59f7e64afb8fe7
Author: Jianing Li <m13940358460@163.com>

Input: hynitron_cstxxx: validate touch count and finger IDs

This commit adds bounds checking for the touch count and finger ID read
from the controller. It ensures that neither exceeds max_touch_num,
preventing out-of-bounds slot accesses during input reporting.

> diff --git a/drivers/input/touchscreen/hynitron_cstxxx.c b/drivers/input/touchscreen/hynitron_cstxxx.c
> index f6139b1a86811..5f2737fe99026 100644
> --- a/drivers/input/touchscreen/hynitron_cstxxx.c
> +++ b/drivers/input/touchscreen/hynitron_cstxxx.c
> @@ -312,6 +312,11 @@ static void cst3xx_touch_report(struct i2c_client *client)
>  		return;
>  
>  	touch_cnt = buf[5] & CST3XX_TOUCH_COUNT_MASK;

[Severity: High]
This is a pre-existing issue, but I noticed that buf is a stack-allocated
array in cst3xx_touch_report() that is passed to i2c_transfer() via
cst3xx_i2c_read_register() earlier in the function.

If the I2C host controller maps the buffers for DMA, passing a stack-allocated
buffer can lead to memory corruption, kernel panics, or DMA API debug warnings
because stack memory is not DMA-safe (especially with virtual kernel stacks
enabled).

Looking at the rest of drivers/input/touchscreen/hynitron_cstxxx.c, similar
stack allocations occur in other functions:

cst3xx_i2c_read_register() allocates __le16 buf
cst3xx_firmware_info() allocates unsigned char buf[4]
cst3xx_bootloader_enter() allocates unsigned char buf[3]
cst3xx_finish_touch_read() allocates unsigned char buf[3]

Should these buffers be heap-allocated or moved to a DMA-safe allocation
within the device structure to prevent DMA corruption?

> +	if (touch_cnt > ts_data->chip->max_touch_num) {
> +		dev_err(&client->dev, "cst3xx touch read failure\n");
> +		return;
> +	}
> +
>  	/*
>  	 * Check the check bit of the last touch slot. The check bit is
>  	 * always present after touch point 1 for valid data, and then
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804031339.2379-1-m13940358460@163.com?part=1

  reply	other threads:[~2026-08-04  3:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  2:03 [PATCH] Input: hynitron_cstxxx: reject out-of-range finger IDs Jianing Li
2026-08-04  2:17 ` sashiko-bot
2026-08-04  3:13 ` [PATCH v2] Input: hynitron_cstxxx: validate touch count and " Jianing Li
2026-08-04  3:21   ` sashiko-bot [this message]
2026-08-04  4:51   ` Dmitry Torokhov

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=20260804032114.46D491F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=m13940358460@163.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