mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiale Yao <yaojiale02@163.com>
To: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	Masaki Ota <masaki.ota@jp.alps.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jiale Yao <yaojiale02@163.com>, stable@vger.kernel.org
Subject: [PATCH 01/10] HID: alps: reject short input reports
Date: Thu, 24 Sep 2026 22:44:04 +0800	[thread overview]
Message-ID: <20260924144414.1192037-2-yaojiale02@163.com> (raw)
In-Reply-To: <20260924144414.1192037-1-yaojiale02@163.com>

The HID core invokes a driver's raw_event callback before validating the
report length.  Both ALPS input parsers therefore need to validate size
before accessing their fixed-format reports.

t4_raw_event() casts the buffer to struct t4_input_report and reads its
contacts and button.  u1_raw_event() reads five bytes per configured finger
starting at offset three, or six bytes for a stick report.  A short report
can make either parser read beyond the valid data.

Reject reports that do not contain all fields used by the selected parser.

Commit 47669bec44fe ("HID: asus: refactor the two workqueues and init
sequence") added the same kind of raw_event length validation to hid-asus.

Fixes: 2562756dde55 ("HID: add Alps I2C HID Touchpad-Stick support")
Fixes: 73196ebe134d ("HID: alps: add support for Alps T4 Touchpad device")
Cc: stable@vger.kernel.org
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/hid/hid-alps.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-alps.c b/drivers/hid/hid-alps.c
index 67179e3fe39b..b1950aff6ad4 100644
--- a/drivers/hid/hid-alps.c
+++ b/drivers/hid/hid-alps.c
@@ -322,7 +322,7 @@ static int t4_raw_event(struct alps_dev *hdata, u8 *data, int size)
 	int i;
 	struct t4_input_report *p_report = (struct t4_input_report *)data;
 
-	if (!data)
+	if (size < sizeof(*p_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;
@@ -370,6 +370,9 @@ 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 < 3 + hdata->max_fingers * 5)
+			return 0;
+
 		for (i = 0; i < hdata->max_fingers; i++) {
 			u8 *contact = &data[i * 5];
 
@@ -407,6 +410,9 @@ 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;
+
 		sp_x = get_unaligned_le16(data+2);
 		sp_y = get_unaligned_le16(data+4);
 
-- 
2.34.1


  reply	other threads:[~2026-09-24 14:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 14:44 [PATCH 00/10] HID: validate short reports in raw_event callbacks Jiale Yao
2026-09-24 14:44 ` Jiale Yao [this message]
2026-09-24 14:44 ` [PATCH 02/10] HID: cougar: reject short special-key reports Jiale Yao
2026-09-24 14:44 ` [PATCH 03/10] HID: cp2112: validate response report lengths Jiale Yao
2026-09-24 14:44 ` [PATCH 04/10] HID: elo: reject short touchscreen reports Jiale Yao
2026-09-24 14:44 ` [PATCH 05/10] HID: logitech-dj: validate unnumbered keyboard reports Jiale Yao
2026-09-24 14:44 ` [PATCH 06/10] HID: mcp2200: validate READ_ALL response length Jiale Yao
2026-09-24 14:44 ` [PATCH 07/10] HID: mcp2221: validate response report length Jiale Yao
2026-09-24 14:44 ` [PATCH 08/10] HID: prodikeys: validate fixed-format MIDI reports Jiale Yao
2026-09-24 14:44 ` [PATCH 09/10] HID: pxrc: reject short input reports Jiale Yao
2026-09-24 14:44 ` [PATCH 10/10] HID: zydacron: validate key report length Jiale Yao
  -- strict thread matches above, loose matches on Subject: below --
2026-09-24 14:13 [PATCH 00/10] HID: validate short reports in raw_event callbacks Jiale Yao
2026-09-24 14:13 ` [PATCH 01/10] HID: alps: reject short input reports Jiale Yao

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=20260924144414.1192037-2-yaojiale02@163.com \
    --to=yaojiale02@163.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masaki.ota@jp.alps.com \
    --cc=stable@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

all inboxes | Powered by JetHome®