From nobody Mon Sep 28 07:22:51 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99FE922D785 for ; Tue, 25 Aug 2026 06:10:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787638238; cv=none; b=Z7IB90+N4TpGwy24CfGfGX79YGxjnyB0+OgsiJ/3olHw94drdbpRJ9a9BkrHMAApl5wyVWt695jWuFKL9ZmvhEcJXaJTBkV3gBcdUlHHg1aM9/Q2LBc7th6VMD4I+B1eHs8mY2KVFM2jF4ne8JDmjsRWXvQwk3jhNsGMvJK824U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787638238; c=relaxed/simple; bh=u3K+pqwlQxfkUG5TAz57N41CJMhsQtXMuS2/ucfBYcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eS0AobqVzLY8mTHtQNwj8R2BZsm6Es/B++eopw/mzQX3QwFpzc/nZusEL5/UdSn4rhVtQKmOdOdk5XhP+dtPKZa43i9vEhCOx8XPjjRp1AUijqPszBomGAhNosGb/b+1pN0i1seTmCNidUKlZTxJiV3Xyq7dkew3VsycdsnreCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Aup/bh8X; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Aup/bh8X" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2d5655cc850so48256585ad.3 for ; Mon, 24 Aug 2026 23:10:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787638236; x=1788243036; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ND0GiXjyOiahUAdjcPXqRI8sK+8IdeZXOpNWsXBTPXI=; b=Aup/bh8XpSUl4f1JT4G4KXRHwna+vUgxKcbIQ7/ty0SkVH/YuarvS/QcjmqPLSE0XB 8EDQWHQ7qEAuS7iISk1zWfT71/32bPGL7o0zJy05QoghjVb4IzZnRGCWv1AQ76INe9Dv BoILzsmOh8L/97Gq5PsilW5aumqhjkuO+Phhu+XAakyFYky11a3p/8Z5c57+6OiT973S haqMowk/Bwd027n/2xy451PZ8LALU1P5zPakr4OWIRGmWX2HpMNrPt2AZqpog5VMMVeN kOt2qNVGBn8ej8h2pHJp4TNIKxyUT3MHiqv4wGG0kSbwLE38K8fjW7kz7pfTuyAz7oEg 4T6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787638236; x=1788243036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ND0GiXjyOiahUAdjcPXqRI8sK+8IdeZXOpNWsXBTPXI=; b=laRs+mDyHIgWnNXXoQomDjL0RrXHOYbxK2TLUjNnI44Ver69cRpyk+3SgOqUPcKrJX PQYjNU/tNxR2jKrg801SOW43UCQ8Jx0zxf26vuBROJTeWoE+roXnHoT0URjIBaSVwZnZ nBnI3xj2qXTgxA0KfAwg6HTxVGC+LgVT5pmTkoVaB8WNiAzADQ0dV3RQMkJNrl0jcApL 5+QEepZ3StPV93tXbiOFxy0vSrbiUmz1xX0silrlIPoT/lqbjYJF4X+jY3cuS/EY3pmU f3AbA9jPG3YeV3YrGwvCqFKRYPXvZEtwP9DiuxvzEbC8+R2Jz3zBjN0hDoa5oyKUAQw5 EJtw== X-Forwarded-Encrypted: i=1; AHgh+RqFrPIDNOkv99Pot7kjaN22oYYYT3XC9QBx/ck+JwpknLTuksChIwZCE5cdKtGFUT0hXWjblzYGMXfJ2sU=@vger.kernel.org X-Gm-Message-State: AFuF++llp38xvjagbfN5YyAT1M+5+h0IjXeahTjqxWLEhqlRRAZkKwso W3+66gMY7aFPr2uULMo0p0jkZmUuG5ifT6f3a6mtBQVoLd8TSo/NXJtY X-Gm-Gg: AR+sD11YAy23HcmKbHBLh4PfRlvaOnGZym4TGeub+V/LaSFIN2/DMwrUADZyiOzPhAA tZh0lkz0nl1PIDvFQ4ABDe97uBtv6LMVzv36mQmDvMyzBlkY1Vm3CA2WTuVORo/D4T0hV2zOD8x mcmvCrpaDu0gwsZLM9hiFCGCgtFRl6gNR8mPk/zsr7jViUax2h188v//p/TGbglzB85wLW8FK1n Jjl798XIt7S28lKRTqB7nRFnbkoEQcqESv4mmR66BNL1X4yyURTs5LhNBznHswF5n+Vs0g+i5+J ao/Z0g606PXp7yqhfVboPQfq9KxWezbsRejYUzS9GUKEheMd4gRuPWP2MqwDXU4l/WsZ9bL3VE7 F7/NrEtjZUI7r9lrH8XVKKNsohjHEOQh+5OkopLEvP7C+aoygXHiKTeTFJVVD0H+wj7YEbgMeKB RZxh5+W7lMBKghwmfxCA6vAarNXvY0psPQ470rM3wBhE85wWCYLnETAbkn+j0mRRc6qgbOla9HL 4w+Aw8/9gHdUvh3yqnofvEQCinnaweulDWRdMRU9YBsiE0Wh6YaBR9K51Qmv3BVYutjYQOcBee5 Tz3r3XrYArxPXT9aC+eD9hvU X-Received: by 2002:a17:902:fc4f:b0:2d5:e9d5:8ae with SMTP id d9443c01a7336-2d64adf7719mr543533055ad.5.1787638235784; Mon, 24 Aug 2026 23:10:35 -0700 (PDT) Received: from LAPTOP-UUUVNN1I.localdomain (bb119-74-6-224.singnet.com.sg. [119.74.6.224]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d676408147sm23954825ad.0.2026.08.24.23.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 23:10:34 -0700 (PDT) From: Wei Jie LAW <98lawweijie@gmail.com> To: Dmitry Torokhov Cc: Wei Jie Law <98lawweijie@gmail.com>, Andrew Duggan , Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3 1/2] Input: synaptics-rmi4 - fix irq[] overrun with 7 interrupt sources Date: Tue, 25 Aug 2026 14:10:26 +0800 Message-ID: <20260825061027.105062-2-98lawweijie@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825061027.105062-1-98lawweijie@gmail.com> References: <20260825061027.105062-1-98lawweijie@gmail.com> 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 Content-Type: text/plain; charset="utf-8" From: Wei Jie Law <98lawweijie@gmail.com> rmi_read_pdt_entry() takes the interrupt source count straight out of the Page Description Table entry the device supplies: entry->interrupt_source_count =3D buf[4] & RMI_PDT_INT_SOURCE_COUNT_MASK; RMI_PDT_INT_SOURCE_COUNT_MASK is 0x07, so the value can be 7, and rmi_create_function() copies it verbatim into fn->num_of_irqs. But struct rmi_function declares int irq[RMI_FN_MAX_IRQS]; with RMI_FN_MAX_IRQS =3D=3D 6, and both rmi_create_function_irq() and rmi_unregister_function() index that array up to fn->num_of_irqs. A device declaring 7 interrupt sources for a function that has a handler -- F01 always does -- makes the driver write irq[6], which is the storage of the following member, unsigned int irq_pos. The function's position in the interrupt bitmap then holds a Linux virq number, and that value feeds set_bit(fn->irq_pos, ...) in rmi_f11_probe()/rmi_f12_probe() and the irq_dispose_mapping() loop on teardown. UBSAN reports every store in the loop body and the read on the unregister path: UBSAN: array-index-out-of-bounds in drivers/input/rmi4/rmi_bus.c:183:10 index 6 is out of range for type 'int [6]' Workqueue: events uhid_device_add_worker dump_stack_lvl+0x64/0x80 __ubsan_handle_out_of_bounds+0xc8/0x100 rmi_function_probe+0x1c1/0x210 [rmi_core] UBSAN: array-index-out-of-bounds in drivers/input/rmi4/rmi_bus.c:186:28 UBSAN: array-index-out-of-bounds in drivers/input/rmi4/rmi_bus.c:187:35 UBSAN: array-index-out-of-bounds in drivers/input/rmi4/rmi_bus.c:189:32 UBSAN: array-index-out-of-bounds in drivers/input/rmi4/rmi_bus.c:191:54 UBSAN: array-index-out-of-bounds in drivers/input/rmi4/rmi_bus.c:282:30 Size the array to match the three bit field that feeds it. Clamping num_of_irqs instead would silently drop an interrupt source a device is allowed to declare, and would desynchronise irq_pos for every function created after it. Reproduced with an emulated RMI4 device that publishes a single F01 PDT entry with interrupt_source_count =3D 7, driven over /dev/uhid and again over dummy_hcd plus raw-gadget, on v6.12.69 and v6.12.105 with CONFIG_UBSAN_BOUNDS=3Dy. No reports after this change, and the same device now probes normally. Fixes: 24d28e4f1271 ("Input: synaptics-rmi4 - convert irq distribution to i= rq_domain") Cc: stable@vger.kernel.org Signed-off-by: Wei Jie Law <98lawweijie@gmail.com> --- drivers/input/rmi4/rmi_bus.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/input/rmi4/rmi_bus.h b/drivers/input/rmi4/rmi_bus.h index 90122df21f74..faf2ebb00d52 100644 --- a/drivers/input/rmi4/rmi_bus.h +++ b/drivers/input/rmi4/rmi_bus.h @@ -12,10 +12,13 @@ struct rmi_device; =20 /* - * The interrupt source count in the function descriptor can represent up = to - * 6 interrupt sources in the normal manner. + * The interrupt source count in the function descriptor is a three bit fi= eld + * (RMI_PDT_INT_SOURCE_COUNT_MASK), so a device can legitimately declare u= p to + * 7 interrupt sources for a single function. irq[] must be able to hold = all + * of them: rmi_create_function_irq() and rmi_unregister_function() both w= alk + * it up to fn->num_of_irqs. */ -#define RMI_FN_MAX_IRQS 6 +#define RMI_FN_MAX_IRQS 7 =20 /** * struct rmi_function - represents the implementation of an RMI4 --=20 2.43.0 From nobody Mon Sep 28 07:22:51 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5CF73B38B5 for ; Tue, 25 Aug 2026 06:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787638241; cv=none; b=tLXeHtqIdYlIj5v1RENB3L4Ae3c4viTDKbdndV1hEiMSvYtv7w1cDkhII46wItuzjD4S9hEPiZYYcr8AWnqkqZ4vST7vKBBOKDer6Xu7qBOsAy1kDc0BOKhInkuFUGxatp+0lAbxUNJCzXyzIFmzPxowyELJzJS5ChpgzPH1gmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787638241; c=relaxed/simple; bh=rcJ76BI70FS7sW5RbzoZTkgt+KpJV9f2V/JttM8vlBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JB2TqrRPuuBcCsQVfE40Qgdhh++KDBO6ZOQj7HxzR7UqW1EhIPkiqNQlkPH7WOVrLqWDqyqno10zaTu02z6GAmCnr3Q9Bx+17GPhM5ZxGouHv6BXq5tPLjWNEgrjBOcYj3CjBri3ht7ktHcmHyZvQSvbbMuVkzjKIdgeCLxW1qs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bl7CLEqo; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bl7CLEqo" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2ccf2360620so40730045ad.3 for ; Mon, 24 Aug 2026 23:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787638239; x=1788243039; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=P6bumZFW7wx8mN2lBfLuzrWtTAkjtdW9StYLJpSBfIE=; b=Bl7CLEqoOtX8YvduOcDGHFiXBk6fP3jzosjWJsXZ2Cjbee0Pn/jQWzlDshy9mgqRAN b+fXS7k/SF0PrYXh9YfnUit6Fu+bn9de7s/S+CeFnhOi1rhvgHce+Z0NpIjtDZl9KZBp omeeiVIpTiorIaL3v06BlrYprUiYauD60XJO4UhryqjIgTxOm39hJ3ywbD8jjyJ0SEWl v3oiPEQqtxVu7kqwahmDk+mo/bu0YU9ffDRbGLayTesEYO+thuY7J7Esg5ZQFf/OVbbF w4ABqeuM7voOLvNEjOgi1o/NJY5IFUrHQ8fSCVQ3iNnecF1Gd5WZUnvqflot0jhgfhRK gjbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787638239; x=1788243039; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=P6bumZFW7wx8mN2lBfLuzrWtTAkjtdW9StYLJpSBfIE=; b=QB8f32QIn/Kbw7TNTUDDsQmYEB3wQ6VTiu9s3OW0LJ382Ddzw9Okifo4y8nKO1/tuw NpC9gBzfOxEJj8Em+e12SN1lHyUY1m2MCU7Rson3zUSx9gvtG9DcC0um6S6Ad8agbung BbBz3WphpomyimayPFQdqCb0g3+2FDuILurUZyCIIifymjYJh4L3Qd/8C9mPEfyPJJ++ w1KEnalSY5oIo2AeU0qgNObmnLEe3S8fZpvu8/nM53R6HqrvHTC2r/LIYwy6TvWoalQI ochdSHJd3NqomIw2BGcql6ChIPMO54MfRrGF1BkQUpbYCvuWJ1Kzd9hlcS0fl2qtQ8g/ +4DQ== X-Forwarded-Encrypted: i=1; AHgh+RoQIqCH8TYL2spSJi74hZN8FID3Qkp38hA4OOWOeWgivvIm3QksFGuzfon3TcaNVsHGV+dwUn8U9+tRIWc=@vger.kernel.org X-Gm-Message-State: AFuF++ld8o+6k+S46QvjO541OzUQd1N+PsS91Zl7gKgxOv24aW4hCvsJ qC8lweGssMALxTaQB5dTlCF2wfObQkimc3dFhKsps7dx1tWtdiD04gHu X-Gm-Gg: AR+sD13+KQfZqFywtl/bu0TyF6PFw0u7KMBMcPaz48jxy/YIhlxGwk0/0MWVqHJJg35 pab9aNx/KOd7DIF4S5NEC6nTN76SQWU5ENrMjypeiePCHQEA4Hcx8+dGC5iw6zrROWqdQkFp1F5 DQlOAV+1buNxS73Xmyxyj5fFrc5AJ+I3D38LKEFIGBIKuwxfwCArro0JsmFC/owH8T0De4QzoLB CyvfVbj4fJjCQ6aMO8WmmrWtFM0ZCQZpqGgkae2/t+EbYDvy+nrYFquRTeBvXt7l4XP8V8FUVwf Oqces3erUvoYhU9g3IADfVpP45w9sX+nzflLOMVzs9gb0yfMXUYFPRd/oEGxnvsiMzSfg4Y+G6R xYUSMGTBt5BcInap5QdFbx7MyVE4+Dl/j1w1oMSZELachgMv9BC9MQS6STDtsA8ogvIgBajA2HM PlFkKe6Q8a0EHW0BvXVpyhDaBUxfW8d6oyHr+pihJRyTI7PgReGicjlzWfgEidZto7ydWjHSfij spFeJ9lwmHAbyD3rVxIaFPz3uHHu4lj5XeEN30ldl+2+oVHeWEjAum7FRB0mytm8/iZ8d7SWyxO OGIcMrCGuAqkUkY8B1c901nh/HBWthwBo3A= X-Received: by 2002:a17:903:1843:b0:2d3:78c2:1f19 with SMTP id d9443c01a7336-2d6dcbb1806mr83496075ad.9.1787638239035; Mon, 24 Aug 2026 23:10:39 -0700 (PDT) Received: from LAPTOP-UUUVNN1I.localdomain (bb119-74-6-224.singnet.com.sg. [119.74.6.224]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d676408147sm23954825ad.0.2026.08.24.23.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 23:10:38 -0700 (PDT) From: Wei Jie LAW <98lawweijie@gmail.com> To: Dmitry Torokhov Cc: Wei Jie Law <98lawweijie@gmail.com>, Andrew Duggan , Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3 2/2] Input: synaptics-rmi4 - reject a PDT that grows between scans Date: Tue, 25 Aug 2026 14:10:27 +0800 Message-ID: <20260825061027.105062-3-98lawweijie@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260825061027.105062-1-98lawweijie@gmail.com> References: <20260825061027.105062-1-98lawweijie@gmail.com> 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 Content-Type: text/plain; charset="utf-8" From: Wei Jie Law <98lawweijie@gmail.com> rmi_driver_probe() walks the Page Description Table three times, and each walk reads the table back from the device: 1. rmi_initial_reset - issue the reset command in the F01 entry 2. rmi_count_irqs - total the interrupt sources 3. rmi_create_function - create the functions and set their irq bits Scan 2 fixes data->irq_count, data->num_of_irq_regs and the size of every per-function irq_mask[]. Scan 3 then accumulates fn->irq_pos and does for (i =3D 0; i < fn->num_of_irqs; i++) set_bit(fn->irq_pos + i, fn->irq_mask); without checking the result against the count that sized the bitmap. Nothing makes the device answer the third scan the way it answered the second, so a device that reports one function with one interrupt source on scan 2 and a long list of functions on scan 3 walks set_bit() past the end of the flexible array at the tail of every struct rmi_function: BUG: KASAN: slab-out-of-bounds in rmi_create_function+0x560/0x930 [rmi_co= re] Write of size 8 at addr ffff888110c92b58 by task kworker/1:2/129 Workqueue: events uhid_device_add_worker kasan_report+0xc6/0x100 kasan_check_range+0x105/0x1b0 rmi_create_function+0x560/0x930 [rmi_core] rmi_scan_pdt+0x190/0x3f0 [rmi_core] rmi_init_functions+0xb8/0x320 [rmi_core] rmi_driver_probe+0x31e/0xbf0 [rmi_core] one report per corrupted function object. The same unvalidated fn->irq_pos is used again by the set_bit() and irq_create_mapping() in rmi_create_function_irq(). Validate the counts before the function is allocated and fail the probe instead. The check is exact, not conservative: when both scans see the same table, the running interrupt total plus the new function's count is exactly what produced data->irq_count, so it never fires for a device that behaves. Placing the check before rmi_alloc_function() is deliberate. Since commit 58d42ec10b73 ("Input: rmi4 - refactor function allocation and registration") that function has already run device_initialize() and dev_set_name() on fn->dev, so disposing of a rejected function with kfree() would leak the name string and skip kobject cleanup on those trees, while put_device() on the same path broke on the pre-refactor trees that stable backports target: a kobject that device_initialize() never touched warns and its saturated refcount keeps the object allocated for good. Rejecting before the allocation needs no cleanup on any tree. Reproduced with an emulated RMI4 device driven over /dev/uhid, and again over dummy_hcd plus raw-gadget, on v6.12.69 booted slub_debug=3DFZPU and on v6.12.105 built with CONFIG_KASAN=3Dy. After this change the same device gets rmi4_physical rmi4-03: F40: interrupt count changed between PDT scans (pos 1 + 6 > 1) rmi4_physical rmi4-03: Function creation failed with code -22. and a device that answers both scans consistently still probes normally. Fixes: 2b6a321da9a2 ("Input: synaptics-rmi4 - add support for Synaptics RMI= 4 devices") Cc: stable@vger.kernel.org Signed-off-by: Wei Jie Law <98lawweijie@gmail.com> --- Changes in v3: - Validate before rmi_alloc_function() instead of freeing after it; no disposal is needed on any tree this way. See the cover letter. Changes in v2: - Dispose of the rejected function with kfree() instead of put_device(). See the cover letter. drivers/input/rmi4/rmi_driver.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_drive= r.c index 5d49a9021c7d..f66be55677a9 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -885,6 +885,25 @@ static int rmi_create_function(struct rmi_device *rmi_= dev, rmi_dbg(RMI_DEBUG_CORE, dev, "Initializing F%02X.\n", pdt->function_number); =20 + /* + * irq_mask[] was sized from the interrupt count collected by the + * earlier rmi_count_irqs() scan of the PDT, and irq[] holds + * RMI_FN_MAX_IRQS entries. Nothing guarantees that this scan sees + * the same table -- the PDT is read back from the device every + * time -- so a device that grows its interrupt counts between the + * two scans would push the set_bit() calls below past the end of + * the flexible array. Refuse the function instead, before anything + * is allocated for it. + */ + if (pdt->interrupt_source_count > RMI_FN_MAX_IRQS || + *current_irq_count + pdt->interrupt_source_count > data->irq_count) { + dev_err(dev, + "F%02X: interrupt count changed between PDT scans (pos %u + %u > %d)\n", + pdt->function_number, *current_irq_count, + pdt->interrupt_source_count, data->irq_count); + return -EINVAL; + } + fn =3D rmi_alloc_function(rmi_dev, pdt->function_number); if (!fn) { dev_err(dev, "Failed to allocate memory for F%02X\n", --=20 2.43.0