Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tristan Madani" <tristmd@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 2/8] HID: alps: validate report size in raw_event callbacks
Date: Sun, 18 Oct 2026 21:45:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-176412@kernel.org> (raw)
In-Reply-To: <20261018213754.1951187-3-tristmd@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] HID: alps: off-by-two report size check in u1_raw_event()
--

commit 5284d6e143901f92388237eea63f898c2ce83a7f
Author: Tristan Madani <tristan@talencesecurity.com>

HID: alps: validate report size in raw_event callbacks

This commit adds report buffer size validation to t4_raw_event() and
u1_raw_event() before accessing report fields.

> 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
[ ... ]
> @@ -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];

[Severity: Medium]
Does this check in u1_raw_event() reject valid 28-byte 5-finger touchpad
reports when receiving U1_ABSOLUTE_REPORT_ID or U1_ABSOLUTE_REPORT_ID_SECD?

Inside the loop, contact is set to &data[i * 5] and the code reads:

	for (i = 0; i < hdata->max_fingers; i++) {
		u8 *contact = &data[i * 5];

		x = get_unaligned_le16(contact + 3);
		y = get_unaligned_le16(contact + 5);
		z = contact[7] & 0x7F;

The report has a 3-byte header (data[0] report ID, data[1] buttons, data[2]
finger count) followed by hdata->max_fingers 5-byte contact entries starting
at data[3]. On the final iteration (i = hdata->max_fingers - 1), the last
byte accessed is contact[7], which is at index:

	(hdata->max_fingers - 1) * 5 + 7 = hdata->max_fingers * 5 + 2

For a 5-finger touchpad (hdata->max_fingers == 5), the last byte is data[27]
(matching the Packet Format table in Documentation/hid/hid-alps.rst), so the
report is 28 bytes long. Requiring hdata->max_fingers * 5 + 5 demands 30
bytes. Should the bound be hdata->max_fingers * 5 + 3 instead?

[ ... ]

>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261018213754.1951187-1-tristmd@gmail.com?part=2

  reply	other threads:[~2026-10-18 21:45 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 ` [PATCH 2/8] HID: alps: validate report size in raw_event callbacks Tristan Madani
2026-10-18 21:45   ` sashiko-bot [this message]
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=sashiko-outbox-176412@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tristmd@gmail.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