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=1796380997; b=CMLTEdoCRRZqQh43IdOnIhMHvSUbq0I60g2/dQxs2DTm+C7l0IVjCIrIhbDb8frotkOX SjGDvOnuJDS5IcbHHJsQ8WSxNquQRncEUpC2ZYE5Tt1ZNBhzqnxXMGOZX0Yos7pkKu3C1 83JrcHprqx3BQceLKfgsPGpdgf8LRJmc1oM/JD5LcKCrhucAP51y7bCVOCJx2spNtwPXT kds00aaCkiVb1bMiMcnL0zKE6oyIMToP5mJkXENH/4cWEjet4Wyea3qbKfAy/rQqG3CSp hcdiGR6AnwNfuy1MP1W8R4x46neUOxTN3DqRurb6GDbLWUYQcCDTGizZN2s+dDKnN4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380997; 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=EL7re4Ll+Vow7P24V8AIzXQkzvNJcs1y1pS2q6xXBPw=; b=rIShTDCmpF7SBcCuYMonGqfTbkgXs9HbfDMPcRorXsay3RDAOGaS9yYI4CNiMRMqn+x1 u6ACehApuPOMQobdxgXhIOPVFT4ccqmpfcHBO5Tf3RPvcHWg97ngn9JAr8PyrL/E6b6et ooIt2Vf3pQ30LUyPoEVg0PXrvNP7Vv4aIWrT/JyzdJkB7FVdz8Br3WpEWoZcq7R/y9XHV K8FWKA3B7Q3Osz5ckowSY7q1gNrafbPKBiSuncSlctTWTI02DtRT7U8utmfZ4mHCLg6BE OYu1U+M378f73+C+D+i0KDUsx0raQ8VtkPKGyLU6CWUW00o1U4AeQUeRSDtTdpK3z0w== 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=rT1NSqDS; 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 51E6E606A322; Fri, 4 Dec 2026 10:43:17 +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=rT1NSqDS Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCA7F1F000C2; Fri, 4 Dec 2026 10:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380997; bh=EL7re4Ll+Vow7P24V8AIzXQkzvNJcs1y1pS2q6xXBPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rT1NSqDS9kLrFSpG1PNUcCvrRYHytcuvHeJNzEm47o1GsAC2LcF0DFKqm8GlsIZiR G1thznP51Fa+K3RoO+hbvSm6pWIBfeQIXN9bjJwP3SNV11p5K/N8Y1Zwj0HW8fnGHk cXb3z7GmNNrEMPzlusyqA1Dd+QpnMeDi9hep4cJQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bartosz Golaszewski Subject: [PATCH 7.3 486/742] gpiolib: keep the line state workqueue alive until device release Date: Fri, 4 Dec 2026 19:05:50 +0900 Message-ID: <20261204100648.047861055@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: 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 @@ -2762,6 +2762,7 @@ int gpiolib_cdev_register(struct gpio_ch ret = cdev_device_add(&gdev->chrdev, &gdev->dev); if (ret) { destroy_workqueue(gdev->line_state_wq); + gdev->line_state_wq = NULL; return ret; } @@ -2772,7 +2773,6 @@ int gpiolib_cdev_register(struct gpio_ch 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 @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -901,6 +902,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);