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=1796382390; b=X5Pwmb28qXnGXBpdmFWbxl7zDJOEBsFWRwzeZiuMQ9rQ6GYLqwWg5Lk/U4iUX0NRKcvy eOGS75BDn3rMCW4X6HS7zO5497cypxEN2oeSNjXQbXfbsDFqpKaJQEMPuyYegdRcpO3Vz DLmw+u4UI1Q9EuWulxUJLeBkFUayF3dRMOwOocwtK9DBHadUD9R+OsoLyLaYVAQlNWxCg HEZr0EEYbhE6yV5BcHsZgDR5JpZLIMD2gQaNQ2bkG4FnMXn3VnL+6FQoFiQnuEnBP0+4J 72+LPs2Ws47shRhvLRK9IlwEEw8DiTnAEQGpP+G3u2XE4LWr7kVKovv6goqZe6KS3Fw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382390; 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=n+3i7VE3ftfvfuBM1M9Ql0++JMvVGUNGUGAV5qVJ7Bs=; b=MKzS/sJ/sS47CTYwhpRD0TppJmifcN0Kn3yp8SX0XI5jR5bCgybWfuWzDN1EyOd8r0jf Rm03sD3iAvRX2JcPGMu14WGBJ3ZE1CUZk/ERKh0I5FgPMT1VWHIy85uBs9+TRQF33z6Go hDJYiDkr8g9lEk1qy0rRwTE4EpHEJ0A6AEZ5YIbNSbUBhJMD56TWpAY88Czo+R7dEp1B1 2DaiTw9XQXwr0zQAwK3oN2ekk1f6h4jsEl7ilS/0XRkuiPWp6Gt9T4qIrin/5G2yicKua XyIVRUdVjQi7Ky7RfwblF3aZpjfuebV5+D7pSEtCqaZL1BXwnOZJxDqnOogY3Y57yNg== 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=axVv91Sp; 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 CBFFD606A322; Fri, 4 Dec 2026 11:06:30 +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=axVv91Sp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E6D41F000C2; Fri, 4 Dec 2026 11:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382390; bh=n+3i7VE3ftfvfuBM1M9Ql0++JMvVGUNGUGAV5qVJ7Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=axVv91SpvtYignw3MTzkwbJER1d3H7qy9bsxIWYq3Wzxf6yrDUAY4oW6uenkaAsHY eTFa55Kay0Or74ZalLI54Irprlh5lcgAERvUiDTyTNqWYJ/t9iDHAADvAmrFjwX4u9 FI23O0h3FPTB8p29i8dK75Ph5Py/0wbSWinlJDd0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexandre Becholey , Bartosz Golaszewski Subject: [PATCH 6.18 433/703] gpio: ljca: Validate the pin index of interrupt events Date: Fri, 4 Dec 2026 19:05:32 +0900 Message-ID: <20261204100639.338432078@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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);