From: Tristan Madani <tristmd@gmail.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org,
Marcus Folkesson <marcus.folkesson@gmail.com>,
Masaki Ota <masaki.ota@jp.alps.com>,
Rahul Rameshbabu <sergeantsagara@protonmail.com>,
Johannes Roith <johannes@gnu-linux.rocks>,
"Daniel M . Lambea" <dmlambea@gmail.com>,
"Derek J . Clark" <derekjohn.clark@gmail.com>,
Zhouwang Huang <honjow311@gmail.com>,
David Barksdale <dbarksdale@uplogix.com>,
Don Prince <dhprince-devel@yahoo.co.uk>,
Clemens Ladisch <clemens@ladisch.de>,
Tristan Madani <tristan@talencesecurity.com>,
stable@vger.kernel.org
Subject: [PATCH 2/8] HID: alps: validate report size in raw_event callbacks
Date: Sun, 18 Oct 2026 21:37:47 +0000 [thread overview]
Message-ID: <20261018213754.1951187-3-tristmd@gmail.com> (raw)
In-Reply-To: <20261018213754.1951187-1-tristmd@gmail.com>
From: Tristan Madani <tristan@talencesecurity.com>
t4_raw_event() and u1_raw_event() access report data at various
offsets and cast the buffer to struct t4_input_report without
verifying that the buffer is large enough. Since hid-core invokes
raw_event before validating the report length in
hid_report_raw_event(), each driver callback must check the size
itself.
Add size validation:
- t4_raw_event: require sizeof(struct t4_input_report)
- u1_raw_event: require at least 2 bytes before the switch
- U1_ABSOLUTE_REPORT_ID: require max_fingers * 5 + 5 for the
per-finger contact array
- U1_SP_ABSOLUTE_REPORT_ID: require 6 bytes for the coordinates
Fixes: 2562756dde55 ("HID: add Alps I2C HID Touchpad-Stick support")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
drivers/hid/hid-alps.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 0556cb5645ebb..dee7d44d6f912 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -324,6 +324,10 @@ static int t4_raw_event(struct alps_dev *hdata, u8 *data, int size)
if (!data)
return 0;
+
+ if (size < sizeof(struct t4_input_report))
+ return 0;
+
for (i = 0; i < hdata->max_fingers; i++) {
x = p_report->contact[i].x_hi << 8 | p_report->contact[i].x_lo;
y = p_report->contact[i].y_hi << 8 | p_report->contact[i].y_lo;
@@ -363,6 +367,10 @@ static int u1_raw_event(struct alps_dev *hdata, u8 *data, int size)
if (!data)
return 0;
+
+ if (size < 2)
+ return 0;
+
switch (data[0]) {
case U1_MOUSE_REPORT_ID:
break;
@@ -370,6 +378,8 @@ static int u1_raw_event(struct alps_dev *hdata, u8 *data, int size)
break;
case U1_ABSOLUTE_REPORT_ID:
case U1_ABSOLUTE_REPORT_ID_SECD:
+ if (size < hdata->max_fingers * 5 + 5)
+ return 0;
for (i = 0; i < hdata->max_fingers; i++) {
u8 *contact = &data[i * 5];
@@ -407,6 +417,8 @@ static int u1_raw_event(struct alps_dev *hdata, u8 *data, int size)
return 1;
case U1_SP_ABSOLUTE_REPORT_ID:
+ if (size < 6)
+ return 0;
if (!hdata->input2)
return 0;
sp_x = get_unaligned_le16(data+2);
--
2.47.3
next prev parent reply other threads:[~2026-10-18 21:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 21:37 [PATCH 0/8] HID: validate report size in raw_event callbacks Tristan Madani
2026-10-18 21:37 ` [PATCH 1/8] HID: pxrc: validate report size in raw_event callback Tristan Madani
2026-10-18 21:37 ` Tristan Madani [this message]
2026-10-18 21:45 ` [PATCH 2/8] HID: alps: validate report size in raw_event callbacks sashiko-bot
2026-10-18 21:37 ` [PATCH 3/8] HID: mcp2200: validate report size in raw_event callback Tristan Madani
2026-10-18 21:37 ` [PATCH 4/8] HID: cougar: " Tristan Madani
2026-10-18 21:37 ` [PATCH 5/8] HID: zydacron: " Tristan Madani
2026-10-18 21:37 ` [PATCH 6/8] HID: oxp: validate report size in raw_event callbacks Tristan Madani
2026-10-18 21:48 ` sashiko-bot
2026-10-18 21:37 ` [PATCH 7/8] HID: cp2112: validate report size in raw_event callback Tristan Madani
2026-10-18 21:37 ` [PATCH 8/8] HID: prodikeys: " Tristan Madani
2026-10-18 21:44 ` sashiko-bot
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=20261018213754.1951187-3-tristmd@gmail.com \
--to=tristmd@gmail.com \
--cc=bentiss@kernel.org \
--cc=clemens@ladisch.de \
--cc=dbarksdale@uplogix.com \
--cc=derekjohn.clark@gmail.com \
--cc=dhprince-devel@yahoo.co.uk \
--cc=dmlambea@gmail.com \
--cc=honjow311@gmail.com \
--cc=jikos@kernel.org \
--cc=johannes@gnu-linux.rocks \
--cc=linux-input@vger.kernel.org \
--cc=marcus.folkesson@gmail.com \
--cc=masaki.ota@jp.alps.com \
--cc=sergeantsagara@protonmail.com \
--cc=stable@vger.kernel.org \
--cc=tristan@talencesecurity.com \
/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