From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Nick Dyer <nick@shmanahar.org>
Cc: Pengpeng <pengpeng@iscas.ac.cn>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Input: atmel_mxt_ts - validate firmware frame bounds
Date: Mon, 6 Jul 2026 17:11:44 +0800 [thread overview]
Message-ID: <20260706091144.76132-1-pengpeng@iscas.ac.cn> (raw)
From: Pengpeng <pengpeng@iscas.ac.cn>
mxt_flash_fw() walks a length-prefixed firmware image. The loop only
checks that the cursor is below fw->size before reading the two-byte
frame length and passing the declared frame to the bootloader write path.
Check that the length field and the complete frame, including CRC bytes,
fit in the remaining firmware image before reading or writing the frame.
Signed-off-by: Pengpeng <pengpeng@iscas.ac.cn>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 2c0e5a67135b..2aa52b4e5ff5 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -2927,10 +2927,19 @@ static int mxt_flash_fw(struct mxt_data *data, const struct firmware *fw)
if (error)
return error;
+ if (fw->size - pos < 2) {
+ dev_err(dev, "Truncated frame size in firmware\n");
+ return -EINVAL;
+ }
+
frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
/* Take account of CRC bytes */
frame_size += 2;
+ if (frame_size > fw->size - pos) {
+ dev_err(dev, "Truncated frame in firmware\n");
+ return -EINVAL;
+ }
/* Write one frame to device */
error = mxt_bootloader_write(data, fw->data + pos, frame_size);
--
2.43.0
next reply other threads:[~2026-07-06 9:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 9:11 Pengpeng Hou [this message]
2026-07-06 9:24 ` [PATCH] Input: atmel_mxt_ts - validate firmware frame bounds sashiko-bot
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=20260706091144.76132-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nick@shmanahar.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