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=1796388753; b=tFvQHkcf1uOy67R+7RidxBtCk9qysH8w0VfgfZyhCmZaJXjVcitg4Ix/x2oPQNJPoY28 eE1CbshDHDN1u87hB5XtJffnAj84wyEzUcMq/d78t0Ja8jQOMHuSJbNXRt2/v1z0cuDWZ 3Q7kql/pBKxswcNYOWIC2tT7m3LrjKRVTJwH60ruNrYu/8YNt2gskYGikUqDT+xOE55K9 SwBwchNf7C4wU/4tsO37i2AYFYgOjs4mHH17LQl36fzTXqr1Elt2JA54AHvVGlGidBI/0 Qm0LFPEqU84cZOBCkdfI9kilTh62xnEZ1yOhPimIkEl32h0cjIE3qPAOGkm4nqx1ISw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388753; 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=b0jHYsdiYB9Gpf43aza1QU9mn1Qq6L9u/FSBVPXnF/A=; b=LfXRSvTxTP6R6dC8xah0nXQct98aIG9ZXVezEd/VrbmmYM7bCcttX+kcboIveJGErbCo DPuI6HOWv2fJmbNYPCVpdqR6o7/78PkUpib/absTB96LrK/qXkIyFUiV06r0zPxB9xEpL z/kA5Q/KnbCvYcnADs1VWORGRXykao5rZBkynVVj/jlR5MSRNZnfQebLLvQCAeSAvo9J+ nCbycbWh6wlSfTEZVT/GIOF49cNJw8kY1nuegbmYIHqc2gTHrfZL4mg64hbRXNINQWulY 2YhN+dwUhXB/mI4BFTeFNXQQUaddDeaNVvEq5ncoP3YLKsGzXdZVes5zTKR3A6Za6TA== 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=ofjwtqEW; 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 BA90A606A32C; Fri, 4 Dec 2026 12:52:33 +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=ofjwtqEW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 746651F000CE; Fri, 4 Dec 2026 12:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388752; bh=b0jHYsdiYB9Gpf43aza1QU9mn1Qq6L9u/FSBVPXnF/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ofjwtqEW0ySzrLV7J24PL9IsyEvOLoM3+fG7J3QWBPYL/i45sMyur11TyqxLbago1 RxB/hE5eF4Rj5pAOIHZMlP8JZ3PBBP511gLEwCxHFXM6I0QkWPK6kzjEMFgoJyBFA5 q6Q5Qblsq53/ztNci8z7WHCIAKQ6spZGnZM1RzDU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hyunjung Ko , Jarkko Sakkinen , Sasha Levin Subject: [PATCH 6.1 0713/1059] tpm: flush timeout work outside buffer_mutex to avoid deadlock Date: Fri, 4 Dec 2026 19:04:04 +0900 Message-ID: <20261204100702.445614749@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: 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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hyunjung Ko [ Upstream commit c22052a012698ce56d599d75b669d55778521c7c ] tpm_common_read() calls flush_work(&priv->timeout_work) under priv->buffer_mutex, but tpm_timeout_work() also takes buffer_mutex, so a running timeout work deadlocks the flush. Flush after unlocking; the timer is deleted under the lock, so no new work can be queued. Fixes: 9488585b21be ("tpm: add support for partial reads") Cc: stable@vger.kernel.org Signed-off-by: Hyunjung Ko Reviewed-by: Jarkko Sakkinen Link: https://lore.kernel.org/r/20261108165812.676876-1-hj351016@gmail.com Signed-off-by: Jarkko Sakkinen [ sashal: Adapted the timer call to the older API, using del_timer_sync() in place of timer_delete_sync(). ] Signed-off-by: Sasha Levin --- drivers/char/tpm/tpm-dev-common.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c index ff86a1fdb5cdc..ddd4434edd33e 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -129,6 +129,7 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, { struct file_priv *priv = file->private_data; ssize_t ret_size = 0; + bool flush = false; int rc; if (!size) @@ -161,9 +162,18 @@ ssize_t tpm_common_read(struct file *file, char __user *buf, if (!priv->response_length) { *off = 0; del_timer_sync(&priv->user_read_timer); - flush_work(&priv->timeout_work); + flush = true; } mutex_unlock(&priv->buffer_mutex); + + /* + * tpm_timeout_work() takes buffer_mutex, so flush it after dropping + * the mutex to avoid a deadlock; the timer is deleted above, so no new + * timeout work can be queued once the mutex is released. + */ + if (flush) + flush_work(&priv->timeout_work); + return ret_size; } -- 2.53.0