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=1796385911; b=qFdP6N7Lc9Aq7y3JZ39ny2eB9xNPGdWJ2ZYcJu1xx12KY801YQl73fEp6QajpC/0O/Zx /PJkp7na+T42fKq8g1Wi5eM/4qKlx2OF+JI6NiZHJwkHCBAatspFFo5bKmFHBpk7CrmrO 9YJhGqTQbC2p/LF41BMqI4i37Xx4npdxti0RLYtKVv/4aT5iPBEQpolqRr2wv1Yew5VM8 C8GfdYBMrfG5P3x6UvaW3Ck51aCHG2+DmAVrj2KY8X01a6VIJrDAzqSyuCfQ+/Ynwhx99 BSetJZcmmaP+oARDk9tTE1wN8jnQPplXf5bD6x+UvDF9XNTEhvXx53d0c2ilIyYlHSA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385911; 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=8wkknvNXem+MZa4+jYIaxKYdvaD/mGAF2+hmM5x2vQ8=; b=zoq/auXXDW5mBvZ+Fxg0aBzfn+IP+0NvAZiQU1u4V7nvd82YnxrwFyXYlTYLA0sSF77k 0RrO3NH+atgrF7eML3l6kBKwvOi8e1EakQxBLtYyaFTYkPqdA1KL6m5rKjQAfFquoyceN q14m1L22IBb5U5RWfIznlS0cgt4meT77DlhEr7esbC5k/p2moYX9+SgWSa+LnmJVH5K8B mQBgz9SRr8PWiLim7f4krOW/2rBfQOYRVyeY/zHQOHjES5jrJSTIZWf6Bu0fzM7hRAcJw RkdhAI/is300rFqkVKbEM/EELdM+GrdaSDpzSk5E/R/o1zV7VznOYK5xYH3TdZbupKw== 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=EmbHR5AT; 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 CD598606A332; Fri, 4 Dec 2026 12:05:11 +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=EmbHR5AT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B3E41F00933; Fri, 4 Dec 2026 12:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385911; bh=8wkknvNXem+MZa4+jYIaxKYdvaD/mGAF2+hmM5x2vQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EmbHR5AThGjMo644DQq2Ahme2jeWP2LW4RyUWdAtZlCXQvC4UvnrcweAjQgKKRhaR cECP9FMIWwNSXHQUJRdmvswXUOl3GGVb7hhhcWI368KWn8mqq7BkRCedFlkoUSHXqs H82WkWPcebL9HM4vl73R4py0jsg+T3PCveoztMxo= 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.6 0744/1167] tpm: flush timeout work outside buffer_mutex to avoid deadlock Date: Fri, 4 Dec 2026 19:02:51 +0900 Message-ID: <20261204100721.447187061@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: 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 del_timer_sync(), since the older tree lacks the newer timer API name. ] 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