From: "Iván Ezequiel Rodriguez" <ivanrwcm25@gmail.com>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
"Iván Ezequiel Rodriguez" <ivanrwcm25@gmail.com>
Subject: [PATCH] usb: typec: ucsi: fix teardown races with late notifications
Date: Thu, 3 Sep 2026 00:03:56 -0300 [thread overview]
Message-ID: <20260903030356.58597-1-ivanrwcm25@gmail.com> (raw)
ucsi_acpi_remove() freed the UCSI instance before removing the ACPI
notify handler. A concurrent notify could call into ucsi_acpi_notify()
and use ua->ucsi after it was destroyed.
Clear ucsi->ntfy before disabling PPM notifications and NULL the
connector array after free so ucsi_connector_change() cannot schedule
work on a dangling connector while a backend still delivers events.
Tested: built drivers/usb/typec/ucsi/ with CONFIG_TYPEC_UCSI=m and
CONFIG_UCSI_ACPI=m via docker kbuild; checkpatch clean.
Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com>
---
drivers/usb/typec/ucsi/ucsi.c | 11 +++++++++++
drivers/usb/typec/ucsi/ucsi_acpi.c | 11 ++++++++---
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index bef3f9b71d71..3395614764cf 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -2369,6 +2369,15 @@ void ucsi_unregister(struct ucsi *ucsi)
ucsi_debugfs_unregister(ucsi);
+ /*
+ * Stop accepting connector-change events before the PPM disable
+ * command and before freeing connectors. Backends may still deliver
+ * a late notification (e.g. ACPI) until their own handler is removed;
+ * with ntfy cleared, ucsi_connector_change() returns early instead of
+ * scheduling work on a connector that is about to be freed.
+ */
+ ucsi->ntfy = 0;
+
/* Disable notifications */
ucsi->ops->async_control(ucsi, cmd);
@@ -2382,6 +2391,8 @@ void ucsi_unregister(struct ucsi *ucsi)
}
kfree(ucsi->connector);
+ ucsi->connector = NULL;
+ memset(&ucsi->cap, 0, sizeof(ucsi->cap));
}
EXPORT_SYMBOL_GPL(ucsi_unregister);
diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c
index 18286d3e9cc5..5fc485121dbb 100644
--- a/drivers/usb/typec/ucsi/ucsi_acpi.c
+++ b/drivers/usb/typec/ucsi/ucsi_acpi.c
@@ -256,11 +256,16 @@ static void ucsi_acpi_remove(struct platform_device *pdev)
{
struct ucsi_acpi *ua = platform_get_drvdata(pdev);
- ucsi_unregister(ua->ucsi);
- ucsi_destroy(ua->ucsi);
-
+ /*
+ * Drop the ACPI notify handler before tearing down the UCSI instance.
+ * Otherwise a concurrent notify can race into ucsi_acpi_notify() and
+ * use ua->ucsi after it has been freed.
+ */
acpi_remove_notify_handler(ACPI_HANDLE(&pdev->dev), ACPI_DEVICE_NOTIFY,
ucsi_acpi_notify);
+
+ ucsi_unregister(ua->ucsi);
+ ucsi_destroy(ua->ucsi);
}
static int ucsi_acpi_suspend(struct device *dev)
--
2.43.0
next reply other threads:[~2026-09-03 3:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 3:03 Iván Ezequiel Rodriguez [this message]
2026-09-03 8:40 ` Huang Wei
2026-09-03 23:21 ` [PATCH v2] usb: typec: ucsi: acpi: fix use-after-free on driver removal Iván Ezequiel Rodriguez
2026-09-04 3:48 ` Huang Wei
2026-09-04 3:37 ` [PATCH] usb: typec: ucsi: fix teardown races with late notifications Huang Wei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260903030356.58597-1-ivanrwcm25@gmail.com \
--to=ivanrwcm25@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®