From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] Input: cyapa - check the panel scan response against its length
Date: Wed, 18 Nov 2026 20:12:14 +0800 [thread overview]
Message-ID: <20261118121214.3571621-1-maoyixie.tju@gmail.com> (raw)
cyapa_gen5_read_panel_scan_raw_data() takes the element count and the
element size from the trackpad's response. It walks read_elements *
data_size bytes of resp_data[] without checking that length against
resp_len. A large count reads past the 256-byte buffer on the stack,
and an element size of 0 divides by zero.
Return -EINVAL when the elements do not fit in the received bytes or
the element size is 0.
Found with a CodeQL-based static analysis tool that we are developing.
Both reproduce in a userspace harness under ASan and UBSan, which
report neither with this patch. Not tested on hardware, only
compile-tested with W=1.
Fixes: 6499d390a166 ("Input: cyapa - add gen5 trackpad read baseline support")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.
I have no PIP data sheet. I assumed that the element count of a
response covers only the elements in that response.
drivers/input/mouse/cyapa_gen5.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index 59f6e97d54827de..c346f16961cc97a 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -2265,6 +2265,11 @@ static int cyapa_gen5_read_panel_scan_raw_data(struct cyapa *cyapa,
break;
data_size = (resp_data[9] & GEN5_PWC_DATA_ELEMENT_SIZE_MASK);
+ if (!data_size ||
+ read_elements * data_size >
+ resp_len - GEN5_RESP_DATA_STRUCTURE_OFFSET)
+ return -EINVAL;
+
offset += read_elements;
if (read_elements) {
for (i = GEN5_RESP_DATA_STRUCTURE_OFFSET;
base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
--
2.34.1
reply other threads:[~2026-11-18 12:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261118121214.3571621-1-maoyixie.tju@gmail.com \
--to=maoyixie.tju@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®