From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: shyckless@gmail.com
Cc: andreas.noever@gmail.com, YehezkelShB@gmail.com,
westeri@kernel.org, heikki.krogerus@linux.intel.com,
linux-kernel@vger.kernel.org, alok.a.tiwari@oracle.com,
linux-usb@vger.kernel.org
Subject: Re: [PATCH] thunderbolt: Keep the USB4 port when component_add() fails
Date: Mon, 16 Nov 2026 14:58:10 +0100 [thread overview]
Message-ID: <20261116135810.GY259790@black.igk.intel.com> (raw)
In-Reply-To: <20261112-thunderbolt-v1-1-fc30057cb7cd@gmail.com>
Hi,
On Thu, Nov 12, 2026 at 09:57:03AM +0000, Suyuan Wang via B4 Relay wrote:
> From: Suyuan Wang <stevewong@hust.edu.cn>
>
> When component_add() fails, usb4_port_device_add() unregisters the
> device but doesn't return:
>
> ret = component_add(&usb4->dev, &connector_ops);
> if (ret) {
> dev_err(&usb4->dev, "failed to add component\n");
> device_unregister(&usb4->dev);
> }
>
> The port was registered just before, so device_unregister() normally
> drops the last reference and usb4_port_device_release() frees usb4.
> The function still goes on to set up runtime PM on usb4->dev and
> returns usb4 to usb4_switch_add_ports(), which stores the stale pointer
> in port->usb4. When the router is removed later,
> usb4_switch_remove_ports() calls component_del() and
> device_unregister() on that pointer again.
>
> component_add() can fail on allocation, or when binding the aggregate
> driver fails. It isn't common, but when it happens the result is a
> use-after-free and a double unregister.
>
> The USB4 port can keep working without the component link. Keep the
> port registered when component_add() fails, and track whether the
> component was added, so that usb4_port_device_remove() only calls
> component_del() for a registered component. Otherwise component_del()
> would hit its WARN_ON().
>
> Found with a static analysis tool and checked by hand.
>
> Fixes: 5dddb4169284 ("thunderbolt: Link USB4 ports to their USB Type-C connectors")
> Reported-by: Alok Tiwari <alok.a.tiwari@oracle.com>
> Closes: https://lore.kernel.org/all/20250622140455.2884518-1-alok.a.tiwari@oracle.com/
> Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Cc: stable@vger.kernel.org
> Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
Applied to thunderbolt.git/fixes, thanks!
prev parent reply other threads:[~2026-11-16 13:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 9:57 Suyuan Wang via B4 Relay
2026-11-16 13:58 ` Mika Westerberg [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=20261116135810.GY259790@black.igk.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=alok.a.tiwari@oracle.com \
--cc=andreas.noever@gmail.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=shyckless@gmail.com \
--cc=westeri@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®