From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380925; b=QqV9dCKnCgT+Fh5sKcGg6FJyOw1iW+bzxKOaFFqVy6B1gaRDmazVadVdCLdM8yxZ+cUh 873ekOovcxWF5Hxb4pq7scJUcl6Yx7S0kc7tg7GUI0kdIl1HPpiAKj0i2SQMFucB4f82t lYsKJcO5Tw9O0kpv1QUVJZEie3onkuFY+A9YvMVKe2gIbwGi9AecF4jHk+RHtGKZTwtg6 om2mI46Zf+FTSsAFIApTgkfI56GEV0+9ORN3cYQKSY3VQGluhJVXM0J8DEms5IGa4K8WT DU0xyA6gZb3uX0LW7Sg1NpIhcmayy8oGPbgGp10JO7B0u/Mdj6Pe6bYzyYKov7FKssw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380925; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=o3fzPKfTsykG3TLgyxNmadCL6BlmkdQy2R6TerkK0ic=; b=SOl9bpUad2gfa/sR2q1w8pL+fJQvgc2T+l6vwB00JMoTrMykTqfljYh6WzMEk2Y4mEZ/ JyARgZvoiukL59Ysc1Xo80+55i/toLxJloJ/Rtf0MdKD51VwXAh1qgib1QGWgU2p480Jz xbEMel8unZN0GC4igRF70p3iiokn6RNIM7oahtfAmEVYLRPJhxXNRrhh0FUNm69XlwulQ X4m33e8pvqW0fSssfS0tk1SpTtQMFuvgj/7jsEi5PlVEAfOK/nt57HNkJZDlPBMNkI0Jh K9UKIHqpRDNiuO+4Q/Xf7z1fSpFWbNSODmwgt9iKTHA6D8yPZjnrvILcVBjws2rpuxQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=HuJwiZEG; arc=none 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 1876E606A322; Fri, 4 Dec 2026 10:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=HuJwiZEG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 877351F000CE; Fri, 4 Dec 2026 10:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380924; bh=o3fzPKfTsykG3TLgyxNmadCL6BlmkdQy2R6TerkK0ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HuJwiZEGyvgYj0jIT2Hjeov9qV7lajXX6W0FuZC/19HbcMvoeNfH7cKfPJQeX6gc2 dfOnq4gnF4fWcnrr5fGLt3FcbkHOnQm2CL3+uvYnZ/QVOAp2e0HqeD8PLUyv0SH0BQ AWs/5mq9DtoP/t3hdxOxji6fpnYor42CkoRPEDdI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexandre Becholey , Bartosz Golaszewski Subject: [PATCH 7.3 481/742] gpio: ljca: Validate the pin index of interrupt events Date: Fri, 4 Dec 2026 19:05:45 +0900 Message-ID: <20261204100647.922331569@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexandre Becholey commit e6e2181c6920ff59ded349a100f80cf85d074601 upstream. ljca_gpio_event_cb() takes the pin index of every item in a GPIO interrupt event from the device and passes it to set_bit() on the reenable_irqs bitmap, which is only LJCA_MAX_GPIO_NUM (64) bits long. The index is a u8, so a malfunctioning or malicious device can set bits past the end of the bitmap, in the members that follow it in struct ljca_gpio_dev: the output_enabled bitmap, the connect_mode pointer and the irq_lock mutex. connect_mode is later dereferenced and written to by ljca_gpio_set_config() and ljca_irq_set_type(), so the device can flip bits of a kernel pointer that is then used for a write. Until commit 4c4e6ea4a120 ("gpio: ljca: Fix duplicated IRQ mapping") an index without an IRQ mapping made irq_find_mapping() fail and the handler returned before set_bit(). Since that change nothing checks the index. A device bound to usb-ljca can trigger this by sending one GPIO interrupt event, once the gpiochip is registered, with an index that sets a bit of connect_mode which is still clear in a kernel pointer: 175 (bit 47) on arm64, 174 (bit 46) on x86_64. The next GPIO line request then faults in ljca_gpio_set_config(). With dummy_hcd and KASAN, on arm64 (torvalds/master 067c5c24cef2): Unable to handle kernel paging request at virtual address ffff7000023dfd30 pc : ljca_gpio_set_config (drivers/gpio/gpio-ljca.c:212) and on x86_64 (torvalds/master 7e1392a42ea2, nokaslr): BUG: unable to handle page fault for address: ffffc8800f5452b8 RIP: 0010:ljca_gpio_set_config (drivers/gpio/gpio-ljca.c:212) Ignore event items whose pin index is not below the number of GPIOs of the chip. That number never exceeds LJCA_MAX_GPIO_NUM, because usb-ljca rejects larger values at enumeration, so set_bit() stays inside the bitmap. Valid items in the same event are still handled. The bug was found by AI agents (Claude Mythos and Claude Opus models). The analysis and the patch were reviewed by a human, who also reproduced the bug on x86_64 and aarch64 with current master. Fixes: 4c4e6ea4a120 ("gpio: ljca: Fix duplicated IRQ mapping") Cc: stable@vger.kernel.org Signed-off-by: Alexandre Becholey Link: https://patch.msgid.link/20261113144432.1354180-1-alex@becholey.ch Signed-off-by: Bartosz Golaszewski Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpio-ljca.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/drivers/gpio/gpio-ljca.c +++ b/drivers/gpio/gpio-ljca.c @@ -292,9 +292,14 @@ static void ljca_gpio_event_cb(void *con return; for (i = 0; i < packet->num; i++) { - generic_handle_domain_irq(ljca_gpio->gc.irq.domain, - packet->item[i].index); - set_bit(packet->item[i].index, ljca_gpio->reenable_irqs); + u8 index = packet->item[i].index; + + /* The pin index comes from the device, do not trust it */ + if (index >= ljca_gpio->gc.ngpio) + continue; + + generic_handle_domain_irq(ljca_gpio->gc.irq.domain, index); + set_bit(index, ljca_gpio->reenable_irqs); } schedule_work(&ljca_gpio->work);