From: sashiko-bot@kernel.org
To: "Neil Armstrong" <neil.armstrong@linaro.org>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/3] usb: typec: tcpm: unregister partner altmodes before re-discovery
Date: Wed, 25 Nov 2026 10:57:09 +0000 [thread overview]
Message-ID: <sashiko-outbox-233177@kernel.org> (raw)
In-Reply-To: <20261125-topic-tcpm-core-fixes-v2-1-aede2a3471f4@linaro.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: typec: tcpm: plug_prime_altmode leak and UAF in
svdm_consume_identity()
--
commit e6d007de8d361cfdd76de81da17f0dc6714fe900
Author: Neil Armstrong <neil.armstrong@linaro.org>
usb: typec: tcpm: unregister partner altmodes before re-discovery
This commit adds a helper to unregister partner alternate modes before
svdm_consume_identity() clears port->mode_data, and reuses it in
tcpm_unregister_altmodes().
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index ca38e05f831a7..20e18bca649eb 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -2068,6 +2068,17 @@ static int tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header,
> return ret;
> }
>
> +static void tcpm_unregister_partner_altmodes(struct tcpm_port *port)
> +{
> + struct pd_mode_data *modep = &port->mode_data;
> + int i;
> +
> + for (i = 0; i < modep->altmodes && i < ALTMODE_DISCOVERY_MAX; i++) {
> + typec_unregister_altmode(port->partner_altmode[i]);
> + port->partner_altmode[i] = NULL;
> + }
> +}
> +
> static void svdm_consume_identity(struct tcpm_port *port, const u32 *p, int cnt)
> {
> u32 vdo = p[VDO_INDEX_IDH];
> @@ -2076,6 +2087,7 @@ static void svdm_consume_identity(struct tcpm_port *port, const u32 *p, int cnt)
> if (cnt <= VDO_INDEX_PRODUCT)
> return;
>
> + tcpm_unregister_partner_altmodes(port);
> memset(&port->mode_data, 0, sizeof(port->mode_data));
[Severity: High]
Should svdm_consume_identity() call tcpm_unregister_altmodes(port) instead
so that port->plug_prime_altmode[] and port->mode_data_prime are also
cleaned up before re-discovery?
When tcpm_cable_vdm_supported(port) is true, partner altmode drivers such
as dp_altmode_probe() allocate their private state with
devm_kzalloc_obj(&alt->dev, *dp) on the partner altmode device and attach
it to the plug altmode via typec_altmode_set_drvdata(plug, dp) and
plug->cable_ops. Unregistering only port->partner_altmode[] frees that
devm state while leaving port->plug_prime_altmode[] registered and
reachable through typec_cable_altmode_vdm(), causing a use-after-free.
Once SOP Discover Modes finishes, tcpm_handle_discover_mode() also chains
into SOP' CMD_DISCOVER_SVID and CMD_DISCOVER_MODES whenever
tcpm_cable_vdm_supported(port) is true:
drivers/usb/typec/tcpm/tcpm.c:tcpm_handle_discover_mode() {
...
if (tcpm_cable_vdm_supported(port)) {
*response_tx_sop_type = TCPC_TX_SOP_PRIME;
response[0] = VDO(USB_SID_PD, 1,
typec_get_cable_svdm_version(typec),
CMD_DISCOVER_SVID);
tcpm_update_vdm_discovery_state(port, VDM_DISCOVERY_PARTNER_MODES);
return 1;
}
...
tcpm_register_plug_altmodes(port);
tcpm_register_partner_altmodes(port);
...
}
Because port->mode_data_prime was not zeroed and
port->plug_prime_altmode[] was not unregistered, SOP' discovery appends to
stale mode_data_prime counts and tcpm_register_plug_altmodes() overwrites
port->plug_prime_altmode[], leaking the previous plug altmode devices.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-topic-tcpm-core-fixes-v2-0-aede2a3471f4@linaro.org?part=1
next prev parent reply other threads:[~2026-11-25 10:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 10:40 [PATCH v2 0/3] usb: tcpm: partner sink capabilities and altmodes leak fixes Neil Armstrong
2026-11-25 10:40 ` [PATCH v2 1/3] usb: typec: tcpm: unregister partner altmodes before re-discovery Neil Armstrong
2026-11-25 10:57 ` sashiko-bot [this message]
2026-11-25 10:40 ` [PATCH v2 2/3] usb: typec: tcpm: unregister stale partner sink capabilities Neil Armstrong
2026-11-25 10:40 ` [PATCH v2 3/3] usb: typec: tcpm: destroy worker after reset_port() in unregister_port() Neil Armstrong
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=sashiko-outbox-233177@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=sashiko-reviews@lists.linux.dev \
/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