From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127803; b=qAdhgdXydXPp3UnOqJM26WH1hmngOP6O8EqUQfVjqaO9YycCFQKeVqGRy724aqU5aRH6 wrWgndwLbCpY83QAPmqo5SlfIX0KwARM0l6kjaKIxTXAph6xmeEMzlqnVciD8cN5yfBSS Z3LO/mresC7ebtFrFzFtoqkXW2KfarGSXOthRCY1QHPXIswHt5LEYEQyFvcIWq8xFP2/h wQtOAVZHhupH+X0NPnQuYikUY3Lfm3yngu/VllHPnh7mGB9y5r3MJMMNhU8SaeU1kGUvN gRoQ5VARqfm0+KOo4hWoCmRGjcFz/gVh35YvUxIxWxAsqkG25M/tm58TD6NCSR2DaNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127803; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=z/LV6z6F0s70ns8LWezQjYn1o4Fp+fwkU8DUTLgYKFY=; b=uO9T/84ADu59FzsxUPJWi+qQ6t9i9xnuhAKd6vCWIqyZZJl9p7Mg78JjnzH0bRqjbR8T ZQqqpYDwYZp5zRsieMxhwyU7alyhgv57ajnNsTOhLFbMjH8T/Si9I5gx1MFG097negEJl di2XDQMLruNU2xc3TdBZGSvxqKe0K5Kexm8BiaCZtS0zlMCe4g2x61riLjedb9dvOYDEb y3AaQZlksRj/eKuIVvZijb0gU8yutTcjHPi9wRGnbMTnWzyvC4fANaRRb4AxsySpLrHrW UecoSAV9ALm8Bt5MoMyJfxj1p49ZW/GJOhNMRIss6qC7yCRluPQb4VsR+hmf4Bc3BYQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=xiaopeng.com; spf=pass smtp.mailfrom=xiaopeng.com; dkim=pass header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=p68yaCKz; arc=none smtp.remote-ip=115.124.28.52 Received: from out28-52.mail.aliyun.com (out28-52.mail.aliyun.com [115.124.28.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B64F606A32C; Tue, 1 Dec 2026 12:23:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B64F606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=p68yaCKz DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1796127796; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=z/LV6z6F0s70ns8LWezQjYn1o4Fp+fwkU8DUTLgYKFY=; b=p68yaCKzuiHRa1t9Gv3GNdxSgQAVldCAjIcrlYR/C19o/4iWYFUv5xT5Z2XfACIDHl8LVI34jgUc6Ngh10lHsORkashwS+1MTUwTXJDb8Wr6Lv3OTP5/QAOWcaDjQFgDPgSUp6MeNV8/O4ecksY3Gpv4BnnyTTUDF16N4ejsfiA= X-Alimail-AntiSpam:AC=CONTINUE;BC=0.1714008|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_alarm|0.0418813-0.00138854-0.95673;FP=10177120959951605043|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037034184;MF=zhugl3@xiaopeng.com;NM=1;PH=DS;RN=5;RT=5;SR=0;TI=SMTPD_---.kEBT74P_1796127795; Received: from DESKTOP-UL5U09E.xiaopeng.local(mailfrom:zhugl3@xiaopeng.com fp:SMTPD_---.kEBT74P_1796127795 cluster:ay29) by smtp.aliyun-inc.com; Tue, 01 Dec 2026 20:23:16 +0800 From: Guanglei Zhu To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, liuc63@xiaopeng.com, stable@vger.kernel.org Subject: [PATCH v3 2/4] Input: adi - fix the packet length guard in adi_read_packet() Date: Tue, 1 Dec 2026 20:23:12 +0800 Message-ID: <20261201122314.361354-3-zhugl3@xiaopeng.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201122314.361354-1-zhugl3@xiaopeng.com> References: <20261103084135.426629-3-zhugl3@xiaopeng.com> <20261201122314.361354-1-zhugl3@xiaopeng.com> 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 The loop that samples the wire stores each bit with adi[i].data[++adi[i].ret] = w; so ret is incremented before the store, but the guard in front of it tests adi[i].ret < ADI_MAX_LENGTH. A packet that fills the buffer therefore writes data[ADI_MAX_LENGTH], one byte past the array, before the guard stops it. Test against ADI_MAX_LENGTH - 1. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Guanglei Zhu --- Tested with the same replay loop driven from a table instead of the gameport. On master a 257 byte packet stores data[256] and ASan reports a heap-buffer-overflow one byte past struct adi; with this patch the loop stops at ret = 255. drivers/input/joystick/adi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c index 026f7de..ad0845e 100644 --- a/drivers/input/joystick/adi.c +++ b/drivers/input/joystick/adi.c @@ -141,10 +141,14 @@ static void adi_read_packet(struct adi_port *port) for (i = 0; i < 2; i++, w >>= 2, x >>= 2) { t[i]--; if ((w & 0x30) && s[i]) { - if ((w & 0x30) < 0x30 && adi[i].ret < ADI_MAX_LENGTH && t[i] > 0) { + if ((w & 0x30) < 0x30 && + adi[i].ret < ADI_MAX_LENGTH - 1 && + t[i] > 0) { adi[i].data[++adi[i].ret] = w; t[i] = gameport_time(gameport, ADI_MAX_STROBE); - } else t[i] = 0; + } else { + t[i] = 0; + } } else if (!(x & 0x30)) s[i] = 1; } } while (t[0] > 0 || t[1] > 0); -- 2.43.0