[PATCH v3 2/2] tpm: Disable TPM on TPM_RC_INITIALIZE
From: Breno Leitao
Date: Fri Nov 13 2026 - 07:24:02 EST
From: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
If the TPM has been spuriously disabled, the game is over. Let's reflect
this truth with TPM_CHIP_FLAG_DISABLE.
Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
[leitao@xxxxxxxxxx: check rc before the loop breaks out on anything but
RETRY/TESTING, skip TPM2_Startup, which a TPM that is already started
fails with TPM2_RC_INITIALIZE, and fix the TPM2_RC_INITIALIZE and
chip->flags typos]
Reviewed-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
---
drivers/char/tpm/tpm-interface.c | 5 +++++
drivers/char/tpm/tpm2-cmd.c | 2 ++
2 files changed, 7 insertions(+)
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 977e205807033d..dd6bb518ab7d9c 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -252,6 +252,11 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz)
if (ret < 0)
break;
rc = be32_to_cpu(header->return_code);
+ /* A TPM that is already started fails TPM2_Startup this way. */
+ if (rc == TPM2_RC_INITIALIZE && cc != TPM2_CC_STARTUP) {
+ chip->flags |= TPM_CHIP_FLAG_DISABLE;
+ break;
+ }
if (rc != TPM2_RC_RETRY && rc != TPM2_RC_TESTING)
break;
/*
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 4b2bb2ddc321a9..65928ae85b496c 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -724,6 +724,8 @@ int tpm2_auto_startup(struct tpm_chip *chip)
goto out;
if (rc == TPM2_RC_INITIALIZE) {
+ chip->flags &= ~TPM_CHIP_FLAG_DISABLE;
+
rc = tpm2_startup(chip);
if (rc)
goto out;
--
2.53.1-Meta