mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Fan Wu <fanwu01@zju.edu.cn>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Song Li <songl@zju.edu.cn>,
	Neil Armstrong <neil.armstrong@linaro.org>
Subject: Re: [PATCH] usb: typec: ucsi: glink: fix use-after-free of ucsi on remove
Date: Wed, 9 Sep 2026 16:20:21 +0200	[thread overview]
Message-ID: <aqFrJUHVKJz9Dyzq@black.igk.intel.com> (raw)
In-Reply-To: <20260908060216.616045-1-fanwu01@zju.edu.cn>

On Tue, Sep 08, 2026 at 06:02:15AM +0000, Fan Wu wrote:
> 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.
> 
> Fixes: 62b5412b1f4a ("usb: typec: ucsi: add PMIC Glink UCSI driver")

+Neil

> Cc: stable@vger.kernel.org
> Assisted-by: Codex:gpt-5.6
> Link: https://lore.kernel.org/r/20260227190430.889-1-nathan.c.rebello@gmail.com
> Co-developed-by: Song Li <songl@zju.edu.cn>
> Signed-off-by: Song Li <songl@zju.edu.cn>
> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>

Just a note. ucsi_registered was introduced in commit 11bb2ffb6793
("usb: typec: ucsi: Move unregister out of atomic section").

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/ucsi/ucsi_glink.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c
> index 12e07b9fe..1db0c88d8 100644
> --- a/drivers/usb/typec/ucsi/ucsi_glink.c
> +++ b/drivers/usb/typec/ucsi/ucsi_glink.c
> @@ -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[] = {

-- 
heikki

      reply	other threads:[~2026-09-09 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  6:02 Fan Wu
2026-09-09 14:20 ` Heikki Krogerus [this message]

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=aqFrJUHVKJz9Dyzq@black.igk.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=fanwu01@zju.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=songl@zju.edu.cn \
    --cc=stable@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®