• axelj's avatar
    tpm: Add Upgrade/Reduced mode support for TPM2 modules · 0aa69878
    axelj authored
    If something went wrong during the TPM firmware upgrade, like power
    failure or the firmware image file get corrupted, the TPM might end
    up in Upgrade or Failure mode upon the next start. The state is
    persistent between the TPM power cycle/restart.
    
    According to TPM specification:
     * If the TPM is in Upgrade mode, it will answer with TPM2_RC_UPGRADE
       to all commands except TPM2_FieldUpgradeData(). It may also accept
       other commands if it is able to complete them using the previously
       installed firmware.
     * If the TPM is in Failure mode, it will allow performing TPM
       initialization but will not provide any crypto operations.
       Will happily respond to Field Upgrade calls.
    
    Change the behavior of the tpm2_auto_startup(), so it detects the active
    running mode of the TPM by adding the following checks.  If
    tpm2_do_selftest() call returns TPM2_RC_UPGRADE, the TPM is in Upgrade
    mode.
    If the TPM is in Failure mode, it will successfully respond to both
    tpm2_do_selftest() and tpm2_startup() calls. Although, will fail to
    answer to tpm2_get_cc_attrs_tbl(). Use this fact to conclude that TPM is
    in Failure mode.
    
    If detected that the TPM is in the Upgrade or Failure mode, the function
    sets TPM_CHIP_FLAG_FIRMWARE_UPGRADE_MODE flag.
    
    The TPM_CHIP_FLAG_FIRMWARE_UPGRADE_MODE flag is used later during driver
    initialization/deinitialization to disable functionality which makes no
    sense or will fail in the current TPM state. Following functionality is
    affected:
     * Do not register TPM as a hwrng
     * Do not register sysfs entries which provide information impossible to
       obtain in limited mode
     * Do not register resource managed character device
    Signed-off-by: default avataraxelj <axelj@axis.com>
    Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
    Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
    0aa69878
tpm-sysfs.c 13.1 KB