From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385721; b=0SZwgvdVoNlzgCJUQZ4myrVQVDuh17HbqFLj8wpfTJ5I2oZIPV8WkLG3fJmlDvf8dH/M vZhYhIioqINz1L4MudFOFQfYVRySgGalXdoocoQ1hyNCPXFZVyREIdTLY8aYFo7CBhpWU QagLeayAgS4tCz5LNXlOBxWJ1hlWchtdlVGRkp4r/zjUoFjVTlw3OsscgOJW6hzHYvPoA snw/Kq2DQadFxSTUNuYwVcOYqQao/OVKSFKphcaBhjVd2y+mdRh6vviUmq2gxY1FujYES ggf4FaJdUdYC9JLAWWKTtrxrUwXWMIBH0j6xgcZlWL+0YeIIeErR6Zzh79JILo+P9SQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385721; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=NoRDRemlo0aEpN1X/BwZxoIbiuL0CZ3f2G24dgcbbqY=; b=id0bAzJt6yi3/xaP1jFpssIm1rBoeyAVUfzj9DMezD0LdFA7F6pW2DZgU7N8GVPNTl0D /ZTP4p95kw7eiFOtHMvqzQdzKwoY+c35oZJsuG3SI2Pb21SBpqVqmJsloMTtIXcAcbVLr 7DNfqA95Q6QrwYdLB2ZJv3VjP+Mmqt8IaA1qydKY9KYsP9MEYJJqIzNJGe8aPQ8uNzBuC +zJfBWVHPUliyvDb31hxkreGPr1CBgSaD7ycGH86j18WhAqf8A8dk3eh+NMkgbzQ8T6CV 78SeNu/6Mo3ut+eZ6GmxJclw0SIht2GdygvXmt1dtZVlEo22MylcULi+BUTzHCIbK3A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yZBDWVKc; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F26E8606A322; Fri, 4 Dec 2026 12:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yZBDWVKc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B6B81F000CE; Fri, 4 Dec 2026 12:02:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385720; bh=NoRDRemlo0aEpN1X/BwZxoIbiuL0CZ3f2G24dgcbbqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yZBDWVKcdLMk0QDacZfMv6/jFCpYd1Ropa4J5RvwdbSqU9zGLoTxNSszqIRlHfYvV ED23ayYDxbKl0V/KxTGh2I/+TxOEQXx1VRFuQgV8SrEPLpf0xMMzfiH6eokLTaCIgg XHKcRuT4E7q+jKeats/PCetBLd6H2FshlRBsL8eQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Josef Bacik , Krzysztof Kozlowski Subject: [PATCH 6.6 0665/1167] w1: remove the masters files before taking its locks Date: Fri, 4 Dec 2026 19:01:32 +0900 Message-ID: <20261204100719.377620806@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit dfc57752ec53c3cc6105656d3037fb2f5e80e9cc upstream. __w1_remove_master_device() calls w1_destroy_master_attributes() with both the mutex of the master and list_mutex held. Removing the files waits for the callbacks which are running, and nearly all of them take one of these two locks: __w1_remove_master_device() read() of .../w1_master_slaves mutex_lock(&dev->mutex) kernfs active reference mutex_lock(&dev->list_mutex) w1_master_attribute_show_slaves() w1_destroy_master_attributes() mutex_lock(&md->list_mutex) sysfs_remove_group() waits waits for the reference The files are readable for everybody, and a bus master goes away when, for instance, a DS2490 USB adapter is unplugged. Remove the files first, before the locks are taken. That has to be done before the slaves are detached and not afterwards: as long as the files exist, a write to w1_master_add could attach a new slave behind the back of this function, which would then wait for the reference count of the master for ever. And it is done before the thread is stopped, because a write to w1_master_search wakes the thread up. Fixes: c30c9b15187e ("W1: fix deadlocks and remove w1_control_thread") Cc: stable Signed-off-by: Josef Bacik Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20261027-llm-char-misc-w1-v1-2-d2e6bfafb6a4@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1_int.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c @@ -180,6 +180,13 @@ void __w1_remove_master_device(struct w1 mutex_unlock(&w1_mlock); set_bit(W1_ABORT_SEARCH, &dev->flags); + + /* + * This waits for the callbacks, which take the locks below. One of + * them wakes the thread up. + */ + w1_destroy_master_attributes(dev); + kthread_stop(dev->thread); mutex_lock(&dev->mutex); @@ -189,7 +196,6 @@ void __w1_remove_master_device(struct w1 w1_slave_detach(sl); mutex_lock(&dev->list_mutex); } - w1_destroy_master_attributes(dev); mutex_unlock(&dev->list_mutex); mutex_unlock(&dev->mutex); atomic_dec(&dev->refcnt);