From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 967474E56E3; Fri, 9 Oct 2026 14:50:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791557421; cv=none; b=aED1/fP0vnimlx6mz89pQFQaLUrjO0c8cnhwLSJ1EzfyBGScqhpxAyHx+yBPLmWUAOYCU1KitT+mdJOvOsz8UlqpXwRVfBJ0DofAubClOj3Yd0JaTrD/sHvSkQrBV7Lq/cj/1r7TvibLkeF1uy8bvRooR9GLhnwWStiSN9ECnIM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791557421; c=relaxed/simple; bh=zTu5xaBoHSwoMTq49dSUMQ6RSMovVQ7lqSamFhDQpWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A1HW/Urt74l7Gm3GQj/WOCqf4ym1FUzhUHxiI1UEFDu86NIuUOt5Sh7XUHkvV3CzYKuYCZFtBCin3BB4ZfneWYnfjJaPKOrOEfZDrTEFkqDmzRgg/J9srOI0YMGIinQuZKyfjdctENwiGwjnVbicL+rMlC4hvrzUYji02BBnvfU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lgLizXei; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lgLizXei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 011DC1F000FF; Fri, 9 Oct 2026 14:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791557420; bh=n+/3+Bu+7kpQaCfPjFwMe5nEX2o+DFPFA51d2VEoQfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lgLizXeiwYYHxwfkUHmvaWEzNoixxW+GQEJ0YlFDvR/1n5sQChCLtbW7HmRuj8vtp /G2CyUU9DgxPcNJLj7gaWfSWIgxQfABSGpSWAdaWUXyyh724WiHX+aXJq4RYW5cCAC xGeLEFeZ5H9TODBH17lYBeilqCMy+X9va0Hu31f4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Fedor Pchelkin , Mika Westerberg Subject: [PATCH 7.2 357/428] thunderbolt: Fix NULL dereference in tb_remove_work() Date: Fri, 9 Oct 2026 16:11:34 +0200 Message-ID: <20261009140954.011564240@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261009140946.008206689@linuxfoundation.org> References: <20261009140946.008206689@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fedor Pchelkin commit 4310c6b8e75d6a47f7548e5948fbe6318aa4440a upstream. 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 Signed-off-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/tb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -3264,11 +3264,11 @@ static void tb_remove_work(struct work_s struct tb *tb = tcm_to_tb(tcm); mutex_lock(&tb->lock); - if (tb->root_switch) + if (tb->root_switch) { tb_free_unplugged_children(tb->root_switch); + tb_free_unplugged_xdomains(tb->root_switch); + } mutex_unlock(&tb->lock); - - tb_free_unplugged_xdomains(tb->root_switch); } static int tb_runtime_resume(struct tb *tb)