Input: cyapa - check the panel scan response against its length
Subsystems (3)
PATCH 1/1 Input: cyapa - check the panel scan response against its length
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.
---
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(+)
drivers/input/mouse/cyapa_gen5.c +5 -0
@@ -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
Signature · 1 line
2.34.1