Skip to contentSkip to conversation

tpm: Stop retrying TPMs that have stopped working

PATCH Superseded Breno Leitao 3 participants 13 messages Nov 12

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover tpm: Stop retrying TPMs that have stopped working

On Meta's datacenter, given the size, TPMs that stop working write about 54 million lines a day to the kernel log, because nothing in the kernel gives up on them.

Two cases make up nearly all of it.

Some TPMs stop responding. Every command then fails only after the transport timeout, while the hwrng thread and userspace keep sending more.

Other TPMs get reset under the running OS, and answer every command with TPM_RC_INITIALIZE (256) from then on, while the hwrng thread retries every 10 seconds:

tpm tpm0: A TPM error (256) occurred attempting get random

The goal is to retire TPMs that are not properly working, similarly to what was done for EFI in commit 4b2c033b5bc971 ("efi/runtime-wrappers:
retire the worker if a wedged call ever returns")

Patch 1 disables the chip once 60 commands in a row have timed out, instead of keeping it in this desolate state. Patch 2, from Jarkko, disables it once it answers TPM_RC_INITIALIZE to anything but TPM2_Startup.

Disabling the chip makes the failure explicit: the log gets one last line about it, and every later command fails at once instead of timing out.

A health-check daemon, such as machine checker, can then detect the broken hardware and send the machine to repair.

---
Changes in v2:
- Disable the TPM after 60 commands in a row time out, instead of after
ten minutes of timeouts, and make the limit the tpm.max_unanswered
boot parameter (Jarkko)
- Open-code the check in tpm_transmit() and drop the "timeout" field
names (Jarkko)
- Replace the hwrng failure counter with Jarkko's patch, which disables
the TPM on TPM_RC_INITIALIZE
- In that patch, move the check ahead of the RETRY/TESTING break, where
it never ran, and skip TPM2_Startup, which a TPM that is already
started fails with TPM_RC_INITIALIZE
- Fix sashiko findings:
- Two timeouts ten minutes apart no longer disable an idle TPM
- Link to v1: https://patch.msgid.link/[email protected]

---
Breno Leitao (1):
tpm: Disable a TPM that stops responding

Jarkko Sakkinen (1):
tpm: Disable TPM on TPM_RC_INITIALIZE

 drivers/char/tpm/tpm-interface.c | 20 ++++++++++++++++++++
 drivers/char/tpm/tpm2-cmd.c      |  2 ++
 include/linux/tpm.h              |  1 +
 3 files changed, 23 insertions(+)

---
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
change-id: 20261110-tpm_unresponsive-a5f71c1db026

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>
#1 lore raw

PATCH v2 1/2 tpm: Disable a TPM that stops responding

A TPM that stops responding fails each command only after the transport timeout, and its callers keep sending more: the hwrng thread every 10 seconds forever, and userspace through /dev/tpmrm0. Each attempt holds tpm_mutex for the whole timeout and logs an error:

tpm tpm0: invalid TPM_STS.x 0xff, dumping stack for forensics tpm tpm0: tpm_try_transmit: send(): error -62
tpm tpm0: tpm_try_transmit: send(): error -62
...

The core already stops using a TPM it cannot trust: tpm_try_get_ops() fails with -EIO once TPM_CHIP_FLAG_DISABLE is set, which tpm2_load_null() does when it cannot restore the null key. Set the same flag once 60 commands in a row have timed out.

A completed command, whatever its TPM return code, resets the count. Some TPMs stall for half a minute, time out a handful of commands, and then recover, so a short streak must not disable them.

With only the hwrng retrying every 10 seconds, 60 timeouts take more than ten minutes. A userspace poller gets there sooner, but each of its commands still waits out the transport timeout.

The limit is the tpm.max_unanswered boot parameter, so that slow pre-production parts, such as FPGA prototypes, can raise it, or set it to 0 to never disable the TPM. A disabled TPM stays disabled until the driver is rebound or the machine reboots.

---
 drivers/char/tpm/tpm-interface.c | 15 +++++++++++++++
 include/linux/tpm.h              |  1 +
 2 files changed, 16 insertions(+)
drivers/char/tpm/tpm-interface.c +15 -0
index e0385b16616b46..b7865ccb799289 100644
@@ -40,6 +40,11 @@ module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
 MODULE_PARM_DESC(suspend_pcr,
 		 "PCR to use for dummy writes to facilitate flush on suspend.");
 
+static unsigned int tpm_max_unanswered = 60;
+module_param_named(max_unanswered, tpm_max_unanswered, uint, 0444);
+MODULE_PARM_DESC(max_unanswered,
+		 "Disable the TPM after this many commands in a row time out (0 = never).");
+
 /**
  * tpm_calc_ordinal_duration() - calculate the maximum command duration
  * @chip:    TPM chip to use.
@@ -268,6 +273,16 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz)
 		delay_msec *= 2;
 		memcpy(buf, save, save_size);
 	}
+
+	if (ret >= 0) {
+		/* we are good, reset nr_unanswered */
+		chip->nr_unanswered = 0;
+	} else if (ret == -ETIME &&
+		   ++chip->nr_unanswered == tpm_max_unanswered) {
+		dev_err(&chip->dev, "%u commands in a row timed out, disabling the TPM\n",
+			chip->nr_unanswered);
+		chip->flags |= TPM_CHIP_FLAG_DISABLE;
+	}
 	return ret;
 }
 
include/linux/tpm.h +1 -0
index 0db277af45c393..e8191585a68e7a 100644
@@ -131,6 +131,7 @@ struct tpm_chip {
 	struct hwrng hwrng;
 
 	struct mutex tpm_mutex;	/* tpm is processing */
+	unsigned int nr_unanswered;	/* commands in a row that timed out */
 
 	unsigned long timeout_a; /* jiffies */
 	unsigned long timeout_b; /* jiffies */
Signature · 1 line
2.53.0-Meta
maintainer
#2 lore raw

Re: [PATCH v2 1/2] tpm: Disable a TPM that stops responding

Quoted 39 lines · Breno Leitao

A TPM that stops responding fails each command only after the transport timeout, and its callers keep sending more: the hwrng thread every 10 seconds forever, and userspace through /dev/tpmrm0. Each attempt holds tpm_mutex for the whole timeout and logs an error:

tpm tpm0: invalid TPM_STS.x 0xff, dumping stack for forensics tpm tpm0: tpm_try_transmit: send(): error -62
tpm tpm0: tpm_try_transmit: send(): error -62
...

The core already stops using a TPM it cannot trust: tpm_try_get_ops() fails with -EIO once TPM_CHIP_FLAG_DISABLE is set, which tpm2_load_null() does when it cannot restore the null key. Set the same flag once 60 commands in a row have timed out.

A completed command, whatever its TPM return code, resets the count. Some TPMs stall for half a minute, time out a handful of commands, and then recover, so a short streak must not disable them.

With only the hwrng retrying every 10 seconds, 60 timeouts take more than ten minutes. A userspace poller gets there sooner, but each of its commands still waits out the transport timeout.

The limit is the tpm.max_unanswered boot parameter, so that slow pre-production parts, such as FPGA prototypes, can raise it, or set it to 0 to never disable the TPM. A disabled TPM stays disabled until the driver is rebound or the machine reboots.

---
 drivers/char/tpm/tpm-interface.c | 15 +++++++++++++++
 include/linux/tpm.h              |  1 +
 2 files changed, 16 insertions(+)
drivers/char/tpm/tpm-interface.c +0 -0
index e0385b16616b46..b7865ccb799289 100644

drivers/char/tpm/tpm-interface.c module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644); · line 46

Quoted 7 lines
drivers/char/tpm/tpm-interface.c +4 -0
@@ -40,6 +40,11 @@ module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
 MODULE_PARM_DESC(suspend_pcr,
 		 "PCR to use for dummy writes to facilitate flush on suspend.");
 
+static unsigned int tpm_max_unanswered = 60;
+module_param_named(max_unanswered, tpm_max_unanswered, uint, 0444);
+MODULE_PARM_DESC(max_unanswered,
+		 "Disable the TPM after this many commands in a row time out (0 = never).");

Documentation/admin/kernel-parameters.txt update is also needed.

tpm_max_missed_responses is what I would suggest, because it is more accurate e.g., on stating what is being counted :-)

drivers/char/tpm/tpm-interface.c ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) · line 278

Quoted 11 lines
drivers/char/tpm/tpm-interface.c +4 -0
+
 /**
  * tpm_calc_ordinal_duration() - calculate the maximum command duration
  * @chip:    TPM chip to use.
@@ -268,6 +273,16 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz)
 		delay_msec *= 2;
 		memcpy(buf, save, save_size);
 	}
+
+	if (ret >= 0) {
+		/* we are good, reset nr_unanswered */

I'm not a huge fan in general of third person plural in the source code comments. Probably a comment here is not needed at all as it does not state anything that would not be obvious (i.e. something nothing non-obvious is documented).

Quoted 15 lines
drivers/char/tpm/tpm-interface.c +7 -0
+		chip->nr_unanswered = 0;
+	} else if (ret == -ETIME &&
+		   ++chip->nr_unanswered == tpm_max_unanswered) {
+		dev_err(&chip->dev, "%u commands in a row timed out, disabling the TPM\n",
+			chip->nr_unanswered);
+		chip->flags |= TPM_CHIP_FLAG_DISABLE;
+	}
 	return ret;
 }
 
include/linux/tpm.h +0 -0
index 0db277af45c393..e8191585a68e7a 100644

include/linux/tpm.h struct tpm_chip { · line 134

Quoted 4 lines
include/linux/tpm.h +1 -0
@@ -131,6 +131,7 @@ struct tpm_chip {
 	struct hwrng hwrng;
 
 	struct mutex tpm_mutex;	/* tpm is processing */
+	unsigned int nr_unanswered;	/* commands in a row that timed out */

This would be then nr_lost_responses.

Quoted 7 lines
include/linux/tpm.h +0 -0
 	unsigned long timeout_a; /* jiffies */
 	unsigned long timeout_b; /* jiffies */
 
Signature · 1 line
2.53.0-Meta

Br, Jarkko

maintainer
#3 lore raw

Re: [PATCH v2 1/2] tpm: Disable a TPM that stops responding

Quoted 88 lines · Jarkko Sakkinen
Quoted 39 lines · Breno Leitao

A TPM that stops responding fails each command only after the transport timeout, and its callers keep sending more: the hwrng thread every 10 seconds forever, and userspace through /dev/tpmrm0. Each attempt holds tpm_mutex for the whole timeout and logs an error:

tpm tpm0: invalid TPM_STS.x 0xff, dumping stack for forensics tpm tpm0: tpm_try_transmit: send(): error -62
tpm tpm0: tpm_try_transmit: send(): error -62
...

The core already stops using a TPM it cannot trust: tpm_try_get_ops() fails with -EIO once TPM_CHIP_FLAG_DISABLE is set, which tpm2_load_null() does when it cannot restore the null key. Set the same flag once 60 commands in a row have timed out.

A completed command, whatever its TPM return code, resets the count. Some TPMs stall for half a minute, time out a handful of commands, and then recover, so a short streak must not disable them.

With only the hwrng retrying every 10 seconds, 60 timeouts take more than ten minutes. A userspace poller gets there sooner, but each of its commands still waits out the transport timeout.

The limit is the tpm.max_unanswered boot parameter, so that slow pre-production parts, such as FPGA prototypes, can raise it, or set it to 0 to never disable the TPM. A disabled TPM stays disabled until the driver is rebound or the machine reboots.

---
 drivers/char/tpm/tpm-interface.c | 15 +++++++++++++++
 include/linux/tpm.h              |  1 +
 2 files changed, 16 insertions(+)
drivers/char/tpm/tpm-interface.c +0 -0
index e0385b16616b46..b7865ccb799289 100644

drivers/char/tpm/tpm-interface.c module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644); · line 46

Quoted 7 lines
drivers/char/tpm/tpm-interface.c +4 -0
@@ -40,6 +40,11 @@ module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
 MODULE_PARM_DESC(suspend_pcr,
 		 "PCR to use for dummy writes to facilitate flush on suspend.");
 
+static unsigned int tpm_max_unanswered = 60;
+module_param_named(max_unanswered, tpm_max_unanswered, uint, 0444);
+MODULE_PARM_DESC(max_unanswered,
+		 "Disable the TPM after this many commands in a row time out (0 = never).");

Documentation/admin/kernel-parameters.txt update is also needed.

tpm_max_missed_responses is what I would suggest, because it is more accurate e.g., on stating what is being counted :-)

drivers/char/tpm/tpm-interface.c ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) · line 278

Quoted 11 lines
drivers/char/tpm/tpm-interface.c +4 -0
+
 /**
  * tpm_calc_ordinal_duration() - calculate the maximum command duration
  * @chip:    TPM chip to use.
@@ -268,6 +273,16 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz)
 		delay_msec *= 2;
 		memcpy(buf, save, save_size);
 	}
+
+	if (ret >= 0) {
+		/* we are good, reset nr_unanswered */

I'm not a huge fan in general of third person plural in the source code comments. Probably a comment here is not needed at all as it does not state anything that would not be obvious (i.e. something nothing non-obvious is documented).

Quoted 17 lines
drivers/char/tpm/tpm-interface.c +7 -0
+		chip->nr_unanswered = 0;
+	} else if (ret == -ETIME &&
+		   ++chip->nr_unanswered == tpm_max_unanswered) {
+		dev_err(&chip->dev, "%u commands in a row timed out, disabling the TPM\n",
+			chip->nr_unanswered);
+		chip->flags |= TPM_CHIP_FLAG_DISABLE;
+	}
 	return ret;
 }
 
include/linux/tpm.h +0 -0
index 0db277af45c393..e8191585a68e7a 100644
@@ -131,6 +131,7 @@ struct tpm_chip {
 	struct hwrng hwrng;
 
Quoted 4 lines

include/linux/tpm.h struct tpm_chip { · line 134

Quoted 2 lines
include/linux/tpm.h +1 -0
 	struct mutex tpm_mutex;	/* tpm is processing */
+	unsigned int nr_unanswered;	/* commands in a row that timed out */

This would be then nr_lost_responses.

Oops sorry.

I mean nr_missed_responses (and I would prefer "missed" over "lost").

Br, Jarkko

#4 lore raw

Re: [PATCH v2 1/2] tpm: Disable a TPM that stops responding

Quoted 89 lines · Jarkko Sakkinen
Quoted 88 lines · Jarkko Sakkinen
Quoted 39 lines · Breno Leitao

A TPM that stops responding fails each command only after the transport timeout, and its callers keep sending more: the hwrng thread every 10 seconds forever, and userspace through /dev/tpmrm0. Each attempt holds tpm_mutex for the whole timeout and logs an error:

tpm tpm0: invalid TPM_STS.x 0xff, dumping stack for forensics tpm tpm0: tpm_try_transmit: send(): error -62
tpm tpm0: tpm_try_transmit: send(): error -62
...

The core already stops using a TPM it cannot trust: tpm_try_get_ops() fails with -EIO once TPM_CHIP_FLAG_DISABLE is set, which tpm2_load_null() does when it cannot restore the null key. Set the same flag once 60 commands in a row have timed out.

A completed command, whatever its TPM return code, resets the count. Some TPMs stall for half a minute, time out a handful of commands, and then recover, so a short streak must not disable them.

With only the hwrng retrying every 10 seconds, 60 timeouts take more than ten minutes. A userspace poller gets there sooner, but each of its commands still waits out the transport timeout.

The limit is the tpm.max_unanswered boot parameter, so that slow pre-production parts, such as FPGA prototypes, can raise it, or set it to 0 to never disable the TPM. A disabled TPM stays disabled until the driver is rebound or the machine reboots.

---
 drivers/char/tpm/tpm-interface.c | 15 +++++++++++++++
 include/linux/tpm.h              |  1 +
 2 files changed, 16 insertions(+)
drivers/char/tpm/tpm-interface.c +0 -0
index e0385b16616b46..b7865ccb799289 100644

drivers/char/tpm/tpm-interface.c module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644); · line 46

Quoted 7 lines
drivers/char/tpm/tpm-interface.c +4 -0
@@ -40,6 +40,11 @@ module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
 MODULE_PARM_DESC(suspend_pcr,
 		 "PCR to use for dummy writes to facilitate flush on suspend.");
 
+static unsigned int tpm_max_unanswered = 60;
+module_param_named(max_unanswered, tpm_max_unanswered, uint, 0444);
+MODULE_PARM_DESC(max_unanswered,
+		 "Disable the TPM after this many commands in a row time out (0 = never).");

Documentation/admin/kernel-parameters.txt update is also needed.

tpm_max_missed_responses is what I would suggest, because it is more accurate e.g., on stating what is being counted :-)

drivers/char/tpm/tpm-interface.c ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) · line 278

Quoted 11 lines
drivers/char/tpm/tpm-interface.c +4 -0
+
 /**
  * tpm_calc_ordinal_duration() - calculate the maximum command duration
  * @chip:    TPM chip to use.
@@ -268,6 +273,16 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz)
 		delay_msec *= 2;
 		memcpy(buf, save, save_size);
 	}
+
+	if (ret >= 0) {
+		/* we are good, reset nr_unanswered */

I'm not a huge fan in general of third person plural in the source code comments. Probably a comment here is not needed at all as it does not state anything that would not be obvious (i.e. something nothing non-obvious is documented).

Quoted 17 lines
drivers/char/tpm/tpm-interface.c +7 -0
+		chip->nr_unanswered = 0;
+	} else if (ret == -ETIME &&
+		   ++chip->nr_unanswered == tpm_max_unanswered) {
+		dev_err(&chip->dev, "%u commands in a row timed out, disabling the TPM\n",
+			chip->nr_unanswered);
+		chip->flags |= TPM_CHIP_FLAG_DISABLE;
+	}
 	return ret;
 }
 
include/linux/tpm.h +0 -0
index 0db277af45c393..e8191585a68e7a 100644
@@ -131,6 +131,7 @@ struct tpm_chip {
 	struct hwrng hwrng;
 
Quoted 8 lines
Quoted 4 lines

include/linux/tpm.h struct tpm_chip { · line 134

Quoted 2 lines
include/linux/tpm.h +1 -0
 	struct mutex tpm_mutex;	/* tpm is processing */
+	unsigned int nr_unanswered;	/* commands in a row that timed out */

This would be then nr_lost_responses.

Oops sorry.

I mean nr_missed_responses (and I would prefer "missed" over "lost").

Ack, respining...

--breno

#5 lore raw

Re: [PATCH v2 1/2] tpm: Disable a TPM that stops responding

In reply to Jarkko Sakkinen
Quoted 6 lines · Jarkko Sakkinen
Quoted 2 lines

This would be then nr_lost_responses.

Oops sorry.

I mean nr_missed_responses (and I would prefer "missed" over "lost").

Would you hate if I go with max_missed_responses?

maintainer
#6 lore raw

Re: [PATCH v2 1/2] tpm: Disable a TPM that stops responding

Quoted 9 lines · Breno Leitao
Quoted 6 lines · Jarkko Sakkinen
Quoted 2 lines

This would be then nr_lost_responses.

Oops sorry.

I mean nr_missed_responses (and I would prefer "missed" over "lost").

Would you hate if I go with max_missed_responses?

It's a great question. Here I think asymmetry defines things better, and makes sense also few months from now.

So I think this would be most consistent:

1. kernel command-line: tpm_max_missed_responses
2. tpm_chip: nr_missed_responses.

The first defines the modulo and second counts up to that.

Can't recall (and too lazy to check) how it exactly was in your code change but I would formalize all this along the lines of:

	if (!(++chip->nr_missed_responses % tpm_max_missed_responses)) {
		/* chip->flags |= TPM2_CHIP_FLAG_DISABLE etc. and of course bail out. */
	}

	/* continue doing things */

[those comments are not part of the proposal]

Br, Jarkko

maintainer
#7 lore raw

Re: [PATCH v2 1/2] tpm: Disable a TPM that stops responding

Quoted 19 lines · Jarkko Sakkinen
Quoted 9 lines · Breno Leitao
Quoted 6 lines · Jarkko Sakkinen
Quoted 2 lines

This would be then nr_lost_responses.

Oops sorry.

I mean nr_missed_responses (and I would prefer "missed" over "lost").

Would you hate if I go with max_missed_responses?

It's a great question. Here I think asymmetry defines things better, and makes sense also few months from now.

So I think this would be most consistent:

1. kernel command-line: tpm_max_missed_responses
2. tpm_chip: nr_missed_responses.

Quoted 6 lines

The first defines the modulo and second counts up to that.

Can't recall (and too lazy to check) how it exactly was in your code change but I would formalize all this along the lines of:

	if (!(++chip->nr_missed_responses % tpm_max_missed_responses)) {

Ugh, sorry that is broken as hell :-)

I mean:

   if (++chip->nr_missed_responses > tpm_max_missed_responses) {

   }

Probably was already something like similar anyway in your changes. I just wanted to highlight how the naming makes in code-level a lot of common sense...

Br, Jarkko

#8 lore raw

PATCH v2 2/2 tpm: Disable TPM on TPM_RC_INITIALIZE

In reply to Breno Leitao

From: Jarkko Sakkinen <[email protected]>

If the TPM has been spuriously disabled, the game is over. Let's reflect this truth with TPM_CHIP_FLAG_DISABLE.

[[email protected]: 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]

---
 drivers/char/tpm/tpm-interface.c | 5 +++++
 drivers/char/tpm/tpm2-cmd.c      | 2 ++
 2 files changed, 7 insertions(+)
drivers/char/tpm/tpm-interface.c +5 -0
index b7865ccb799289..144e2dbae66853 100644
@@ -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;
 		/*
drivers/char/tpm/tpm2-cmd.c +2 -0
index 4b2bb2ddc321a9..65928ae85b496c 100644
@@ -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;
Signature · 1 line
2.53.0-Meta
maintainer Reviewed-by on v2 2/2
#9 lore raw

Re: [PATCH v2 2/2] tpm: Disable TPM on TPM_RC_INITIALIZE

Quoted 21 lines · Breno Leitao

From: Jarkko Sakkinen <[email protected]>

If the TPM has been spuriously disabled, the game is over. Let's reflect this truth with TPM_CHIP_FLAG_DISABLE.

[[email protected]: 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]

---
 drivers/char/tpm/tpm-interface.c | 5 +++++
 drivers/char/tpm/tpm2-cmd.c      | 2 ++
 2 files changed, 7 insertions(+)
drivers/char/tpm/tpm-interface.c +0 -0
index b7865ccb799289..144e2dbae66853 100644

drivers/char/tpm/tpm-interface.c ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz) · line 256

Quoted 5 lines
drivers/char/tpm/tpm-interface.c +2 -0
@@ -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) {

Good catch! Thanks.

Quoted 23 lines
drivers/char/tpm/tpm-interface.c +3 -0
+			chip->flags |= TPM_CHIP_FLAG_DISABLE;
+			break;
+		}
 		if (rc != TPM2_RC_RETRY && rc != TPM2_RC_TESTING)
 			break;
 		/*
drivers/char/tpm/tpm2-cmd.c +2 -0
index 4b2bb2ddc321a9..65928ae85b496c 100644
@@ -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;
Signature · 2 lines
-- 
2.53.0-Meta

Br, Jarkko

#10 lore raw

Re: [PATCH v2 2/2] tpm: Disable TPM on TPM_RC_INITIALIZE

In reply to Breno Leitao
Quoted 4 lines · On Thu, 12 Nov 2026 04:30:18 -0800 Breno Leitao <[email protected]> wrote:

From: Jarkko Sakkinen <[email protected]>

If the TPM has been spuriously disabled, the game is over. Let's reflect this truth with TPM_CHIP_FLAG_DISABLE.

Shouldn't it be completely 'game over'?
(aka panic time...)

David

maintainer
#11 lore raw

Re: [PATCH v2 2/2] tpm: Disable TPM on TPM_RC_INITIALIZE

Quoted 10 lines · David Laight
Quoted 4 lines · On Thu, 12 Nov 2026 04:30:18 -0800 Breno Leitao <[email protected]> wrote:

From: Jarkko Sakkinen <[email protected]>

If the TPM has been spuriously disabled, the game is over. Let's reflect this truth with TPM_CHIP_FLAG_DISABLE.

Shouldn't it be completely 'game over'?
(aka panic time...)

There's nothing pointing to that direction. Nothing is really broken except likely firmware bug or similar situation. We don't want to brick the machine because of that. Neither security is endangered as anything that was sealed with TPM, it is inaccessible.

It's also useful for us that any possible user has a chance to run e.g., acpidump without kernel pulling the carpet.

Quoted 2 lines

David

Br, Jarkko

maintainer
#12 lore raw

Re: [PATCH v2 2/2] tpm: Disable TPM on TPM_RC_INITIALIZE

Quoted 12 lines · Jarkko Sakkinen
Quoted 10 lines · David Laight
Quoted 4 lines · On Thu, 12 Nov 2026 04:30:18 -0800 Breno Leitao <[email protected]> wrote:

From: Jarkko Sakkinen <[email protected]>

If the TPM has been spuriously disabled, the game is over. Let's reflect this truth with TPM_CHIP_FLAG_DISABLE.

Shouldn't it be completely 'game over'?
(aka panic time...)

Quoted 7 lines

There's nothing pointing to that direction. Nothing is really broken except likely firmware bug or similar situation. We don't want to brick the machine because of that. Neither security is endangered as anything that was sealed with TPM, it is inaccessible.

It's also useful for us that any possible user has a chance to run e.g., acpidump without kernel pulling the carpet.

And fTPM tripping has been reoccuring theme since they first arrived in 2014; not something extremely rare that "almost never" would happen.

Br, Jarkko