From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127801; b=lZ7Ge7tGTZtAzfgSeFyAmUDQLZDz/pvsbreQbq/NgXSQqoskl/pdiH+D5bKOdjwi3qg/ qAuo0FIeWEQld32OOo1HyxY8lLL1k792a2exMjrS9ceN2m51zMb0bzAYW8uJOD81hV+b6 h6JekWwVNIfWG2vHJMfGsCZbn/Dj4xRig/y1kxvrrgUoiOElT0OhPCSUjUg1y5nLMeKD3 tvuI3pqSJgc6fANIBgajAUzV2MjXABK7f0j7pln01AN/Xifec3xB5VWNgUmIqfT1YUvzE mJXKT2ArPhW8uIrQvqJ3oT1+6+df9yq+v6yeC2Arm2sCroYloZNq1zuaJgy+JoWwKIw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127801; 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=cq+q2v45bQYk4i7mWUMloGRHyJ9U174Mv0seWn/7Fys=; b=zjPs2PI6eAn+CKKmeO+PU7TPg/HTo9w0u/mEOtQ8ZCwgja+oS/ct3Z9N/i3LsCT2QmZs mErpa3EtYJtBjQ5Ot1cxi+yFiYUQ3etkAr9zvVfgx7RrqpQTfsRlb+dIvWWRbXfykTNA3 Zke3rRYhE9f+J0q10QdWf6NqrSp6rMK8C4y11n4JkyklVGHwKgIB4otvW0HJ32lkixQgg gO2zCkzpEKFZvv5nIk10KRgzo7YLbjmHX8VPX/VcLAjqQVgB1NLDlXLtmXeVqXoEaIYf8 ENg6DIGVvUMNvhObU4RMUvyaqMXcF4zaCG1WiSKfckdgTArSHt7qlN/aIe1d7WeW8Hg== 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=BQMzw2NV; arc=none smtp.remote-ip=115.124.28.4 Received: from out28-4.mail.aliyun.com (out28-4.mail.aliyun.com [115.124.28.4]) (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 1F970606A32D; Tue, 1 Dec 2026 12:23:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1F970606A32D 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=BQMzw2NV DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1796127797; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=cq+q2v45bQYk4i7mWUMloGRHyJ9U174Mv0seWn/7Fys=; b=BQMzw2NVCEUM+EF+BhKfj8QN9+aUyusoXqonaJmj6JVFQ6FGKklj8PO2pgMkxXh9//qYGz6DdWrYFgsug6qf/oDROIgDhvMXScKkfEjumcIAq29DUz3ckJNROgZ72tsfqZfu2Rrlr1PVzVSzREOBmYl13sg1rbyjQEQ3M+JB9ZQ= X-Alimail-AntiSpam:AC=CONTINUE;BC=0.8121229|0.1089389;CH=green;DM=|AD|false|;DS=CONTINUE|ham_system_inform|0.253198-0.00100827-0.745794;FP=3431027509900677074|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037071049;MF=zhugl3@xiaopeng.com;NM=1;PH=DS;RN=5;RT=5;SR=0;TI=SMTPD_---.kEBT74o_1796127796; Received: from DESKTOP-UL5U09E.xiaopeng.local(mailfrom:zhugl3@xiaopeng.com fp:SMTPD_---.kEBT74o_1796127796 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 3/4] Input: adi - reject ID packets with wrapped axis or button counts Date: Tue, 1 Dec 2026 20:23:13 +0800 Message-ID: <20261201122314.361354-4-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 adi_id_decode() derives the counts from fields of the ID packet and hands them to adi_decode() and the input device setup: adi->axes10 = adi->axes8 - i; ... adi->buttons -= 4; Nothing checks that the packet leaves enough behind for the split. A 10-bit axis count larger than the 8-bit one, or a TPD or WGP packet with fewer than four buttons, subtracts below zero, and the loops that report the axes and buttons then quietly do nothing. The fields are plain char as well, so what they hold depends on whether char is signed on the architecture. Store the byte fields as u8 and pad as s8 so the values do not change with the architecture, and reject an ID packet whose split or button count would wrap instead of letting the wrapped value reach the loops that walk the axis and button tables. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Guanglei Zhu --- Tested with a bit stream builder for the ID packet, built with ASan. On master a packet whose 10-bit split is larger than the 8-bit count gives axes10 = -1, and a TPD packet with three buttons gives buttons = -1; the reporting loops then skip them. With this patch both packets are rejected with length = 0. Storing the counts as u8 without the checks wraps them to 255 instead, and the wrapped counts walk past adi_key[] and adi_abs[] - ASan reports a read past the 8 entry table. drivers/input/joystick/adi.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c index ad0845e..57a7978 100644 --- a/drivers/input/joystick/adi.c +++ b/drivers/input/joystick/adi.c @@ -91,18 +91,18 @@ struct adi { int length; int ret; int idx; - unsigned char id; - char buttons; - char axes10; - char axes8; - signed char pad; - char hats; + u8 id; + u8 buttons; + u8 axes10; + u8 axes8; + s8 pad; + u8 hats; char *abs; short *key; char name[ADI_MAX_NAME_LENGTH]; char cname[ADI_MAX_CNAME_LENGTH]; char phys[ADI_MAX_PHYS_LENGTH]; - unsigned char data[ADI_MAX_LENGTH]; + u8 data[ADI_MAX_LENGTH]; }; struct adi_port { @@ -364,6 +364,12 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port) i = adi_get_bits(adi, 4); if (t & ADI_FLAG_10BIT) { + if (i > adi->axes8) { + printk(KERN_WARNING "adi: Bad axis split (%d of %d 10-bit)\n", + i, adi->axes8); + adi->length = 0; + return; + } adi->axes10 = adi->axes8 - i; adi->axes8 = i; } @@ -383,11 +389,14 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port) switch (adi->id) { case ADI_ID_TPD: - adi->pad = 4; - adi->buttons -= 4; - break; case ADI_ID_WGP: - adi->pad = 0; + if (adi->buttons < 4) { + printk(KERN_WARNING "adi: Bad button count (%d) for device %#x\n", + adi->buttons, adi->id); + adi->length = 0; + return; + } + adi->pad = adi->id == ADI_ID_TPD ? 4 : 0; adi->buttons -= 4; break; default: -- 2.43.0