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=1796382402; b=pszNXKYHnICo1rNO0qMjQNhdfwM1CBrzwAMSaVw2kaOdcL46JSalZ8k66k56uZmcIt9o C5FkFxi6wozXkiKrT/GIXcKXmJ2gTahtcQS/c1b4htidIctfofxHHR0MlESdVsEW+ZwSl 0dPWzQ310fNjmGYFhPXQT5mJOmWayqDxtAHsVNruV9gOvJuUKteiytHuhZXsEz2KDYJVf V8msWOjepc3J1qxa8XGPj8/d/QGZiwhyT+9QBZGg7MVPfYuFHisPsi1j6ku0soAxJhyvl SYV46Bw34KiMqLbhfP/CmTwA1Ocsu/UdF5FYn+nrqtsmPFW0Y6EcgcPjxSyq9WMWaVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382402; 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=Gl+fuWCis8evOxNrd33qt1YMMx23bvgyN7LmYTl1zDg=; b=ruoMbhc4ietqR0CoAXcnC2j4b7O7EBfAU7RcF4z6ONMPf4c4LSvtHTIbxYry7yM++OE4 7B5VYU8ZzZrnJ/ysPU5GgXrxQLCyNTcUwBk1+ZxjP4saFngWbAYGQYW0WWoDCJ1oMcA0E b6NMuedf5i6OXGAGdCPN/WO3DL6feRneMGytJdlkIKDCHccY/IHvnVSvNPLOQeuvWgXet WoaaabPrs9W7aRepKpGkvzv5qD5vDVM+/lDySGl3rBi6Y0bIFWYRkhP+EpIg59PXbL8jp Ypmstx06FtTytcA/YJS5ASllueQyGQOpW3+bUPnXSvKydOuHKA1iAqO2jsLb4fUFwvQ== 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=OCSz8tRA; 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 103BB606A32C; Fri, 4 Dec 2026 11:06:42 +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=OCSz8tRA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E7981F000C2; Fri, 4 Dec 2026 11:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382401; bh=Gl+fuWCis8evOxNrd33qt1YMMx23bvgyN7LmYTl1zDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OCSz8tRAnpGIx8LTu0ixWYSHxkcAoNMapEspqr3lt7CjhWjy6i6lD5c1En7Z2q0l2 0JWFSXW3aRvFzST4o+CJfC/V+Rb/tdpQFhnGmCD+uSlrY0KMBkmNfbQsSf5iyo9qfD j3+9lsZFEwOP+VvxX+Te4CxS6Jn05n9P2g6f4UQk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bartosz Golaszewski Subject: [PATCH 6.18 437/703] gpiolib: keep the line state workqueue alive until device release Date: Fri, 4 Dec 2026 19:05:36 +0900 Message-ID: <20261204100639.439680081@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: Bartosz Golaszewski commit 2e002a1d05b1979006f3c46eb6cb5cc36e5630ac upstream. gpiod_line_state_notify() races with a concurrent gpiochip_remove() which unconditionally destroys the line state workqueue causing a use-after-free situation where queue_work() can schedule a work on a freed workqueue. Keep the line state workqueue alive until GPIO device release. Cc: stable@vger.kernel.org Fixes: 07c61d4da43f ("gpiolib: notify user-space about in-kernel line state changes") Closes: https://sashiko.dev/#/bug/linux-d0e9e518-2348-4fe3-857d-f3d61a42f159 Link: https://patch.msgid.link/20261110-gpio-line-state-wq-uaf-v2-1-ce6d8266656e@oss.qualcomm.com Signed-off-by: Bartosz Golaszewski Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib-cdev.c | 2 +- drivers/gpio/gpiolib.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2848,6 +2848,7 @@ int gpiolib_cdev_register(struct gpio_de ret = cdev_device_add(&gdev->chrdev, &gdev->dev); if (ret) { destroy_workqueue(gdev->line_state_wq); + gdev->line_state_wq = NULL; return ret; } @@ -2866,7 +2867,6 @@ int gpiolib_cdev_register(struct gpio_de void gpiolib_cdev_unregister(struct gpio_device *gdev) { - destroy_workqueue(gdev->line_state_wq); cdev_device_del(&gdev->chrdev, &gdev->dev); blocking_notifier_call_chain(&gdev->device_notifier, 0, NULL); } --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -858,6 +859,9 @@ static void gpiodev_release(struct devic synchronize_srcu(&gdev->desc_srcu); cleanup_srcu_struct(&gdev->desc_srcu); + if (gdev->line_state_wq) + destroy_workqueue(gdev->line_state_wq); + ida_free(&gpio_ida, gdev->id); kfree_const(gdev->label); kfree(gdev->descs);