* [PATCH] Input: usbtouchscreen - check received length when completing a packet
@ 2026-11-30 12:06 Maoyi Xie
0 siblings, 0 replies; only message in thread
From: Maoyi Xie @ 2026-11-30 12:06 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 12:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:06 [PATCH] Input: usbtouchscreen - check received length when completing a packet Maoyi Xie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox