Skip to content

Commit cc7d859

Browse files
committed
tpm: Rollback tpm2_load_null()
Do not continue on tpm2_create_primary() failure in tpm2_load_null(). Cc: [email protected] # v6.10+ Fixes: eb24c97 ("tpm: disable the TPM if NULL name changes") Reviewed-by: Stefan Berger <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent d658d59 commit cc7d859

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

drivers/char/tpm/tpm2-sessions.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -915,33 +915,37 @@ static int tpm2_parse_start_auth_session(struct tpm2_auth *auth,
915915

916916
static int tpm2_load_null(struct tpm_chip *chip, u32 *null_key)
917917
{
918-
int rc;
919918
unsigned int offset = 0; /* dummy offset for null seed context */
920919
u8 name[SHA256_DIGEST_SIZE + 2];
920+
u32 tmp_null_key;
921+
int rc;
921922

922923
rc = tpm2_load_context(chip, chip->null_key_context, &offset,
923-
null_key);
924-
if (rc != -EINVAL)
925-
return rc;
924+
&tmp_null_key);
925+
if (rc != -EINVAL) {
926+
if (!rc)
927+
*null_key = tmp_null_key;
928+
goto err;
929+
}
926930

927-
/* an integrity failure may mean the TPM has been reset */
928-
dev_err(&chip->dev, "NULL key integrity failure!\n");
929-
/* check the null name against what we know */
930-
tpm2_create_primary(chip, TPM2_RH_NULL, NULL, name);
931-
if (memcmp(name, chip->null_key_name, sizeof(name)) == 0)
932-
/* name unchanged, assume transient integrity failure */
933-
return rc;
934-
/*
935-
* Fatal TPM failure: the NULL seed has actually changed, so
936-
* the TPM must have been illegally reset. All in-kernel TPM
937-
* operations will fail because the NULL primary can't be
938-
* loaded to salt the sessions, but disable the TPM anyway so
939-
* userspace programmes can't be compromised by it.
940-
*/
941-
dev_err(&chip->dev, "NULL name has changed, disabling TPM due to interference\n");
931+
/* Try to re-create null key, given the integrity failure: */
932+
rc = tpm2_create_primary(chip, TPM2_RH_NULL, &tmp_null_key, name);
933+
if (rc)
934+
goto err;
935+
936+
/* Return null key if the name has not been changed: */
937+
if (!memcmp(name, chip->null_key_name, sizeof(name))) {
938+
*null_key = tmp_null_key;
939+
return 0;
940+
}
941+
942+
/* Deduce from the name change TPM interference: */
943+
dev_err(&chip->dev, "null key integrity check failed\n");
944+
tpm2_flush_context(chip, tmp_null_key);
942945
chip->flags |= TPM_CHIP_FLAG_DISABLE;
943946

944-
return rc;
947+
err:
948+
return rc ? -ENODEV : 0;
945949
}
946950

947951
/**

0 commit comments

Comments
 (0)