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=1796385723; b=hqIcm1WX4RMtdPLZwPX+mVbBzrS3PMSHLj5WHq7bemur17mRTzBvbvYtq80xWn0LstPR TyJ9Zg7HR1cNZ0caelAmiXK02zEc+H7Ztl6F98HnvwYFqr/Bl54Tu4gNccRnKWjEptMxj G268pKjp40HMYKX4LwRyAWrLdIXw/QchwLDw8od48qbadYX0BhBooD9h7fGopQuSEV0kw 74iK2+KZ/n9hsckKP6PuK4h3VAb2CAcvuk3rGdze7Gh/ErRbYXCe6ZergFWTNRa9uKx5B xQvp9+66xN9qSbcDyDRb5dmnVyKtH2PxIToV9+H21BVAJqj3gFEJL441z1OIGz5ZNeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385723; 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=rkAckFCM+tDmVGvSw1bJTxFn2Tk4GThFx2LzTsIstmM=; b=i9fBgRzERoerZvO9/ok5rkHDIwrjYUeqD6eWnHzNR/p7Rm3imZRVpfPY3GiJwiY6X0hr yAXxmg7rXPt1OihAS+av5SLoJowoKaND34GzPK5iF8xInnhl/cs0uJ2HT3SX0e7cv3Hvw dMYviAWxeCanFf55bUYnD2AD5au73iA3vr9sKPXH+KIEygA4aOt/fbJMAF3IcmgskekaN wL4lQSxNlItdc5zgXHZO9I4YbHimAeSRMzXKmMHP5xI24T9/5lNrOMDrKq+5zvsAd2pnP GSvzbx7quxm1B18k2LqEld9ji3r7c57Bl1PzmvI7Jxsn58af0Sn+25qk4GZwTtUVLzw== 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=nqrFiFjw; 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 3C94F606A32C; Fri, 4 Dec 2026 12:02:03 +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=nqrFiFjw Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD2CD1F000CE; Fri, 4 Dec 2026 12:02:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385723; bh=rkAckFCM+tDmVGvSw1bJTxFn2Tk4GThFx2LzTsIstmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nqrFiFjwsTHH06QvGqqSRUaf2sVSIIQE/t4XrzAic+JE2fkSyYYPyAdpb1FMwrdqa 0lYsfmycuP4Uthz4FYOR6xGUSbW0XKtAvEpiqGSo0aWQW0tVnPC7JyF7T5kFtGemMQ 0Tg6Eqk0nU2HDYJq4Ra13iQTA9oqjFsFswbqaUR0= 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 0666/1167] w1: use the bus mutex for the "rw" file Date: Fri, 4 Dec 2026 19:01:33 +0900 Message-ID: <20261204100719.402625655@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 8599e08648c0b4913ea7b202511f1294d176e793 upstream. Commit b02f8bede217 ("W1: split master mutex to avoid deadlocks.") gave the bus a mutex of its own, because the lock which protects the list of slaves is held while a slave is removed, which waits for the sysfs callbacks of the slave, so these must not take it. It converted all the slave drivers, but not the "rw" file of the default family in w1.c, which still takes the mutex of the master to talk on the bus. That has two consequences: - A deadlock. w1_process() holds the mutex of the master while it searches the bus and detaches the slaves which have gone: w1_process() read() of .../rw mutex_lock(&dev->mutex) kernfs active reference w1_search_process() rw_read() w1_slave_detach() mutex_lock(&master->mutex) w1_unref_slave() waits device_unregister() waits for the reference The file is readable for everybody. - The accesses through this file are not serialised with those of the slave drivers, which take bus_mutex, so that two transactions can get mixed up on the wire. Take bus_mutex here as well. It also excludes the search, which takes it for every pass. Fixes: b02f8bede217 ("W1: split master mutex to avoid deadlocks.") Cc: stable Signed-off-by: Josef Bacik Reviewed-by: Krzysztof Kozlowski Link: https://patch.msgid.link/20261027-llm-char-misc-w1-v1-1-d2e6bfafb6a4@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -116,7 +116,7 @@ static ssize_t rw_write(struct file *fil { struct w1_slave *sl = kobj_to_w1_slave(kobj); - mutex_lock(&sl->master->mutex); + mutex_lock(&sl->master->bus_mutex); if (w1_reset_select_slave(sl)) { count = 0; goto out_up; @@ -125,7 +125,7 @@ static ssize_t rw_write(struct file *fil w1_write_block(sl->master, buf, count); out_up: - mutex_unlock(&sl->master->mutex); + mutex_unlock(&sl->master->bus_mutex); return count; } @@ -135,9 +135,9 @@ static ssize_t rw_read(struct file *filp { struct w1_slave *sl = kobj_to_w1_slave(kobj); - mutex_lock(&sl->master->mutex); + mutex_lock(&sl->master->bus_mutex); w1_read_block(sl->master, buf, count); - mutex_unlock(&sl->master->mutex); + mutex_unlock(&sl->master->bus_mutex); return count; }