From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: "André Draszik" <andre.draszik@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Badhri Jagan Sridharan <badhri@google.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Peter Griffin <peter.griffin@linaro.org>,
Tudor Ambarus <tudor.ambarus@linaro.org>,
Juan Yescas <jyescas@google.com>,
Amit Sunil Dhamne <amitsd@google.com>,
kernel-team@android.com, linux-usb@vger.kernel.org,
linux-rt-devel@lists.linux.dev, stable@vger.kernel.org
Subject: Re: [PATCH v2 3/4] usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind
Date: Mon, 30 Nov 2026 13:35:09 +0100 [thread overview]
Message-ID: <aw1tfTRkPcXYxZOL@black.igk.intel.com> (raw)
In-Reply-To: <20261125-max77759-wait-v2-3-9914b985c00b@linaro.org>
On Wed, Nov 25, 2026 at 12:16:57PM +0000, André Draszik wrote:
> Unbinding the tcpci_maxim driver triggers a use-after-free in
> regulator_disable() if the driver has acquired the vbus regulator:
>
> Unable to handle kernel paging request at virtual address
> 006b6b6b6b6b6bb7
> pc : regulator_lock_recursive+0x20/0x218
> lr : regulator_lock_dependent+0x198/0x2c0
> Call trace:
> regulator_lock_recursive+0x20/0x218 (P)
> regulator_lock_dependent+0x198/0x2c0
> regulator_disable+0x4c/0x100
> max_tcpci_set_vbus+0x70/0x108 [tcpci_maxim]
> tcpci_set_vbus+0x44/0x100 [tcpci]
> tcpm_reset_port+0x13c/0x288 [tcpm]
> tcpm_unregister_port+0x70/0x120 [tcpm]
> tcpci_unregister_port+0x24/0x68 [tcpci]
> max_tcpci_unregister_tcpci_port+0x18/0x30 [tcpci_maxim]
> devm_action_release+0x1c/0x30
>
> max_tcpci_set_vbus() obtains chip->vbus_reg lazily via
> devm_regulator_get_exclusive(). When the regulator is acquired after
> max_tcpci_probe() has queued max_tcpci_unregister_tcpci_port() with
> devm_add_action_or_reset(), devres releases resources in reverse order
> and frees the regulator handle before max_tcpci_unregister_tcpci_port()
> unregisters the port and max_tcpci_set_vbus() accesses chip->vbus_reg.
>
> Switch to regulator_get_exclusive() and register a devres cleanup action
> for regulator_put() before tcpci_register_port(), so the port is
> unregistered and tcpm_reset_port() disables VBUS before the regulator
> handle is released.
>
> Fixes: 0c8935642cb0 ("usb: typec: tcpm/tcpci_maxim: deprecate WAR for setting charger mode")
> Cc: stable@vger.kernel.org
> Signed-off-by: André Draszik <andre.draszik@linaro.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/tcpm/tcpci_maxim_core.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> index 2bb306b6b1f9..2e6a8906fb32 100644
> --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> @@ -209,8 +209,7 @@ static void process_rx(struct max_tcpci_chip *chip, u16 status)
> static int get_vbus_regulator_handle(struct max_tcpci_chip *chip)
> {
> if (IS_ERR_OR_NULL(chip->vbus_reg)) {
> - chip->vbus_reg = devm_regulator_get_exclusive(chip->dev,
> - "vbus");
> + chip->vbus_reg = regulator_get_exclusive(chip->dev, "vbus");
> if (IS_ERR_OR_NULL(chip->vbus_reg)) {
> dev_err(chip->dev,
> "Failed to get vbus regulator handle\n");
> @@ -221,6 +220,14 @@ static int get_vbus_regulator_handle(struct max_tcpci_chip *chip)
> return 0;
> }
>
> +static void max_tcpci_put_vbus_regulator(void *data)
> +{
> + struct max_tcpci_chip *chip = data;
> +
> + if (!IS_ERR_OR_NULL(chip->vbus_reg))
> + regulator_put(chip->vbus_reg);
> +}
> +
> static int max_tcpci_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, bool source, bool sink)
> {
> struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata);
> @@ -514,6 +521,11 @@ static int max_tcpci_probe(struct i2c_client *client)
> chip->data.cable_comm_capable = true;
> chip->data.attempt_vconn_swap_discovery = max_tcpci_attempt_vconn_swap_discovery;
>
> + ret = devm_add_action_or_reset(&client->dev,
> + max_tcpci_put_vbus_regulator, chip);
> + if (ret)
> + return ret;
> +
> max_tcpci_init_regs(chip);
> chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
> if (IS_ERR(chip->tcpci))
>
> --
> 2.56.1.831.g720f3f5937-goog
>
--
heikki
next prev parent reply other threads:[~2026-11-30 12:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 12:16 [PATCH v2 0/4] usb: typec: tcpm/tcpci_maxim: lockdep, wakeup and vbus regulator fixes André Draszik
2026-11-25 12:16 ` [PATCH v2 1/4] usb: typec: tcpm/tcpci_maxim: fix invalid wait context André Draszik
2026-11-25 12:16 ` [PATCH v2 2/4] usb: typec: tcpm/tcpci_maxim: init wakeup before irq André Draszik
2026-11-25 12:16 ` [PATCH v2 3/4] usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind André Draszik
2026-11-30 12:35 ` Heikki Krogerus [this message]
2026-11-25 12:16 ` [PATCH v2 4/4] usb: typec: tcpm/tcpci_maxim: only complain about vbus when sourcing André Draszik
2026-11-30 12:38 ` Heikki Krogerus
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=aw1tfTRkPcXYxZOL@black.igk.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=amitsd@google.com \
--cc=andre.draszik@linaro.org \
--cc=badhri@google.com \
--cc=bigeasy@linutronix.de \
--cc=clrkwllms@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jyescas@google.com \
--cc=kernel-team@android.com \
--cc=linux-rt-devel@lists.linux.dev \
--cc=linux-usb@vger.kernel.org \
--cc=peter.griffin@linaro.org \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
--cc=tudor.ambarus@linaro.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