Linux Input/HID development
 help / color / mirror / Atom feed
From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org
Subject: [PATCH] HID: google: check the report count in hammer_get_folded_state()
Date: Sat, 28 Nov 2026 14:03:08 +0800	[thread overview]
Message-ID: <20261128060308.4131815-1-maoyixie.tju@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-28  6:03 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=20261128060308.4131815-1-maoyixie.tju@gmail.com \
    --to=maoyixie.tju@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@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