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=1796383827; b=yDIJZJDWVt7k3EvF7oaTTvSVylwSl9YMCmlGW/EhZLHjADeoZix91gX4WIZjOfXncX0u 46IH37qJviXcbnChx37vngHZ2dlAADXcU6ZTkr5G9yqIHVlogghhOY2j5xE4xS/rZH5dX mJkZmnKk+4noCKEtGw76BT4OI/TwGvC8MQTqRoUxkXADUymh7J20sdCUSWiWlViCr5iYs LoRI2biGnZ3WDilpVvAOmJUb2JKet57/9HuxLSq21uOMdalByMGBopcaRtJzX5iDqHvN4 tCNxbRNAUjifh0Fg1aky1QFIFb2+WEKMspbm+PJ+keNCksU2SrU8vK8XKwzeVeKXxoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383827; 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=BfjSkM9EwF5IpUfE+8vVe083BWTnq164ngJP/AQQFik=; b=XzYvKNI5p9laChvAY0AV90chQGsEzhSccEp0bixFGjnImPHxxB426ipH61i3F8A1P2rX Va8OG9a990bJmneRYZXnAbd2lxRRhf8m/uosJ8GYqLy62x3bO7aoe0b5jV85p3uYGoRh6 CscF8c3wReSyl45hQXhKJKq3jOV/0C+n0XpKzZlKFnPONdOoipEvYCDpULWRG3HLn7Yng M3szxziSiHWbrxA7p+EFyZsNPYUJqXyclJFRBfpjSu/IN0NsD1ItMx2yjVRv7elYhByWP ro7lbTQ3aMGd/r5clz4Fje0jMSjrnqzEhwHZ7clP/lQA+TIG46qLkD0ZGbC+H3bKsvQ== 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=JImRFiVu; 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 835ED606A322; Fri, 4 Dec 2026 11:30:27 +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=JImRFiVu Received: by smtp.kernel.org (Postfix) with ESMTPSA id B66A71F000C2; Fri, 4 Dec 2026 11:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383827; bh=BfjSkM9EwF5IpUfE+8vVe083BWTnq164ngJP/AQQFik=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JImRFiVuYKlvCz3zGRG4XYK4h7hXT5+Igq9j/5RZmEqX13wE6s+h+H5Ek0/0YXOvd saSqGF/6Xfal/sM2/OJj997+FuVewSXmnON5E1X0t5jzCByA9SoxwqKKLyTRVyTyWW 8w2AWPHSXa15u8rsgcGdZVJ0Cze+TF7EuDKGZpWY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexandre Becholey , Bartosz Golaszewski Subject: [PATCH 6.12 385/555] gpio: ljca: Validate the pin index of interrupt events Date: Fri, 4 Dec 2026 19:07:08 +0900 Message-ID: <20261204100624.439552660@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 @@ -287,9 +287,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);