From: Chengyu Liu <lui2012qwq@gmail.com>
To: dmitry.torokhov@gmail.com
Cc: linux-input@vger.kernel.org, Chengyu Liu <lui2012qwq@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 2/2] Input: cyapa - clamp SMBus block reads to the caller's buffer
Date: Tue, 3 Nov 2026 21:11:27 +0800 [thread overview]
Message-ID: <20261103131127.1585884-3-lui2012qwq@gmail.com> (raw)
In-Reply-To: <20261103131127.1585884-1-lui2012qwq@gmail.com>
cyapa_smbus_read_block() hands the caller's buffer straight to
i2c_smbus_read_block_data() without passing the buffer size; the i2c
core then copies the device-provided count, and any count <= 32 passes
the adapters' range checks. Both the group-read branch and the indexed
loop (on its final partial chunk) can therefore write past the caller's
buffer.
The affected callers use 27-byte stack objects:
cyapa_gen3_irq_handler() (struct cyapa_reg_data, on every touch
interrupt) and cyapa_gen3_get_query_data() (at probe). A device
reporting a count of 32 overruns them by 5 bytes, with contents
controlled by the device, in interrupt context.
Bounce through a full-size I2C_SMBUS_BLOCK_MAX buffer and clamp the
copy to the requested length in both branches.
Found by static analysis.
Fixes: 9f1cd857518f ("Input: cyapa - re-design driver to support multi-trackpad in one driver")
Cc: stable@vger.kernel.org
Signed-off-by: Chengyu Liu <lui2012qwq@gmail.com>
---
drivers/input/mouse/cyapa_gen3.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
index fc3fb95452..cd80ae51f4 100644
--- a/drivers/input/mouse/cyapa_gen3.c
+++ b/drivers/input/mouse/cyapa_gen3.c
@@ -254,20 +254,30 @@ ssize_t cyapa_smbus_read_block(struct cyapa *cyapa, u8 cmd, size_t len,
return -EINVAL;
if (SMBUS_GROUP_BLOCK_CMD_MASK & cmd) {
+ u8 tmp[I2C_SMBUS_BLOCK_MAX];
+
/* read specific block registers command. */
smbus_cmd = SMBUS_ENCODE_RW(cmd, SMBUS_READ);
- ret = i2c_smbus_read_block_data(client, smbus_cmd, values);
+ ret = i2c_smbus_read_block_data(client, smbus_cmd, tmp);
+ if (ret > 0)
+ /* never trust the device-provided count */
+ memcpy(values, tmp, min_t(size_t, ret, len));
goto out;
}
ret = 0;
for (index = 0; index * I2C_SMBUS_BLOCK_MAX < len; index++) {
+ u8 tmp[I2C_SMBUS_BLOCK_MAX];
+ size_t chunk = min_t(size_t, len - index * I2C_SMBUS_BLOCK_MAX,
+ I2C_SMBUS_BLOCK_MAX);
+
smbus_cmd = SMBUS_ENCODE_IDX(cmd, index);
smbus_cmd = SMBUS_ENCODE_RW(smbus_cmd, SMBUS_READ);
buf = values + I2C_SMBUS_BLOCK_MAX * index;
- ret = i2c_smbus_read_block_data(client, smbus_cmd, buf);
+ ret = i2c_smbus_read_block_data(client, smbus_cmd, tmp);
if (ret < 0)
goto out;
+ memcpy(buf, tmp, min_t(size_t, ret, chunk));
}
out:
--
2.25.1
next prev parent reply other threads:[~2026-11-03 13:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 13:11 [PATCH 0/2] Input: clamp SMBus block reads to the caller's buffer Chengyu Liu
2026-11-03 13:11 ` [PATCH 1/2] Input: rmi4 - clamp SMBus block reads to the requested length Chengyu Liu
2026-11-03 13:11 ` Chengyu Liu [this message]
2026-11-03 13:22 ` [PATCH 2/2] Input: cyapa - clamp SMBus block reads to the caller's buffer sashiko-bot
2026-11-03 14:10 ` cy l
2026-11-03 18:48 ` [PATCH 0/2] Input: " 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=20261103131127.1585884-3-lui2012qwq@gmail.com \
--to=lui2012qwq@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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