* [PATCH] HID: google: check the report count in hammer_get_folded_state()
@ 2026-11-28 6:03 Maoyi Xie
0 siblings, 0 replies; only message in thread
From: Maoyi Xie @ 2026-11-28 6:03 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires; +Cc: linux-input
hammer_get_folded_state() reads the folded state from the GET_REPORT
buffer at field->report_offset. A device can declare the folded field
with a Report Count of zero. Such a field takes no space in the report,
so the read can go up to four bytes past the buffer.
Skip fields with a Report Count of zero, as the HID core does.
Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under AddressSanitizer. Not tested on
hardware.
Fixes: df7b622906f2 ("HID: google: Get HID report on probe to confirm tablet switch state")
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.
drivers/hid/hid-google-hammer.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c
index 6296eb686ca9..25a600efe1ba 100644
--- a/drivers/hid/hid-google-hammer.c
+++ b/drivers/hid/hid-google-hammer.c
@@ -457,6 +457,10 @@ static void hammer_get_folded_state(struct hid_device *hdev)
for (a = 0; a < report->maxfield; a++) {
struct hid_field *field = report->field[a];
+ /* Ignore if report count is out of bounds. */
+ if (field->report_count < 1)
+ continue;
+
if (field->usage->hid == HID_USAGE_KBD_FOLDED) {
u32 value = hid_field_extract(hdev, buf+1,
field->report_offset, field->report_size);
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-28 6:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28 6:03 [PATCH] HID: google: check the report count in hammer_get_folded_state() Maoyi Xie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox