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=1796379438; b=UqqxhEWVwNO6MGhGVaxTuHEpZZ0AuvAZhUupx8goPzUZzMj8jhaTJ9sE8ri2hMvss39t b7/WrmzRtsVAt0iQKgpg9wO0JQBx1HP0azwozuD9pgkxxWUL6NQ/Fmv0m1Asx3eFutDuK M3L8FgyjdHVTXJoaUlVZK9JEnY+ootLPvhBkyJo/wWnBc481FigCg+Shg5FqpQStNqr+f F1WBwa+A3dceYjL/MOMBnawV5wqLp8DcZeG7XvhzZRLuRE6id7fO15wwpAL5BKcRQWQwX QyQku/0AMvhz+vc+0rAitTDtcmL+NPAMC8fREGanDWmsCiGNu90UUdWylfgunDXkYFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379438; 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=IKQvSOenV2ZRUXOcwSvLwYC79O6+43OUiqyQ/frzd9Y=; b=2rHx03vfzHxTSgquKxYxjfGRuTCaw70pbBRtFdzHRzZaGF/4dIBKuRmZsn9JoMVzJY5g lhSne8xYPGHts5XWuucQNHa+f/5Bx3flPOZUqTZCiG6CvjKsNNaggtsMtof2W/r84jBRs mPbzevIHACkj4GoGS/NMBdIULp/y3pcn88dge+tRKf4fOJAd/dhKibIAGEAQkVqM7CtWI +jvLNohhRjHohlwPa/eGn8w5mugRxpTkCQ8Zw0aW5TaKtt6pihIwkPQ6ind6yyVHlpUHe CToJjetVgeGE2AVJfsl9/Q1MINis+3kZUOGFzVVN5EPgouUvRYDhjbpzNWwkn5um/ng== 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=YKj4MsTk; 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 C9DC0606A32C; Fri, 4 Dec 2026 10:17: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=YKj4MsTk Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E1031F0092C; Fri, 4 Dec 2026 10:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379438; bh=IKQvSOenV2ZRUXOcwSvLwYC79O6+43OUiqyQ/frzd9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YKj4MsTkWh5vEbPg1n1feBbZGzIbVMOlQoLR51aDCB4zz1j2XvU8Tw3ZOwJNaTCA0 3vmNbflAnVRsyHBjdC+yvv5CePkYiEB5PzJEOvJFFEU+kLEzsv3vBKayTsQS/oX5gP G+LfC8jvcvqiPQGkhxP58xAZPVJlksR+mVt364dw= 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.12 029/555] tpm: flush timeout work outside buffer_mutex to avoid deadlock Date: Fri, 4 Dec 2026 19:01:12 +0900 Message-ID: <20261204100606.096031929@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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: Replaced timer_delete_sync() with the older del_timer_sync() name that this tree uses; the rest matches upstream. ] 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 1bfdcb9794e20..98b35c4e8bc8c 100644 --- a/drivers/char/tpm/tpm-dev-common.c +++ b/drivers/char/tpm/tpm-dev-common.c @@ -132,6 +132,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) @@ -164,9 +165,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