From: sashiko-bot@kernel.org
To: "Neil Armstrong" <neil.armstrong@linaro.org>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: typec: tcpm: unregister partner altmodes before re-discovery
Date: Fri, 20 Nov 2026 10:14:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-224915@kernel.org> (raw)
In-Reply-To: <20261120-topic-tcpm-core-fixes-v1-1-c753d1d286bb@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 cc703948c4765e30249455553c02522ac441936b
Author: Neil Armstrong <neil.armstrong@linaro.org>
usb: typec: tcpm: unregister partner altmodes before re-discovery
This commit unregisters existing partner alternate modes in
svdm_consume_identity() before clearing port->mode_data on re-discovery,
sharing a new tcpm_unregister_partner_altmodes() helper with
tcpm_unregister_altmodes().
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index bb90211660cae..1d007e59a2bf9 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -2060,6 +2060,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];
> @@ -2068,6 +2079,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) so that
port->plug_prime_altmode[] is unregistered and port->mode_data_prime is
cleared as well?
When tcpm_cable_vdm_supported(port) is true, completing SOP Discover Modes
in tcpm_handle_discover_mode() automatically chains into SOP' Discover
SVIDs and Discover Modes and then calls tcpm_register_plug_altmodes(),
which appends to stale port->mode_data_prime counts and overwrites
port->plug_prime_altmode[] without unregistering the previous plug altmode
devices.
In addition, partner altmode drivers such as dp_altmode_probe() allocate
their private struct 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 driver data while leaving
port->plug_prime_altmode[] registered with a dangling drvdata pointer
until re-discovery finishes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-topic-tcpm-core-fixes-v1-0-c753d1d286bb@linaro.org?part=1
next prev parent reply other threads:[~2026-11-20 10:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 9:56 [PATCH 0/2] usb: tcpm: partner sink capabilities and altmodes leak fixes Neil Armstrong
2026-11-20 9:56 ` [PATCH 1/2] usb: typec: tcpm: unregister partner altmodes before re-discovery Neil Armstrong
2026-11-20 10:14 ` sashiko-bot [this message]
2026-11-20 9:56 ` [PATCH 2/2] usb: typec: tcpm: unregister stale partner sink capabilities Neil Armstrong
2026-11-20 10:03 ` sashiko-bot
2026-11-20 10:12 ` 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-224915@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