From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796486826; b=wMh5gJgUSBvDufASYUEt1wice32Q6ca5PBph8hqlf5VKet4sexWoPmajUHDphQ/vfR7n cPv0+2R6SnJVGzZHioZ8gMW6ojtW9CztzjKe/47aZsMhJC7101JGVmRRyThszGG1rT6Dr Z+jpAFulfpi9g0HAJ8gGFUWai0u+1xGp+Jk+qQMd0m8602k3IHFFHwd3sxl7g1XIERS0V bJfxnaXFywSoEYISIo15c//qITJDsjZ5tyXG7VKxiZ89v3vH3pohAWmwFrPUGWjlb6MhC MiPzCKW9Bt6iEvSod5eCcsJ/ok/HUUomtifDKl7o1dYkVhlOFf+aoxgy8uKoAiNetYQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796486826; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=+uYL2VOe4+CM7cZ09xRYYKIaZkJVxTP3S2FR2OsaXX8=; b=3LILw0XIigutZz3CoC4HLojfrn49ZhmxfrUh11LSzO0LwWIIWWHfZtXzhdHyNVIz9muz vEyL+5adyOrSfFN2g5ylwEQaO1fpEfyXfTLbCAZ5ztvnw8W2QTnD3rbHrQW3+hzPH1Dsc bfDjbfkss5yd3wQ2GUYG79XWZrthHS1QEU03yHmv7HAi56xEtLt0YnpPFc9FUXTCGahhn 8DuxFSeW3VbFcv26fbr94Fn8bkj7QlC6N6o/oWofFcRHQJdm8+uwSX3lm5jljV+DjCGIG DyKWtCdwFvUBnnbxBxcGaQw0L+yVLdV9FcHnjanlpJt1eH19I52Wy6uv5MIu/X42A8A== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=M1b0mqq4; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFB30606A32F for ; Sat, 5 Dec 2026 16:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=M1b0mqq4 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796486825; b=CuE0WXCMhfLqPEA/emdzUaZD/Vel6PBlD9nQYhlPRShjM5CIdTYzbO992o52v1bQLV1l ZvIV3Md0bU8BOWuoDBtcTOin4/KjvdDPKABcdbDrkVW9cKUgLjbyWp28U9eq633ZrYUue PEBHcrTkety1iPw49jaCywW/kHOSQpMDN6+lZvB2pQ5Nj74nWqRSWNV36UvgvDDoYL15j 18XvbDo9D7zkzl60i7DIvrO1CHqPc+7IlpYYQev40o/6di7m38OZ38vyRTbochHcsqtDk eG8DQfnuESMEYYbvP/VfcnHXIdeqexSRcep0zjjOWzkeUpnqkV5p05wR2qVj31IlW0w== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796486825; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=+uYL2VOe4+CM7cZ09xRYYKIaZkJVxTP3S2FR2OsaXX8=; b=bYrQzUnMPgP7WfY1CV9t8iH6ZemD9q8C1k2Y7Oj5Vdpxi2pDZJoE4u+O65UUu7O/urOj +iI+BxCfjoLkyZA/3dFb0Nx0FebL3YahMuvVhD/ngSGUsF0aYvvf7fqY9BSnZdiJh8wpN k7WmtArt+81Oavx0MV0s/UndVfInViW2qy7hezLpAAuaSzrHIBnmdo+wXecDbKt+2aJJZ //xIExRK96s6vPCxAvNWc/iR2yf79xmTY3HU/npjRBm5PHWOmkHM7JSKM1AKKix2bP/8O 3tb49wTFTYv7Fppk5u7sn97S/oVEARN6SZkACEzfokb605/hUWJggDmKggYpyLZFxIg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (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.kernel.org (Postfix) with ESMTPS id 345571F00A11; Sat, 5 Dec 2026 16:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796486825; bh=+uYL2VOe4+CM7cZ09xRYYKIaZkJVxTP3S2FR2OsaXX8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=M1b0mqq4AWAlZHv+Jlu53Gx5Turw3/K6QV5vEL3zfSCqa8IxCzE+R1EmIyApoyZDn kp5e+tpCqXSzCwC6ptfSmO1t3V8f9ZLDVko7eaN0GygMNJd/R8zX2Yx3KTYeqZ03KY Hbzi1u8tGzO+EUK5WXpWx1XcAcGy872Ea/O8hmR45vLDUj+24csP15DmqUVkXMkxOQ TbyfgB/0EFG0oh87SHKSbpaSufb6M5eCu0Fx6MBzyW32tVygAbOVs7Fy5MR2gDrdN4 ipyHJtcq6t8SHCaanbScD4xBWtMTD8ltm+EUuC2H9u0sn/Xj0Y/tQhxZmYYmV02jFo J5FCBxENSXIqA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id B159D503A7; Sat, 5 Dec 2026 16:07:04 +0000 (UTC) From: Maoyi Xie via B4 Relay Date: Sun, 06 Dec 2026 00:07:04 +0800 Subject: [PATCH v3 2/2] HID: intel-ish-hid: Allocate hid_devices for MAX_HID_DEVICES entries 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-Type: text/plain; charset="utf-8" Message-Id: <20261206-ishtp-hid-buffers-v3-2-1dff00637cb7@gmail.com> References: <20261206-ishtp-hid-buffers-v3-0-1dff00637cb7@gmail.com> In-Reply-To: <20261206-ishtp-hid-buffers-v3-0-1dff00637cb7@gmail.com> To: Jiri Kosina , Srinivas Pandruvada Cc: Maoyi Xie , linux-input@vger.kernel.org, Benjamin Tissoires , Zhang Lixu X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796486823; l=1839; i=maoyixie.tju@gmail.com; s=20261205; h=from:subject:message-id; bh=zn0FygrTUlrdwPJ+bu6QujesnB82NbjsrpJLJdKQdq4=; b=eqReB2NQiyNdNzmon1GMz0q+Nklh4cmkK2wPP8z4gZazxDPzcrqpKttiuTka7DJkXn8d0BKe2 0+lYwduu4yaBIuO7dyHArQH8o9Ymf69IWpPTMf47pfI3Lp0BUWSlOr7 X-Developer-Key: i=maoyixie.tju@gmail.com; a=ed25519; pk=ydzJ0f1uQvj5L6EhJ06HNQgqdJc9AbK3VpVFt+TW8R8= X-Endpoint-Received: by B4 Relay for maoyixie.tju@gmail.com/20261205 with auth_id=1755 X-Original-From: Maoyi Xie Reply-To: maoyixie.tju@gmail.com Content-Transfer-Encoding: 7bit From: Maoyi Xie process_recv() allocates hid_devices only when it is NULL, with the count of the first ENUM_DEVICES response. It then copies as many entries as each response announces. A later response with a larger count, for example after an ISH reset, can write past the array. Allocate the array once for MAX_HID_DEVICES entries, the size of the other per-device arrays. The array is never reallocated, because hid_ishtp_cl_init() and the request paths read it without a lock. Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware. Fixes: 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie --- v3: - Allocate MAX_HID_DEVICES entries instead of U8_MAX, as Zhang Lixu suggested. - Rebase on hid.git for-next. - Change the subject to name MAX_HID_DEVICES. I used an LLM to help write the harness and this patch. --- drivers/hid/intel-ish-hid/ishtp-hid-client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/intel-ish-hid/ishtp-hid-client.c b/drivers/hid/intel-ish-hid/ishtp-hid-client.c index d521c520178b..47cc2fb71810 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid-client.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid-client.c @@ -128,7 +128,7 @@ static void process_recv(struct ishtp_cl *hid_ishtp_cl, void *recv_buf, if (!client_data->hid_devices) client_data->hid_devices = devm_kzalloc_objs(cl_data_to_dev(client_data), struct device_info, - client_data->hid_dev_count); + MAX_HID_DEVICES); if (!client_data->hid_devices) { dev_err(cl_data_to_dev(client_data), "Mem alloc failed for hid device info\n"); -- 2.34.1