From nobody Mon Sep 28 08:52:22 2026 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 6C017419302 for ; Mon, 24 Aug 2026 12:27:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787574466; cv=none; b=PXoaIUGVxIvsy3Qvhh65s6/8ACLhYctGhkZFFDVt9mO3WJID1hi951J7QKBfkTB5ytJC5EE6NQJSMhB6GqjhNVvCSX04YJ7IWs0SVkd5ac0r7D4uLV/T9a0gAA5xqBtQQ9w2FCDPzXeblyJflll3JOamp3S+/G26sPokCsbolJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787574466; c=relaxed/simple; bh=WZE0UAjryG3LKGmJlWlrF4NVV/WeS+t9+KyPhRYEdqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WIl/8sa82DYSMbLU1+rMeafK9ywSgyYzB73G/rya08jjIAjgifOLv5ul6R73TBQ73aSFPqYXxhK3pyXqN9Vy48fcKY9ztqGYNUibmRHZ706z3tPWgPT9rqaNXJoVjPRR6N2YaJ82XWGiH7n4V78qmLjjfK4/OQN6VinGoAsVrbM= 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=mOdtWIR8; arc=none smtp.client-ip=209.85.160.174 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="mOdtWIR8" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-51c8e2e39easo34170791cf.0 for ; Mon, 24 Aug 2026 05:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787574463; x=1788179263; 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=EB3wFOXHlXyIKQOwKFQXlogVT9fQ7bqKTlFugd3hmJ4=; b=mOdtWIR8Vuc4hJv29I4T9WGf9AJPLc57Qvad8aeBK5UtrjIQ59S+lbGOJkNKfIy19R wEzMfSU/FLcwJKSSqTyJ3EH7m3ONVfObO+VhFAojK1/v53bM8D9o4kGqcGs1KhblQrop 6nS8c9tvn6USnMmiRliSsxC8uBFBx5Mr6VztFjvPMO1lJcfmI4AZixmuLcYQdAIYA8VU rm5eP6OEPzCCDK3oOi90bH3yRNmanTp30fAUdVbXt53iQqnAvWOvXaXmWmgrp4KOV/FO ljUVRIRUt6uctLDD4KoS166WSihSG2iXZS6Ck2osRxeySojnCpwmSYWLo+RaFVbZyTo6 ezVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787574463; x=1788179263; 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=EB3wFOXHlXyIKQOwKFQXlogVT9fQ7bqKTlFugd3hmJ4=; b=YgjXOlGIr3IWaX0AGB7CI3rfdbeUL6V+etQFo7YlV/IJfwRtD5JTG7IUlO5t3FmvS4 JX3470N6Esa/IzZStudmU/kZOgoxsv/EdO0sMqJkAIBEa1p1npO0PHUc0i5IT8IseG53 31DXR5H/F796cDcWcxM8ttpIHwuPnU986hvV6HslI/zVih4RqJ00P+H3qwrILzH0Yb7z zm3uzWQ1r8wXiUFcVHWPVEcxTyo7nV6jJ15bbR4160Doux1g8FUkhXYp9SET+2mlx6HS mW4dQybp5PUfOv2MySmmETW/E0k4XUtLZNNBeRSw/9GhcPWYcQEpSLlaBUQTBx/1rIry Pw8w== X-Forwarded-Encrypted: i=1; AHgh+RqZxW5pn9ijTFXllErUBrG9Qwlgi9Vskl0EMs1G8em+y+xp7c0LqiBO8bEIljoJKiMie1i7P4CvTtKnhiQ=@vger.kernel.org X-Gm-Message-State: AFuF++kWXwoNL3/cukq4LjLYLvMtQaspZbrS9ymawL8BSjrba653ZVMh TZ3MTgOYWWd7DNRk1XykVJvjdmwt1wR+BFHn7hcgiN/rIU3TTWkZbBn/ X-Gm-Gg: AR+sD118Rb2peW+AMEZVAm/DN1Xj7RWjPYB24UdPVuClUrEuI9m/2PupbaFP7z4u1oL F3i/2VttMHhndF2NfqnGV808EKXXaeJQ25b6kY5qWCSG/IMnirmDuvUP1yQaB44VtO7e5d1QIW0 wiWSpgzM2nl1cLUSQnOfCmuq5HkZq6RtSuL8GACWxXapSTGr9LGz0xKFugek5/Pond5grsv+WaK iQn2crU6OVj6nSgORWv6TsoyF+wtq9XLOUMDR3qn7TeyFvLFZ90WpO+1Kw4vv8Vtj6BApmWe5/7 giRm4ShSKqcyZVAH8AzT0BP5OXWDsMXxSLTHgtSNeu8TKYzGkBuTRwNEBgWK2+lzogUoA/XnDU1 k25lJoloTFGoV+4YAuj4pI+sqQkM8DCHLgBgbz/Rjr1YTbELrpQic/TJUu4SdjK5vD/r42igaF8 o0prcz6bjdYY19UMdwNVk/QP7XisIaS0zMaQAO6i4SKmLldWr2pfmGevmq2Gg97sTaVQPx48RsM tIB0R1S8XRz1YyBa8GHp6QQFzphSEV6onjVouSqLJYh+X23UtaaRpVWPk9RcX2xeRjP9BCPKvuR AfLdghSGUM9SPgukP4xX7OzK X-Received: by 2002:a05:622a:481a:b0:52d:78c9:9377 with SMTP id d75a77b69052e-52e09ce9a34mr177469481cf.36.1787574463031; Mon, 24 Aug 2026 05:27:43 -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 6a1803df08f44-90c93a4f093sm60745276d6.37.2026.08.24.05.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 05:27:42 -0700 (PDT) From: Wei Jie Law <98lawweijie@gmail.com> To: Dmitry Torokhov Cc: Andrew Duggan , Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 1/2] Input: synaptics-rmi4 - fix irq[] overrun with 7 interrupt sources Date: Mon, 24 Aug 2026 20:27:32 +0800 Message-ID: <20260824122733.76321-2-98lawweijie@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824122733.76321-1-98lawweijie@gmail.com> References: <20260824122733.76321-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" 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 08:52:22 2026 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 4AE8A41A4F3 for ; Mon, 24 Aug 2026 12:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787574468; cv=none; b=EhVci3o3YQNo/01fH31mb/yLz14wwSbmZ564lRqVTMtkY5SORRqzF0GI5LM/pV37RQWy1iosbOOewd1oWkhnmJebsZt7dxnNvGExf68G7GlBLa7Rbykpagy5Rrjmenb/2qbTYEFzwpEBwULoXRZyxsxILVo6JIFGHZUgU/1HLEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787574468; c=relaxed/simple; bh=C9ljMPmOgKzzGRi9lsltS32itRvLvS7A9iFne2T9euI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eSkIOtrPFG4twRnuDv9/nYkAYbALAeH6AWzZssjS99H+AXo5PL9WM4kQeKEsrtOMvQRUyzaX0jqikuRxOXKhcHSIpqFxIqaq3/4OQMGZB+2NW4vvam7n30P9Lji1moxaY21fOO2kukmp+laJVAMtzO1GFcImdMAdBZQJ8MXsq7k= 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=LD6InFZZ; arc=none smtp.client-ip=209.85.219.44 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="LD6InFZZ" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-8efcfdb2b43so22059546d6.3 for ; Mon, 24 Aug 2026 05:27:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787574466; x=1788179266; 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=dCP4SoxE8UtElbaGnJtG7fQSm7CuB0xZVB5xSM21nbM=; b=LD6InFZZwRepGmXD353W2OKtohFRJRAvrHrV58XM7gacs5SvtttuOzL+H+RVQp109V tJm3v+7g694vBv/u4szLqSq+AThHROGsaVctI3BPxC34vEv0v1QwszhNHC2i9BN+1VBo mPmcr+xLSQjhejXnA1cNPllAsSAN6MIYCGB79b1XFeoBlcG421iO21S0rc0RmnmNPUXm nAdlqScKD0qdGVVp6Nc/okrGRBJG/SnUHz2H/hRwuu/UifZcVHScgWunYMUXfjPG3mIn zOcYLX4bIouePG+fv1s3vu0cfj6MBueFbvAY2FOsAWcZZH0Qa8ESosuwbbOte5ZrE6B9 cetg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787574466; x=1788179266; 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=dCP4SoxE8UtElbaGnJtG7fQSm7CuB0xZVB5xSM21nbM=; b=U94DmBYhBi4/lfGNcxf0Ca3ROKWkRmEXksbYgE/H3sYH8kc7xjS1BfcfivXhS5RsyF Nu9UvBW1bzyY9kqNNSWasqUhJSPthoqDQ/UppeZrsSez4QdjXD1iV0U8qkQt2ckusLiE WqkVDStYh/P+EKegofveNYPuHXqk42UcLPTnBaYlEaHuN1jKc9Yg6x4uVvrshkSjF+6G I2/nkp/K6X55uYTl0HNnh/rMBniejWt9DZdAOulBDSF3XNrAGwYcXH5Zk1R8K6nD5qJy sSe83b/LQQkCJbwPIWH88IGfNTaM/sJD+jCGxsUwp79XX0HGXLDQoZWIm/lwqxf71uE/ 8YbQ== X-Forwarded-Encrypted: i=1; AHgh+RrEI8L0BtcB0Y+7piF767P/sBrxCx+hs4hJvRoIDohkyRT24b/zVQPGt2J1J6Fi9buIZuNfXVxKOAX1zUo=@vger.kernel.org X-Gm-Message-State: AFuF++kPpuks4xULq8GFMngwHzFaTUk0tlSM9mcVt5ZHQ+bWoe8iXuHA FxBCXtljKoDtwWjzw1NegG6aqBSAlVRyone62p/yzzlR5W/t3p1u6bRO X-Gm-Gg: AR+sD12l6SHm4TZpBay1WiYMT873/Lc/hQdrmGH56wU5v/OzvN2dR699VeOibqaL75j b2qg/Zm/AGLuETvRHryuxDQ2iKp1q+fWp4/0a18XAlyD1X+ObzE73gO/xp8DBen3mz2bYJ6kWJu b8BW0vuEFuY7n6/TmGKwBtSCD6o+KaEVhGtsb60Bf6G4ig/2BQLjEQALr690yKFdN7e+IXUYpTk XyAUMvquAKqszQ1EVtJKhzxezIYAZ+eUlGHbhpS1XhnMErcso6xASCKjswTJiEDRlHkJ2Msjp2k khUJUo3v8hPCMIHMOZhMmqQob9Oye+CbysfecxlD4BmeRiazooxc8wTVe+4XcQWrvH1qui0cNIA 9pjb5VK27KN8xRekdXKKBX4hhWcf8fMF2DFW/oMKjGhlFXu7BSZQMObjMSJY4+xhrajhKtcFzUe 29VO36OvYyJdB++9sb30mNDZ4w1n4FYgmOXn/yd4AGrIokBvOAeq7KmEPY4x69xi9qiJ+XWv3wu sxa7Gq5uwymKsMJ6+URH0FIEeqrvbQ1tSpqzkhFaGiDIEKp9fosol3YzNwW21dnDPrXP8f2mZ29 4lVthHxgSSBmjPOnVCkOALEiuxOn1fD69uw= X-Received: by 2002:a05:6214:508c:b0:90c:576a:db55 with SMTP id 6a1803df08f44-90c8fa36499mr169713346d6.21.1787574466014; Mon, 24 Aug 2026 05:27:46 -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 6a1803df08f44-90c93a4f093sm60745276d6.37.2026.08.24.05.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 05:27:45 -0700 (PDT) From: Wei Jie Law <98lawweijie@gmail.com> To: Dmitry Torokhov Cc: Andrew Duggan , Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 2/2] Input: synaptics-rmi4 - reject a PDT that grows between scans Date: Mon, 24 Aug 2026 20:27:33 +0800 Message-ID: <20260824122733.76321-3-98lawweijie@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260824122733.76321-1-98lawweijie@gmail.com> References: <20260824122733.76321-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" 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 position before using it and fail the probe instead. The check is exact, not conservative: when both scans see the same table, fn->irq_pos + fn->num_of_irqs is the running total that produced data->irq_count, so it never fires for a device that behaves. 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 The rejection happens before rmi_register_function(), i.e. before device_initialize() has touched fn->dev, so the partially built function is disposed of with kfree(): put_device() on a kobject that was never initialised warns and then leaves the object behind, because the saturated refcount stops the release from ever running. Signed-off-by: Wei Jie Law <98lawweijie@gmail.com> --- Changes in v2: - Dispose of the rejected function with kfree() instead of put_device(). See the cover letter. drivers/input/rmi4/rmi_driver.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_drive= r.c index 5d49a9021c7d..8dcf088a7a81 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -899,6 +899,24 @@ static int rmi_create_function(struct rmi_device *rmi_= dev, fn->irq_pos =3D *current_irq_count; *current_irq_count +=3D fn->num_of_irqs; =20 + /* + * irq_mask[] was sized from the interrupt count collected by the + * earlier rmi_count_irqs() scan of the PDT. 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 these set_bit() calls past the end + * of the flexible array. Refuse the function instead. + */ + if (fn->num_of_irqs > RMI_FN_MAX_IRQS || + fn->irq_pos + fn->num_of_irqs > data->irq_count) { + dev_err(dev, + "F%02X: interrupt count changed between PDT scans (pos %u + %u > %d)\n", + pdt->function_number, fn->irq_pos, fn->num_of_irqs, + data->irq_count); + kfree(fn); + return -EINVAL; + } + for (i =3D 0; i < fn->num_of_irqs; i++) set_bit(fn->irq_pos + i, fn->irq_mask); =20 --=20 2.43.0