From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127804; b=A4gc/5HZy7TTSn7Tvnq3ZewfYPosHWnFSCamCbx/0jrCGdnOHBrK4GAaLe+2Dw4kk8Cx mDuwfNq9uvO0kMGHht+5HvfEIaZamzh9ObeaDu6iB5rOfVehXy6AduwMaTnmlDZn/bgjU zZRPKk2Gf/R9PN/RCgjZQ7AEdjxNWlGHNmakDU2wYYzruqTuQu+YcVJmb1CxTU3ojKdpY hVi42cTX4XsWlAvMgrQa4K5fHpnm3hgN3D6QFetVw7vVH1ORT15WCFriu+pSDkWsQ8YfA +YtUNZOJyPRcpEViNygb0HiOYyb4EF4hMmO13ZM8Ph5u2jOE5pcrVjcADa+WET8FqcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127804; 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=M/4AUQiPRmbUtkFhr3JKW6W2n3MqX926Cf242g6Vxbg=; b=b4yWgiUwvboI50NPxe//0JSCcQerHQ34MDGwmieTMgPSbT4ScIKXJyGP4SG/aBbv9FmE 8bfYRLHEFq2CEA6uEMJ/scM8deOoiAYA45xiF8+jT0iSoGAH3TbEzc0IDNar3XgVyE408 dbRyv0gaB5nOssxYwAgj3ho8/ILPMdkr39pZrnCw1usAh/R1Alu6lT76S3CKNi1AVE4T6 lLy82eDOO77zmlQHYfGSRQK3fJ9esuUGPFZ9/TOmo9ZWWhu7T4XhUpu62h/8rP0UlnIkg 639FIg2tkI0HPI9IAedRCYOKzE1bKoudvY3irzjqkz+KJv96oKNIZFVimWEUMTsSEIw== 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=CxWQerVl; arc=none smtp.remote-ip=115.124.28.148 Received: from out28-148.mail.aliyun.com (out28-148.mail.aliyun.com [115.124.28.148]) (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 36D3F606A686; Tue, 1 Dec 2026 12:23:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36D3F606A686 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=CxWQerVl 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=M/4AUQiPRmbUtkFhr3JKW6W2n3MqX926Cf242g6Vxbg=; b=CxWQerVlY63AqdcbWwSsfZyymJbA2kreEQyyIcEBJjGPa93rmO/1B/7e+jmST7N66EYxdG4OaWLVaF5Ed/iJw4v4vf4cVwUyKPx+DvwYC+BSq68PNrsXe+t3CAgx3jM+7WfDfT3GgRNmCV5bDk6FL3Oql+0F9F4tMOeb17vzEJY= X-Alimail-AntiSpam:AC=CONTINUE;BC=0.924253|0.09915012;CH=green;DM=|AD|false|;DS=CONTINUE|ham_system_inform|0.108087-0.000600848-0.891312;FP=870445283756543986|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033032106048;MF=zhugl3@xiaopeng.com;NM=1;PH=DS;RN=5;RT=5;SR=0;TI=SMTPD_---.kEBT75G_1796127797; Received: from DESKTOP-UL5U09E.xiaopeng.local(mailfrom:zhugl3@xiaopeng.com fp:SMTPD_---.kEBT75G_1796127797 cluster:ay29) by smtp.aliyun-inc.com; Tue, 01 Dec 2026 20:23:17 +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 4/4] Input: adi - check the decoded counts against the device tables Date: Tue, 1 Dec 2026 20:23:14 +0800 Message-ID: <20261201122314.361354-5-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-kernel@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() decodes the number of axes, hats and buttons from the ID packet, and adi_init_input(), adi_init_center() and adi_decode() then walk adi->abs and adi->key, the axis and key tables of the device: for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) set_bit(adi->abs[i], input_dev->absbit); The packet is free to claim more axes or buttons than the device has, which walks past the end of those static tables. Keep the size of both tables next to the pointers and reject an ID packet whose counts do not fit. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Guanglei Zhu --- Tested with the same builder: an ID packet for device 0 that asks for 15 axes and 15 buttons passes the length check, and the setup loop then reads adi_wmi_abs[9..14], past the end of that 9 entry table; ASan reports a global-buffer-overflow. With this patch the packet is rejected with length = 0. drivers/input/joystick/adi.c | 48 +++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c index 57a7978..a329fcb 100644 --- a/drivers/input/joystick/adi.c +++ b/drivers/input/joystick/adi.c @@ -67,11 +67,37 @@ static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_B static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 }; static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; -static char* adi_abs[] = { adi_wmi_abs, adi_wmgpe_abs, adi_wmf_abs, adi_cm2_abs, adi_wmi_abs, adi_wmf_abs, - adi_wmgpe_abs, adi_wmed3d_abs, adi_wmgpe_abs, adi_wmgpe_abs, adi_wmi_abs }; +struct adi_tables { + char *abs; + unsigned int abs_count; + short *key; + unsigned int key_count; +}; -static short* adi_key[] = { adi_wmi_key, adi_wmgpe_key, adi_cm2_key, adi_cm2_key, adi_wmi_key, adi_cm2_key, - adi_wmgpe_key, adi_wmed3d_key, adi_wmgpe_key, adi_wmgpe_key, adi_wmi_key }; +static const struct adi_tables adi_tables[] = { + { adi_wmi_abs, ARRAY_SIZE(adi_wmi_abs), adi_wmi_key, + ARRAY_SIZE(adi_wmi_key) }, + { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key, + ARRAY_SIZE(adi_wmgpe_key) }, + { adi_wmf_abs, ARRAY_SIZE(adi_wmf_abs), adi_cm2_key, + ARRAY_SIZE(adi_cm2_key) }, + { adi_cm2_abs, ARRAY_SIZE(adi_cm2_abs), adi_cm2_key, + ARRAY_SIZE(adi_cm2_key) }, + { adi_wmi_abs, ARRAY_SIZE(adi_wmi_abs), adi_wmi_key, + ARRAY_SIZE(adi_wmi_key) }, + { adi_wmf_abs, ARRAY_SIZE(adi_wmf_abs), adi_cm2_key, + ARRAY_SIZE(adi_cm2_key) }, + { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key, + ARRAY_SIZE(adi_wmgpe_key) }, + { adi_wmed3d_abs, ARRAY_SIZE(adi_wmed3d_abs), adi_wmed3d_key, + ARRAY_SIZE(adi_wmed3d_key) }, + { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key, + ARRAY_SIZE(adi_wmgpe_key) }, + { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key, + ARRAY_SIZE(adi_wmgpe_key) }, + { adi_wmi_abs, ARRAY_SIZE(adi_wmi_abs), adi_wmi_key, + ARRAY_SIZE(adi_wmi_key) }, +}; /* * Hat to axis conversion arrays. @@ -403,6 +429,16 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port) adi->pad = -1; break; } + + t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX; + if (adi->axes10 + adi->axes8 + + (adi->hats + (adi->pad != -1)) * 2 > adi_tables[t].abs_count || + adi->buttons > adi_tables[t].key_count) { + printk(KERN_WARNING "adi: Device %#x has no room for %d axes and %d buttons\n", + adi->id, adi->axes10 + adi->axes8 + + (adi->hats + (adi->pad != -1)) * 2, adi->buttons); + adi->length = 0; + } } static int adi_init_input(struct adi *adi, struct adi_port *port, int half) @@ -421,8 +457,8 @@ static int adi_init_input(struct adi *adi, struct adi_port *port, int half) snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname); snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half); - adi->abs = adi_abs[t]; - adi->key = adi_key[t]; + adi->abs = adi_tables[t].abs; + adi->key = adi_tables[t].key; input_dev->name = adi->name; input_dev->phys = adi->phys; -- 2.43.0