All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tpm: Add upgrade/reduced mode support for TPM1.2 modules
@ 2022-06-02 16:13 Stefan Mahnke-Hartmann
  2022-06-03  4:26 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Mahnke-Hartmann @ 2022-06-02 16:13 UTC (permalink / raw)
  To: jarkko, linux-integrity, linux-kernel
  Cc: peterhuewe, jgg, Stefan Mahnke-Hartmann

In case a TPM in failure mode is detected, the TPM should be accessible
through a transparent communication channel for analysing purposes (e.g.
TPM_GetTestResult) or a field upgrade. Since a TPM in failure mode has
similar reduced functionality as in field upgrade mode, the flag
TPM_CHIP_FLAG_FIRMWARE_UPGRADE is also valid.

As described in TCG TPM Main Part1 Design Principles, Revision 116,
chapter 9.2.1. the TPM also allows an update function in case a TPM is
in failure mode.

If the TPM in failure mode is detected, the function tpm1_auto_startup()
sets TPM_CHIP_FLAG_FIRMWARE_UPGRADE flag, which is used later during
driver initialization/deinitialization to disable functionality which
makes no sense or will fail in the current TPM state. The following
functionality is affected:
 * Do not register TPM as a hwrng
 * Do not get pcr allocation
 * Do not register sysfs entries which provide information impossible to
   obtain in limited mode

Signed-off-by: Stefan Mahnke-Hartmann <stefan.mahnke-hartmann@infineon.com>
---
Changelog:
 * v2:
   * Commit message updated.
   * Error handling for failed self test and other errors seperated.
.
 drivers/char/tpm/tpm.h      | 1 +
 drivers/char/tpm/tpm1-cmd.c | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2163c6ee0d36..c0778498bc41 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -56,6 +56,7 @@ enum tpm_addr {
 #define TPM_ERR_DEACTIVATED     0x6
 #define TPM_ERR_DISABLED        0x7
 #define TPM_ERR_INVALID_POSTINIT 38
+#define TPM_ERR_FAILEDSELFTEST  0x1C
 
 #define TPM_TAG_RQU_COMMAND 193
 
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index f7dc986fa4a0..fe21679ba0b6 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -709,8 +709,13 @@ int tpm1_auto_startup(struct tpm_chip *chip)
 	if (rc)
 		goto out;
 	rc = tpm1_do_selftest(chip);
-	if (rc) {
-		dev_err(&chip->dev, "TPM self test failed\n");
+	if (rc == TPM_ERR_FAILEDSELFTEST) {
+		dev_err(&chip->dev, "TPM self test failed, so the TPM has limited functionality\n");
+		/* A TPM in this state possibly allows or needs a firmware upgrade */
+		chip->flags |= TPM_CHIP_FLAG_FIRMWARE_UPGRADE;
+		return 0;
+	} else if (rc) {
+		dev_err(&chip->dev, "TPM self test not successful\n");
 		goto out;
 	}
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] tpm: Add upgrade/reduced mode support for TPM1.2 modules
  2022-06-02 16:13 [PATCH v2] tpm: Add upgrade/reduced mode support for TPM1.2 modules Stefan Mahnke-Hartmann
@ 2022-06-03  4:26 ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2022-06-03  4:26 UTC (permalink / raw)
  To: Stefan Mahnke-Hartmann; +Cc: linux-integrity, linux-kernel, peterhuewe, jgg

On Thu, Jun 02, 2022 at 06:13:01PM +0200, Stefan Mahnke-Hartmann wrote:
> In case a TPM in failure mode is detected, the TPM should be accessible
> through a transparent communication channel for analysing purposes (e.g.
> TPM_GetTestResult) or a field upgrade. Since a TPM in failure mode has
> similar reduced functionality as in field upgrade mode, the flag
> TPM_CHIP_FLAG_FIRMWARE_UPGRADE is also valid.
> 
> As described in TCG TPM Main Part1 Design Principles, Revision 116,
> chapter 9.2.1. the TPM also allows an update function in case a TPM is
> in failure mode.
> 
> If the TPM in failure mode is detected, the function tpm1_auto_startup()
> sets TPM_CHIP_FLAG_FIRMWARE_UPGRADE flag, which is used later during
> driver initialization/deinitialization to disable functionality which
> makes no sense or will fail in the current TPM state. The following
> functionality is affected:
>  * Do not register TPM as a hwrng
>  * Do not get pcr allocation
>  * Do not register sysfs entries which provide information impossible to
>    obtain in limited mode
> 
> Signed-off-by: Stefan Mahnke-Hartmann <stefan.mahnke-hartmann@infineon.com>
> ---
> Changelog:
>  * v2:
>    * Commit message updated.
>    * Error handling for failed self test and other errors seperated.
> .
>  drivers/char/tpm/tpm.h      | 1 +
>  drivers/char/tpm/tpm1-cmd.c | 9 +++++++--
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 2163c6ee0d36..c0778498bc41 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -56,6 +56,7 @@ enum tpm_addr {
>  #define TPM_ERR_DEACTIVATED     0x6
>  #define TPM_ERR_DISABLED        0x7
>  #define TPM_ERR_INVALID_POSTINIT 38
> +#define TPM_ERR_FAILEDSELFTEST  0x1C
>  
>  #define TPM_TAG_RQU_COMMAND 193
>  
> diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
> index f7dc986fa4a0..fe21679ba0b6 100644
> --- a/drivers/char/tpm/tpm1-cmd.c
> +++ b/drivers/char/tpm/tpm1-cmd.c
> @@ -709,8 +709,13 @@ int tpm1_auto_startup(struct tpm_chip *chip)
>  	if (rc)
>  		goto out;
>  	rc = tpm1_do_selftest(chip);
> -	if (rc) {
> -		dev_err(&chip->dev, "TPM self test failed\n");
> +	if (rc == TPM_ERR_FAILEDSELFTEST) {
> +		dev_err(&chip->dev, "TPM self test failed, so the TPM has limited functionality\n");

Given that returning to a legit state, as far as driver is concerned,
i.e. firmware upgrade mode, I would use the following warn here instead:

dev_warn(&chip->dev, "TPM self test failed, switching to the firmware upgrade mode\n");

It's a success state because you are returning zero.


> +		/* A TPM in this state possibly allows or needs a firmware upgrade */
> +		chip->flags |= TPM_CHIP_FLAG_FIRMWARE_UPGRADE;
> +		return 0;
> +	} else if (rc) {
> +		dev_err(&chip->dev, "TPM self test not successful\n");

Why did you change the error message?

>  		goto out;
>  	}
>  
> -- 
> 2.25.1
> 

BR, Jarkko

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-03  4:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 16:13 [PATCH v2] tpm: Add upgrade/reduced mode support for TPM1.2 modules Stefan Mahnke-Hartmann
2022-06-03  4:26 ` Jarkko Sakkinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.