Skip to contentSkip to conversation

tpm: Replace WARN_ONCE() with dev_err_once() in tpm_tis_status()

PATCH Superseded Jarkko Sakkinen 3 participants 4 messages May 31, 2021 – Jun 1, 2021

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 1/1 tpm: Replace WARN_ONCE() with dev_err_once() in tpm_tis_status()

Do not torn down the system when getting invalid status from a TPM chip. This can happen when panic-on-warn is used.

In addition, print out the value of TPM_STS.x instead of "invalid status". In order to get the earlier benefits for forensics, also call dump_stack().

Fixes 55707d531af6 ("tpm_tis: Add a check for invalid status")
Cc Hans de Goede <[email protected]>
Cc Greg KH <[email protected]>
---
 drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +10 -1
index 55b9d3965ae1..514a481829c9 100644
@@ -202,7 +202,16 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
 		 * acquired.  Usually because tpm_try_get_ops() hasn't
 		 * been called before doing a TPM operation.
 		 */
-		WARN_ONCE(1, "TPM returned invalid status\n");
+		dev_err_once(&chip->dev, "invalid TPM_STS.x 0x%02x, dumping stack for forensics\n",
+			     status);
+
+		/*
+		 * Dump stack for forensics, as invalid TPM_STS.x could be
+		 * potentially triggered by impaired tpm_try_get_ops() or
+		 * tpm_find_get_ops().
+		 */
+		dump_stack();
+
 		return 0;
 	}
 
Signature · 1 line
2.31.1
Reviewed-by Greg Kroah-Hartman on v1 1/1
#1 lore raw
Quoted 28 lines · Jarkko Sakkinen

Do not torn down the system when getting invalid status from a TPM chip. This can happen when panic-on-warn is used.

In addition, print out the value of TPM_STS.x instead of "invalid status". In order to get the earlier benefits for forensics, also call dump_stack().

Fixes 55707d531af6 ("tpm_tis: Add a check for invalid status")
Cc Hans de Goede <[email protected]>
Cc Greg KH <[email protected]>
---
 drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +2 -1
index 55b9d3965ae1..514a481829c9 100644
@@ -202,7 +202,16 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
 		 * acquired.  Usually because tpm_try_get_ops() hasn't
 		 * been called before doing a TPM operation.
 		 */
-		WARN_ONCE(1, "TPM returned invalid status\n");
+		dev_err_once(&chip->dev, "invalid TPM_STS.x 0x%02x, dumping stack for forensics\n",
+			     status);

drivers/char/tpm/tpm_tis_core.c static u8 tpm_tis_status(struct tpm_chip *chip) · line 216

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +8 -0
+
+		/*
+		 * Dump stack for forensics, as invalid TPM_STS.x could be
+		 * potentially triggered by impaired tpm_try_get_ops() or
+		 * tpm_find_get_ops().
+		 */
+		dump_stack();
+
 		return 0;
 	}
#2 lore raw
In reply to Jarkko Sakkinen

Dear Jarkko,

Am 31.05.21 um 06:51 schrieb Jarkko Sakkinen:

Quoted 1 line

Do not torn down the system when getting invalid status from a TPM chip.

Nit: Do not *tear* down …?

Quoted 1 line

This can happen when panic-on-warn is used.

Hmm, I’d say it works as expected then? Shouldn’t an invalid status of an important device like TPM considered a warning?

Quoted 25 lines

In addition, print out the value of TPM_STS.x instead of "invalid status". In order to get the earlier benefits for forensics, also call dump_stack().

Fixes 55707d531af6 ("tpm_tis: Add a check for invalid status")
Cc Hans de Goede <[email protected]>
Cc Greg KH <[email protected]>
---
  drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +2 -1
index 55b9d3965ae1..514a481829c9 100644
@@ -202,7 +202,16 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
  		 * acquired.  Usually because tpm_try_get_ops() hasn't
  		 * been called before doing a TPM operation.
  		 */
-		WARN_ONCE(1, "TPM returned invalid status\n");
+		dev_err_once(&chip->dev, "invalid TPM_STS.x 0x%02x, dumping stack for forensics\n",
+			     status);

drivers/char/tpm/tpm_tis_core.c static u8 tpm_tis_status(struct tpm_chip *chip) · line 216

Quoted 10 lines
drivers/char/tpm/tpm_tis_core.c +8 -0
+
+		/*
+		 * Dump stack for forensics, as invalid TPM_STS.x could be
+		 * potentially triggered by impaired tpm_try_get_ops() or
+		 * tpm_find_get_ops().
+		 */
+		dump_stack();
+
  		return 0;
  	}

Kind regards,

Paul

author maintainer
#3 lore raw
Quoted 7 lines · Paul Menzel

Dear Jarkko,

Am 31.05.21 um 06:51 schrieb Jarkko Sakkinen:

Quoted 1 line

Do not torn down the system when getting invalid status from a TPM chip.

Nit: Do not *tear* down …?

Oops, a typo, thank you.

Quoted 4 lines
Quoted 1 line

This can happen when panic-on-warn is used.

Hmm, I’d say it works as expected then? Shouldn’t an invalid status of an important device like TPM considered a warning?

By warning do you mean WARN() or pr_warn()?

/Jarkko