FAILED: patch "[PATCH] usb: typec: ucsi: glink: fix use-after-free of ucsi on remove" failed to apply to 6.6-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 63b269ec537dc0fd26d0bd64872c26860d108c9d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026100540-barterer-those-a743@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 63b269ec537dc0fd26d0bd64872c26860d108c9d Mon Sep 17 00:00:00 2001
From: Fan Wu <[email protected]>
Date: Tue, 8 Sep 2026 06:02:15 +0000
Subject: [PATCH] usb: typec: ucsi: glink: fix use-after-free of ucsi on remove
The pmic_glink client is released by the devres cleanup, which runs after pmic_glink_ucsi_remove() has returned, so its notification callbacks can queue work until then. Work that runs after ucsi_unregister() has been called touches freed state: it dereferences the connector array that ucsi_unregister() freed, or registers and unregisters the instance a second time.
Disable both work items with disable_work_sync() before unregistering, and unregister only if the instance is still registered.
This issue was found by an in-house static analysis tool.
drivers/usb/typec/ucsi/ucsi_glink.c +13 -2
@@ -362,6 +362,10 @@ static void pmic_glink_ucsi_destroy(void *data) {struct pmic_glink_ucsi *ucsi = data; +/* Drain the work items before ucsi_destroy() frees the ucsi instance */ +cancel_work_sync (&ucsi->notify_work); +cancel_work_sync (&ucsi->register_work); +/* Protect to make sure we're not in a middle of a transaction from a glink callback */ mutex_lock (&ucsi->lock);ucsi_destroy (ucsi->ucsi);
@@ -467,8 +471,15 @@ static void pmic_glink_ucsi_remove(struct auxiliary_device *adev) {struct pmic_glink_ucsi *ucsi =dev_get_drvdata (&adev->dev); -/* Unregister first to stop having read & writes */ -ucsi_unregister (ucsi->ucsi); +/* Callbacks can queue work until devres releases the client */ +disable_work_sync (&ucsi->notify_work); +disable_work_sync (&ucsi->register_work); + +/* register_work may have unregistered the instance already */ +if (ucsi->ucsi_registered) { + ucsi->ucsi_registered = false; +ucsi_unregister (ucsi->ucsi); + } }static const struct auxiliary_device_id pmic_glink_ucsi_id_table[] = {