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=1796388439; b=Gh5MK03PFOhiWPPQDCtMDWqfWsDtyAEdT9mSt9E4L+ISaeoOmvFx9gNAwige+7CHRzMZ tyQBLZxzZhXlUbqKYUFpcE3D7/Nmipu1Wt4V4TBLGPvgv+gB6NaWSsEdTk117nUda27N5 /iZz/NUa7J/3eFXJRqgG3uW6oIKZx/6jU17xId7a8VV0bnfiFojD+scLUqcw/kVGJfP1r Cmm+JPYKLWoRRrovdad2cY+nsFF5dLf98QkYIrhckMls6DaxJt0M8nJQrZ84D1YFMezER 9703i0bAwZmNOnAJ9w/gI2u9mzHPF1iM9FMVJJELhrdagxFjIOmR+5kdEu43kvkxYWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388439; 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=fdpR2lEAXZuzU+I08YEcpy2/g/FJrEgrKZZamWVeNNU=; b=zgHPOAG74Gv/9s6a4qwIy39J9N261RWGsUwuUbWIBqLyCdAsjsXGtL7BvcWIcz56LAVJ GeFOqqgy88mm/QR/pz2udUjLxQddB7mQzsE76X99D7Z+RWiFNIdP9eQp5jXpO+OKNUZPB ydEr7m+AL0YxpAl496ESNWx1qEzOT0uG0UgBGcS+ytDOhN2SsKi9nuNdJwiAL7ts4/S+E n749e898YI1QSxXb465xzJg/6kvVo9QNAqApsnKZUr5skRRuTsaNV6KopFPyXo5yLY2cj 8skvfwLQGhLFOk+VYVY1N6MVBDgHNVY/F68X6I8Iyy/fpxlD7xyjWbJlo7WL4ZQDqSw== 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=X4ODpHQ8; 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 E474E606A332; Fri, 4 Dec 2026 12:47:18 +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=X4ODpHQ8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EE9D1F00931; Fri, 4 Dec 2026 12:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388438; bh=fdpR2lEAXZuzU+I08YEcpy2/g/FJrEgrKZZamWVeNNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X4ODpHQ8U9fO5vHCuUArPuQTBwYlmSCaC55mooWt7DjV5RmJSghya7895AMQqYO6b uLX2AwoLLe5sJWj5JkLlulFBJx9hBZT6fV/10tP9gG5Tp4cIIEhCQ3zzmQF5Nkb1Su OlVscCoR2FgRYBIDddDX5oA8W92XWaUPULDAAspM= 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.1 0613/1059] w1: remove the masters files before taking its locks Date: Fri, 4 Dec 2026 19:02:24 +0900 Message-ID: <20261204100659.993737340@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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);