From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Fedor Pchelkin <pchelkin@ispras.ru>
Cc: Mika Westerberg <westeri@kernel.org>,
linux-usb@vger.kernel.org,
Andreas Noever <andreas.noever@gmail.com>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
stable@vger.kernel.org
Subject: Re: [PATCH] thunderbolt: fix NULL dereference in tb_remove_work()
Date: Wed, 2 Sep 2026 09:10:06 +0200 [thread overview]
Message-ID: <20260902071006.GJ106095@black.igk.intel.com> (raw)
In-Reply-To: <20260831075836.16038-1-pchelkin@ispras.ru>
Hi,
On Mon, Aug 31, 2026 at 10:58:09AM +0300, Fedor Pchelkin wrote:
> There is a slight race between tb_remove_work() and tb_domain_remove()
> which leads to dereferencing a NULL tb->root_switch pointer inside
> tb_free_unplugged_xdomains():
>
> Thread A Thread B
>
> tb_remove_work()
> tb_domain_remove()
> mutex_lock(&tb->lock)
> tb_stop()
> /* doesn't cancel a running callback */
> cancel_delayed_work(&tcm->remove_work)
> ...
> tb_switch_remove(tb->root_switch)
> tb->root_switch = NULL
> mutex_unlock(&tb->lock)
> mutex_lock(&tb->lock)
> ...
> /* without checking ->root_switch */
> tb_free_unplugged_xdomains(tb->root_switch)
> mutex_unlock(&tb->lock)
>
> Commit a8937f35cf39 ("thunderbolt: Remove XDomain from the bus without
> holding tb->lock") doesn't seem right to move tb_free_unplugged_xdomains()
> out of the &tb->lock section and the check for tb->root_switch, in
> particular. It states:
>
> For this reason separate removing the XDomain from the topology data
> structures (where we need the lock) from unregistering the device from
> the bus (where remove callbacks of the drivers are being called).
>
> tb_free_unplugged_xdomains() belongs to the former group of functions
> requiring the lock. And it also calls tb_xdomain_remove() which should
> only be called with &tb->lock held.
>
> Found by Linux Verification Center (linuxtesting.org) with Svace static
> analysis tool.
>
> Fixes: a8937f35cf39 ("thunderbolt: Remove XDomain from the bus without holding tb->lock")
> Cc: stable@vger.kernel.org
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Applied to thunderbolt.git/fixes, thanks!
prev parent reply other threads:[~2026-09-02 7:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 7:58 Fedor Pchelkin
2026-09-02 7:10 ` 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=20260902071006.GJ106095@black.igk.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=pchelkin@ispras.ru \
--cc=stable@vger.kernel.org \
--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®