From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org
Subject: [PATCH] Input: usbtouchscreen - check received length when completing a packet
Date: Mon, 30 Nov 2026 20:06:40 +0800 [thread overview]
Message-ID: <20261130120640.2437520-1-maoyixie.tju@gmail.com> (raw)
usbtouch_process_multi() completes a buffered packet with
pkt_len - buf_len bytes of the next transfer. It does not check that
count against the received length. A short transfer makes it copy stale
bytes. With a small wMaxPacketSize it reads up to 12 bytes past the URB
buffer. For a touch packet up to four such bytes end up in the reported
coordinates.
If the rest has not arrived, append what was received and wait for the
next transfer.
Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under AddressSanitizer. Not tested on
hardware.
Fixes: 1d3e20236d7a ("[PATCH] USB: usbtouchscreen: unified USB touchscreen driver")
Fixes: 4ef38351d770 ("Input: usbtouchscreen - separate report and transmit buffer size handling")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/all/20260630070422.459181F000E9@smtp.kernel.org/
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.
The one-byte append above this hunk does not advance pkt, so that byte
is copied a second time. This is older behavior, and I can fix it in a
second patch if you prefer.
drivers/input/touchscreen/usbtouchscreen.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 0bbacb517c28..afb77149a7b1 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -1239,6 +1239,12 @@ static void usbtouch_process_multi(struct usbtouch_usb *usbtouch,
tmp = pkt_len - usbtouch->buf_len;
if (usbtouch->buf_len + tmp >= usbtouch->type->rept_size)
goto out_flush_buf;
+ if (tmp > len) {
+ /* still incomplete: append and wait for more */
+ memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, len);
+ usbtouch->buf_len += len;
+ return;
+ }
memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
usbtouch_process_pkt(usbtouch, usbtouch->buffer, pkt_len);
--
2.34.1
reply other threads:[~2026-11-30 12:06 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=20261130120640.2437520-1-maoyixie.tju@gmail.com \
--to=maoyixie.tju@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--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