From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366605; b=YDx1sO2iLD0M3vrLb18PKQ96Gkvpmde1tsbSyqt9VCTm4utd1l0EWMgCIbWRYhUYgvAY zdfof0IITP92bEf34opGm2zWIeH0o7PXMCtxceuxpFvNxNeq7nHTwqO7cOeZtLG/Bmo3w E595YXUaNeT037bbRGwz6lIeSQppUoBcxWdhjA/+4pK5MuvIvyeyqdGo5EHeAI+OFis3Q 67B++S7Bs6tyXYTk8J06jgSMgicQTkew6dVlsDTrIPZZbViH6vO5PWyZqKRQbxtJDh6vZ 5/MwNqEU5UA4nXVGz0RLAMCVwrJRD1dAi+r28Vs9xcTxnN0EwWF04alzifnizggefmw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366605; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=zuwDwbpzNhMeByxb32RgwRzB7R6FAhhtNE7JSe7PxPs=; b=z/pwPvKOzxiLfbm/c96nUFXA/gUhEeOzU8mo8Ttp+T/5D6d/+D+CKQysIHroDKUVLOnM zkZknEGC1Q5bZQQw+SK+3KMn+oTAYn62Bl2ACN0qsc4fQjSQVLHgwY9LyfyJnbUuTF7J2 yZIpDa0nhZAX0DieE299wGJ3KjtXfLlNDdooVyjISTidVwb6PcYyLzDR9XE1Ql5xe6W37 th8GyKNnmVWx5Nhu4GZY1k4s2hd9dE42dJyiax0T8i/4z/effy9VSoLXQwS7oWfLAS+/O aS4viIp2RxpeNiHnjbBGIEwwL9P1ZKFuJQIRakVHuKt9mQaE/WO+TR5xcKVvmgZgi8Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nsZ6X13N; arc=none smtp.remote-ip=192.198.163.14 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44118606A322 for ; Fri, 4 Dec 2026 06:43:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 44118606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nsZ6X13N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796366606; x=1827902606; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zuwDwbpzNhMeByxb32RgwRzB7R6FAhhtNE7JSe7PxPs=; b=nsZ6X13NzPag7sxtQLGKLBHdln/0i+FkALcjHI9bThEM31ZwDH4YBN1O DSve4tlXB8G0Lok3pY7pLDvw5IheYCh7CLMMM1TUgfpToK0kSSaOtHW7H +cz2x5e4ThtZeUCY7rZYp/OSzANr3JjXdJYncRap6MPfO0QTxkH7+UyRK Ovuh9ltl6LR70+yzmRdLSAedNnVmk8MJVXdk9Se5x0AMPaP9953Gs61IR 3CimFf8j00qeCCJX2VDShbfvA77FxC+nBD2f8+3eopeLCIhwJRpnOP8GY rPgfNfTKdqjyuxK07r0wtSxfsLkbzZF9ZhnDpJqWdWFQ3HwqyK/sgDgLL g==; X-CSE-ConnectionGUID: Or928Kv7S7u9KVCxEeHs+A== X-CSE-MsgGUID: p895EcMaS3mSEUj7wzVTMQ== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5321735" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5321735" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:42:50 -0800 X-CSE-ConnectionGUID: hXUGvuIVRF2bHBr3KU/ShA== X-CSE-MsgGUID: 2GWyPljoTs6LCcE6ODnBbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="14293164" Received: from lixuzha-desk.sh.intel.com ([10.238.208.185]) by fmviesa007.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:42:47 -0800 Date: Fri, 4 Dec 2026 14:42:45 +0800 From: Zhang Lixu To: Maoyi Xie Cc: Srinivas Pandruvada , Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Subject: Re: [PATCH v2 2/2] HID: intel-ish-hid: Allocate hid_devices for the largest device count Message-ID: References: <20261125090633.1385386-1-maoyixie.tju@gmail.com> <20261125090633.1385386-3-maoyixie.tju@gmail.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-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20261125090633.1385386-3-maoyixie.tju@gmail.com> On Wed, Nov 25, 2026 at 05:06:33PM +0800, Maoyi Xie wrote: > 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. > > The count is one byte. Allocate the array once for U8_MAX entries. 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 > --- > v2: > - Allocate the array once for the largest count and do not reallocate > it (Sashiko review). > - The subject changed with that. > - Shorten the commit message. > v1: https://lore.kernel.org/linux-input/20261123092816.2200718-3-maoyixie.tju@gmail.com/ > > 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 d1eccdc37e7a..0837af243904 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_kcalloc( > cl_data_to_dev(client_data), > - client_data->hid_dev_count, > + U8_MAX, Personally, I'd prefer MAX_HID_DEVICES over U8_MAX here, even without [1]. hid_devices[] is indexed 1:1 with report_descr[], hid_descr[], and hid_sensor_hubs[] in struct ishtp_cl_data, all of which are sized to MAX_HID_DEVICES, and ISH firmware keeps the enumerated count within MAX_HID_DEVICES as well. Thanks, Lixu > sizeof(struct device_info), > GFP_KERNEL); > if (!client_data->hid_devices) { > -- > 2.34.1 >