]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tpm: Add upgrade/reduced mode support for TPM1.2 modules
authorStefan Mahnke-Hartmann <stefan.mahnke-hartmann@infineon.com>
Fri, 3 Jun 2022 08:41:58 +0000 (10:41 +0200)
committerJarkko Sakkinen <jarkko@kernel.org>
Wed, 3 Aug 2022 20:56:19 +0000 (23:56 +0300)
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>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
drivers/char/tpm/tpm.h
drivers/char/tpm/tpm1-cmd.c

index 2163c6ee0d364f3f8ee935e5abae8f547b4a886f..24ee4e1cc452a006945ffbe9c257275332a46d6d 100644 (file)
@@ -55,6 +55,7 @@ enum tpm_addr {
 #define TPM_WARN_DOING_SELFTEST 0x802
 #define TPM_ERR_DEACTIVATED     0x6
 #define TPM_ERR_DISABLED        0x7
+#define TPM_ERR_FAILEDSELFTEST  0x1C
 #define TPM_ERR_INVALID_POSTINIT 38
 
 #define TPM_TAG_RQU_COMMAND 193
index f7dc986fa4a0a2044c589940714a56466b031b83..cf64c738510529bc8b8a751bdaac20cfe6b884bc 100644 (file)
@@ -709,7 +709,12 @@ int tpm1_auto_startup(struct tpm_chip *chip)
        if (rc)
                goto out;
        rc = tpm1_do_selftest(chip);
-       if (rc) {
+       if (rc == TPM_ERR_FAILEDSELFTEST) {
+               dev_warn(&chip->dev, "TPM self test failed, switching to the firmware upgrade mode\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 failed\n");
                goto out;
        }