From nobody Thu Apr 2 12:36:48 2026 Received: from cstnet.cn (smtp25.cstnet.cn [159.226.251.25]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 634A640DFA2; Sun, 29 Mar 2026 00:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774743437; cv=none; b=KXmkMGqv0lMxIFYmdmXG07eJI+oM17oUXlviRrNBqU3MgZ9AywOGqP55qvNbM/8K6ePt+mN/PapFxL7b0r+GllxBPtLNM7bIy//1Yf3Cj51KFfsrfdgbvWboSXUp1Px31zEZc/7bfj7mxGZGOyjmCHIsKG3zKwx4lwVJ4fv+eRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774743437; c=relaxed/simple; bh=FSdOx/dtI5u/q7uad+y3xAVWN57X+pw/p2xoLVjBEx0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jIdpLMKm4thHykK7jrPXx3mHdDRkexIcCHLZxqZgwvSwlWWsdlZpJPv1kkEL1BToC29OPkIjIID5IR3DP8tV2H+HVJ2tF9ZWS5YNXy8mUL2jebteYiH/U7Uicmsum4cE6Z/VoBXuW4fkdxtFxA9kx72bD1P94AaVEldJn6vaUC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from localhost.localdomain (unknown [111.196.245.197]) by APP-05 (Coremail) with SMTP id zQCowADXZQmHb8hpe4LICw--.39110S2; Sun, 29 Mar 2026 08:17:12 +0800 (CST) From: Pengpeng Hou To: dmitry.torokhov@gmail.com Cc: andriy.shevchenko@linux.intel.com, kees@kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, pengpeng@iscas.ac.cn Subject: [PATCH v2] Input: aiptek: validate raw macro indices before updating state Date: Sun, 29 Mar 2026 08:17:11 +0800 Message-ID: <20260329001711.88076-1-pengpeng@iscas.ac.cn> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260323070311.42849-1-pengpeng@iscas.ac.cn> References: <20260323070311.42849-1-pengpeng@iscas.ac.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: zQCowADXZQmHb8hpe4LICw--.39110S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WF43ZFyDXryfCrWUGr13twb_yoW5Jry3pr WUX39IkFWvva17Xw12qw1UAry5twsrtrZ8XF13Jw4q9F1FqryxW3s8J3y2vF95CF1kJ39F qrs3tr4DCr9rZF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkE14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr 1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY1x0262kKe7AK xVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1l IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j 6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUSNt xUUUUU= X-CM-SenderInfo: pshqw1xhqjqxpvfd2hldfou0/ Content-Type: text/plain; charset="utf-8" aiptek_irq() derives macro key indices directly from tablet reports and then uses them to index macroKeyEvents[]. Report types 4 and 5 also save the derived value in aiptek->lastMacro and later use that state to release the previous key. Validate the raw macro index once before it enters that state machine, so lastMacro only ever stores an in-range macro key. Keep direct bounds checks for report type 6, which reads the macro number from the packet body and uses it immediately. Signed-off-by: Pengpeng Hou --- v2: - validate the raw `macro` value before it enters `lastMacro` - drop the redundant bounds checks on `lastMacro` itself drivers/input/tablet/aiptek.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c index 6df24cee3c9d..e0f64ed63543 100644 --- a/drivers/input/tablet/aiptek.c +++ b/drivers/input/tablet/aiptek.c @@ -658,6 +658,8 @@ static void aiptek_irq(struct urb *urb) pck =3D (data[1] & aiptek->curSetting.stylusButtonUpper) !=3D 0 ? 1 : 0; =20 macro =3D dv && p && tip && !(data[3] & 1) ? (data[3] >> 1) : -1; + if (macro >=3D ARRAY_SIZE(macroKeyEvents)) + macro =3D -1; z =3D get_unaligned_le16(data + 4); =20 if (dv) { @@ -700,6 +702,8 @@ static void aiptek_irq(struct urb *urb) right =3D (data[1] & aiptek->curSetting.mouseButtonRight) !=3D 0 ? 1 : 0; middle =3D (data[1] & aiptek->curSetting.mouseButtonMiddle) !=3D 0 ? 1 := 0; macro =3D dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : 0; + if (macro >=3D ARRAY_SIZE(macroKeyEvents)) + macro =3D -1; =20 if (dv) { /* If the selected tool changed, reset the old @@ -737,11 +741,11 @@ static void aiptek_irq(struct urb *urb) */ else if (data[0] =3D=3D 6) { macro =3D get_unaligned_le16(data + 1); - if (macro > 0) { + if (macro > 0 && macro - 1 < ARRAY_SIZE(macroKeyEvents)) { input_report_key(inputdev, macroKeyEvents[macro - 1], 0); } - if (macro < 25) { + if (macro + 1 < ARRAY_SIZE(macroKeyEvents)) { input_report_key(inputdev, macroKeyEvents[macro + 1], 0); } @@ -760,7 +764,8 @@ static void aiptek_irq(struct urb *urb) aiptek->curSetting.toolMode; } =20 - input_report_key(inputdev, macroKeyEvents[macro], 1); + if (macro < ARRAY_SIZE(macroKeyEvents)) + input_report_key(inputdev, macroKeyEvents[macro], 1); input_report_abs(inputdev, ABS_MISC, 1 | AIPTEK_REPORT_TOOL_UNKNOWN); input_sync(inputdev); --=20 2.50.1 (Apple Git-155)