From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127795; b=peCKiGxUiR7R1wqgqZCuid4Vjj9xnLJfYyATyaZeXRnoZZXYQ+71EdTDu2/iyTWJR5/a alXMJsF1kSeRJTK0iVa8R1/4tpgkh0vQhiQ+SXBedBd3HhouwXzDb4YkoGcXjikzAV+8P sTEdWFaT2yelvFH2G6Lmi0FcGaCSrSWgcDN5ASOwZJUN1VxaN1jkw+KPbaI0EibahihNP 0qt8bFG0KBedXnYkwQqP6vchGH9ci9w3fHWJP0oq4CB7VYIffdYWjtCidoIDIR2g9NWpz v0AQFiGSJkfF78HFpMaUYeq5/UDqr3qjFxZhdo/yO5GysncU5bYrO23EjQXrS6xUu/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127795; 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=6jNWw7Gj485YUS0rM6MsC7EOSkSNo7XuaWEMOWyUZ+k=; b=X+xHKEjunjNI63jKXvxeRQPAKlRq+BDOgzplgmWHuHRR8gDQIGkBualGlwHRAOy+NzPG jVSoFTTbGQSNjnY9OwvBJ3ZDq+6YpUNB8KoVhcIGQn2NqlrH2H0XxnSweXZst7tmP8Am+ WD/2OWLot7X8eLQQjIzDKbnUll9LBo2GBZCCeRXth9QTenbNBqJ8Bsg1a4sHZZFU3QYVK Lz4U51DvA/gH3Zh26U5O3JrW9qJOdW+95VwjXrnvBeOPhlRtK6ZifyxD8hAhXKavzUE+O tiu6Vuh7eCAZtZfdP0lRSN4GC2o8klIZ6uKMvdYwRbS7+8C69HJwcF4UIAMnMIAMx/g== 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=GXsuaq6K; arc=none smtp.remote-ip=115.124.28.171 Received: from out28-171.mail.aliyun.com (out28-171.mail.aliyun.com [115.124.28.171]) (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 B2993606A32E; Tue, 1 Dec 2026 12:23:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B2993606A32E 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, unprotected) header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=GXsuaq6K DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1796127790; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=6jNWw7Gj485YUS0rM6MsC7EOSkSNo7XuaWEMOWyUZ+k=; b=GXsuaq6KJFLLP1HKAAyVenP57dKQIPlymYiNl6ePjdmJIWLELD8pEazokr37FNNV/tiUyCB1t6b6uBZqsnZnyPbgmoNi2iYCYOy+QwR1VbGLIyR9uvwHfZED9hFGZcmrob8CpyV8/ArAAgg6DWtPMtCh4fFvZx5rjUtY7L9Tc90= X-Alimail-AntiSpam:AC=CONTINUE;BC=0.07624961|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00424129-0.000387356-0.995371;FP=16493982870905425554|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033024148021;MF=zhugl3@xiaopeng.com;NM=1;PH=DS;RN=5;RT=5;SR=0;TI=SMTPD_---.kEGrFRp_1796127789; Received: from DESKTOP-UL5U09E.xiaopeng.local(mailfrom:zhugl3@xiaopeng.com fp:SMTPD_---.kEGrFRp_1796127789 cluster:ay29) by smtp.aliyun-inc.com; Tue, 01 Dec 2026 20:23:10 +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 v2] Input: cyapa_gen3 - reject reports with too many fingers Date: Tue, 1 Dec 2026 20:23:09 +0800 Message-ID: <20261201122309.361277-1-zhugl3@xiaopeng.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261103084135.426629-8-zhugl3@xiaopeng.com> References: <20261103084135.426629-8-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 finger count is taken from the top nibble of a status byte the trackpad firmware fills in, and used to walk the touch array: num_fingers = (data->finger_btn >> 4) & 0x0f; for (i = 0; i < num_fingers; i++) { const struct cyapa_touch *touch = &data->touches[i]; The nibble allows up to fifteen fingers, but the array holds the five touches the chip is documented to report, so a packet that claims more makes the driver report coordinates read from the stack past the register block. Clamping the count was my first attempt. A packet that reports more fingers than the chip has is corrupted, though, and reporting five bogus touches to userspace is not better than rejecting it. A bus read that fails and returns 0xff for the whole report block is one way in: it sets OP_STATUS_SRC, CYAPA_DEV_NORMAL and OP_DATA_VALID at once, so the existing header check lets it through. Reject such a report in the header validation of both the interrupt and the poll path. The driver already reinitializes the device when it sees a bad state, so returning -EINVAL from these helpers takes that path. Size the array from GEN3_MAX_FINGERS, and read the count through GEN3_FINGER_NUM() in the event path as well: the macro masked with 0x07 while the event path masked with 0x0f, and under the old mask a count between 8 and 15 folded back into the valid range. Fixes: 9f1cd857518f ("Input: cyapa - re-design driver to support multi-trackpad in one driver") Cc: stable@vger.kernel.org Signed-off-by: Guanglei Zhu --- v2: reject the report in the header validation instead of clamping the count, as asked; size the array from GEN3_MAX_FINGERS and use GEN3_FINGER_NUM() in the event path as well (the macro masked with 0x07 while the event path masked with 0x0f). Tested with a user space replay of the two helpers, built with ASan. On master every count above five walks past the 27-byte report block and ASan reports a read at offset 63 of the block; a header check that keeps the 0x07 mask still lets counts 8..15 through, since 8 & 0x07 is zero. With this patch counts 0..5 behave as before, counts 6..15 and the all-0xff glitch packet return -EINVAL and nothing is reported. drivers/input/mouse/cyapa_gen3.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c index fc3fb95..f6860a7 100644 --- a/drivers/input/mouse/cyapa_gen3.c +++ b/drivers/input/mouse/cyapa_gen3.c @@ -25,7 +25,7 @@ #define GEN3_MAX_FINGERS 5 -#define GEN3_FINGER_NUM(x) (((x) >> 4) & 0x07) +#define GEN3_FINGER_NUM(x) (((x) >> 4) & 0x0f) #define BLK_HEAD_BYTES 32 @@ -113,7 +113,7 @@ struct cyapa_reg_data { */ u8 finger_btn; /* CYAPA reports up to 5 touches per packet. */ - struct cyapa_touch touches[5]; + struct cyapa_touch touches[GEN3_MAX_FINGERS]; } __packed; struct gen3_write_block_cmd { @@ -1149,7 +1149,7 @@ static int cyapa_gen3_event_process(struct cyapa *cyapa, int num_fingers; int i; - num_fingers = (data->finger_btn >> 4) & 0x0f; + num_fingers = GEN3_FINGER_NUM(data->finger_btn); for (i = 0; i < num_fingers; i++) { const struct cyapa_touch *touch = &data->touches[i]; /* Note: touch->id range is 1 to 15; slots are 0 to 14. */ @@ -1200,6 +1200,11 @@ static int cyapa_gen3_irq_handler(struct cyapa *cyapa) return -EINVAL; } + if (GEN3_FINGER_NUM(data.finger_btn) > GEN3_MAX_FINGERS) { + dev_err(dev, "invalid finger count: %02x\n", data.finger_btn); + return -EINVAL; + } + return cyapa_gen3_event_process(cyapa, &data); } @@ -1223,6 +1228,9 @@ static int cyapa_gen3_try_poll_handler(struct cyapa *cyapa) (data.finger_btn & OP_DATA_VALID) != OP_DATA_VALID) return -EINVAL; + if (GEN3_FINGER_NUM(data.finger_btn) > GEN3_MAX_FINGERS) + return -EINVAL; + return cyapa_gen3_event_process(cyapa, &data); } -- 2.43.0