[PATCH] Input: cyapa - check the panel scan response against its length

From: Maoyi Xie

Date: Wed Nov 18 2026 - 07:13:07 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Maoyi Xie <maoyixie.tju@xxxxxxxxx>
---
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