From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Dudley Du <dudl@cypress.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 02/10] Input: cyapa - validate firmware image size in cyapa_pip_check_fw()
Date: Mon, 23 Nov 2026 18:31:08 +0000 [thread overview]
Message-ID: <20261123183200.3900004-3-lee@kernel.org> (raw)
In-Reply-To: <20261123183200.3900004-1-lee@kernel.org>
cyapa_pip_check_fw() parses the firmware header, the trailing
application integrity record, and the application rows without verifying
that the supplied firmware buffer is large enough to hold them.
A truncated firmware image smaller than struct cyapa_tsg_bin_image_head
causes an out-of-bounds read in cyapa_pip_fw_head_check() and can
underflow the unsigned size subtraction in
cyapa_get_image_record_data_num(). An image containing a valid header
but zero complete flash records causes image_records[flash_records_count
- 1] to read before the start of fw->data. Finally, an image whose
metadata specifies an app_len exceeding the available application
records reads past the end of fw->data while computing app_crc.
Validate the header size, ensure at least one flash record is present,
and bound the application row count against the non-integrity record
count before dereferencing image_records.
Fixes: 5812d3067294 ("Input: cyapa - add gen5 trackpad firmware update support")
Closes: https://sashiko.dev/#/bug/linux-cc76de59-950f-4e64-b49e-7605164e02a9
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/input/mouse/cyapa_gen5.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index 59f6e97d5482..bce8104f4149 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -1249,6 +1249,11 @@ int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw)
u16 app_integrity_crc;
int i;
+ if (fw->size < sizeof(struct cyapa_tsg_bin_image_head)) {
+ dev_err(dev, "%s: firmware image is too small.\n", __func__);
+ return -EINVAL;
+ }
+
/* Verify the firmware image not miss-used for Gen5 and Gen6. */
if (cyapa_pip_fw_head_check(cyapa,
(struct cyapa_tsg_bin_image_head *)fw->data)) {
@@ -1259,6 +1264,11 @@ int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw)
image_records =
cyapa_get_image_record_data_num(fw, &flash_records_count);
+ if (flash_records_count <= 0) {
+ dev_err(dev, "%s: firmware image has no flash records.\n",
+ __func__);
+ return -EINVAL;
+ }
/*
* APP_INTEGRITY row is always the last row block,
@@ -1295,6 +1305,11 @@ int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw)
return -EINVAL;
}
+ if (fw_app_len / CYAPA_TSG_FW_ROW_SIZE > flash_records_count - 1) {
+ dev_err(dev, "%s: invalid firmware app length.\n", __func__);
+ return -EINVAL;
+ }
+
/* Verify application image CRC. */
app_crc = 0xffffU;
for (i = 0; i < fw_app_len / CYAPA_TSG_FW_ROW_SIZE; i++) {
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 18:32 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 18:31 [PATCH 00/10] Input: assorted bug fixes across input drivers Lee Jones
2026-11-23 18:31 ` [PATCH 01/10] Input: matrix_keypad - validate GPIO counts against matrix limits Lee Jones
2026-11-23 20:12 ` Dmitry Torokhov
2026-11-23 18:31 ` Lee Jones [this message]
2026-11-23 23:33 ` [PATCH 02/10] Input: cyapa - validate firmware image size in cyapa_pip_check_fw() Dmitry Torokhov
2026-11-23 18:31 ` [PATCH 03/10] Input: applespi - cancel touchpad registration work on removal Lee Jones
2026-11-23 20:13 ` Dmitry Torokhov
2026-11-23 18:31 ` [PATCH 04/10] Input: matrix_keypad - only stop and start active device across sleep Lee Jones
2026-11-23 18:42 ` sashiko-bot
2026-11-23 18:31 ` [PATCH 05/10] Input: stinger - zero-initialise driver state in stinger_connect() Lee Jones
2026-11-23 20:19 ` Dmitry Torokhov
2026-11-23 18:31 ` [PATCH 06/10] Input: synaptics-rmi4 - check for NULL drvdata in rmi_set_attn_data() Lee Jones
2026-11-24 4:33 ` Dmitry Torokhov
2026-11-23 18:31 ` [PATCH 07/10] Input: axp20x-pek - skip IRQ handling during sleep without input device Lee Jones
2026-11-23 20:22 ` Dmitry Torokhov
2026-11-23 18:31 ` [PATCH 08/10] Input: mt6779-keypad - enable keypad clock before programming registers Lee Jones
2026-11-23 20:25 ` Dmitry Torokhov
2026-11-23 18:31 ` [PATCH 09/10] Input: pinephone-keyboard - request IRQ before registering input device Lee Jones
2026-11-23 20:25 ` Dmitry Torokhov
2026-11-23 18:31 ` [PATCH 10/10] Input: wacom_w8001 - use reinit_completion() in w8001_command() Lee Jones
2026-11-23 20:26 ` 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=20261123183200.3900004-3-lee@kernel.org \
--to=lee@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=dudl@cypress.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sakari.ailus@linux.intel.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.