From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796040405; b=bMbiLwGLDbkefzdEsm22eKfIYQl5Qn9l8FmKt+b498QtbrQEec2m5fdxaqAGf04WhGdj mWXdk5dO699XDtxe+O/ANy9eq2AIe5ULrc2DNr2lwjmLbmosskufewixrr0GOYSfhBpAb yeIdQZb2zxDLurL+R0fQgNQ6Lp8Zk+a2IkXVVdvEwZ7wSc6Fhgqi0cIll79P7w5Ste3LW BeCIn6TD/VQ4+MQPEGX56DpVzj0x/uUuI2bB2T7YBeqqI3KTeoZL6OiOhx9ogd+mSKBnb HySIpGpXNwX/2GKU2Bl41E86vRkn/POABsSCZR2j8i2TO3AD/RkIH1TJW5qhHPlONTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796040405; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=+He5SxEzBr+vIrJdyDVslNC1TnxYkqxTXjsrmCrWXBI=; b=ab5KwmSo7SzuMiISb0PYXXq3ws5A2AU83L+JISOb+hJSSN44r+VQQrAFAOPD3VVnTnM5 +RXVBohzHCulQ/2OD4tdPjTp94+2eUxCkqQzyIi4pjyPc/vI6X79XwczkaLdnNyqPWiqu tyY7LTv3SNDkWFegZzykFX0sf0D11jARvfwSZiVzPYQYonvCXYcSCHUwd7iyQKQFdSD5L Zw2Ow3TBbyILXOiTaoIVvqHmv8GlTUn+WtVmFk8Le4HwL7jBJNOCJM3Ni1B9UBPs56UOW PmhGotccR+1I+UUUMhHOeXHFZeNX+3Eb6dp331sLSH0QcppX1fnBy0K/TUtKySSykwQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=GfkPeDrB; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47AE9606A31C for ; Mon, 30 Nov 2026 12:06:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 47AE9606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=GfkPeDrB Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-386cf1041cdso9252872eec.0 for ; Mon, 30 Nov 2026 04:06:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796040404; x=1796645204; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=+He5SxEzBr+vIrJdyDVslNC1TnxYkqxTXjsrmCrWXBI=; b=GfkPeDrBl8scyB8T1f7nH9PXpZRu5oUzquucssnQMYDE+qwepabigpNmEN/4k0fuSd biOM3/MQYisE5pBct9+oNGrDHHqY+Q5KOQ86oFbNTwtg5mXS2iRjLwz7WgFZW0DckqeZ fANjrr1o1fiuXfgaJnzCiN5GBlpSE9K5OoNJf8fkK4rYQhWqSKQYjKP/YcD9q8W0XxIl Z76i92HJu4zlmeKdgqfzFJHD32u9dAKgzu+LTEv7oo3f5/5CFAMDzpfSUvPWAjuY5U7x WFvYH0ocrmy80lLBkW1/xVMA5SIqW6HtnDALYBsy+r2RaDWpkW5jHN63CbEgqTylFbog RDtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796040404; x=1796645204; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+He5SxEzBr+vIrJdyDVslNC1TnxYkqxTXjsrmCrWXBI=; b=tXqQf1FNgKnpUdnX7RKSWKeauyMm4eeEJ52dd8h1T2DdXMpzs5kHeGWVj2Ub/GwY1E L60dP33g+Nw+etEJjlHI0MWxCd68oszsW7sfxqTfKbqRLcUms0x4U9+V0xLH2K3bZQJz SSUEhZqwtdOamoyNor9oHAwmQHMwUpIFoM9osCI2eEzk8iuQJgQw6k3Am89rw18dV2/v VJEIGKfAHzHl1j+L3TUEaH+Zq5s+/htpPNaKpRVZ2OsvzofyukI9ro9UaEnzZGgxrp6o CsJffMUvvlFMKwt4XLaOnsuOdnFpy+6x3oXjVuLxvbRBfUMypUYg35UbH4UGb7d+Mhby 77JA== X-Gm-Message-State: APuU4Z9yhPes3ZFHNdpSfRe6NMxVIWISrLuRaW1YIEL2RcUdk17IJ4pX l3NrmVhtH0PNqYM4AQrfPg5/gjawI4NNgARHyYHvO0uxFNA/0VIYmWad X-Gm-Gg: AZFdTZd6F3grJJ/oh6E/NaID6XZmMY4K7Sw2DlT+X3oU9nMDsf1S3WDLCOPR91k4u6W oRGUHKGzMHOc4055DqVj6014FxLDViODEr0F6sAB0c2xsxSCNfwYhjn/RHVdf9ZA32CuCJRro5Z kP6g6kB4A1ftSRGMnYf5w19MNtNoVHTBXj4JAoLnfx2IX1mC+8vlgba672Nokg8TvqrTacsIXNp uMUD4eNAtiSZZFaa/AAicTLgrdW14cMqHyptlW/JXrsOMBidfab5oQu240ZqbDcmIGprcktL50+ /xCW2HwFgyMUTRP4FnSURN+mURK7oN3PGPibBpqVhtUXxZySmUBV9NX6kCCuCgtcmA/r6UDDGyh 9TC3YVxLT9UZ77NyBPCcCdD6pqZTjyT9hZJCV99qEowv9ynSbMlsMAfBx6urwH6QCIaKU8ZftrU ICDrWRBWZFE5HpzYQc1l2Iqx+6PETylp7Jeb+EwuidwrmUW4TFZSO3PTLeNfVynvJaTrzF80Xhg tGQMUd9DvL5woXYZ9oa8voVZzx3oh1lsVYDeuTOktnfRrsE9vq6afjCTm3HAww7DN9SntUYWHAr DpQs3pHgiQS/nQxFXy/6K+r8juc8D3XYdtoI5xxeINO0dAe4shDT8wfpqDC32N52lJSV/9SV/HI = X-Received: by 2002:a05:7301:2108:b0:386:b99:8ff9 with SMTP id 5a478bee46e88-3860b999354mr29168551eec.40.1796040404163; Mon, 30 Nov 2026 04:06:44 -0800 (PST) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386aaae4960sm66780272eec.18.2026.11.30.04.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 04:06:43 -0800 (PST) From: Maoyi Xie To: Dmitry Torokhov 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 Message-Id: <20261130120640.2437520-1-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Link: https://lore.kernel.org/all/20260630070422.459181F000E9@smtp.kernel.org/ Signed-off-by: Maoyi Xie --- 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