Skip to content

Commit

Permalink
KEYS: trusted: correctly initialize digests and fix locking issue
Browse files Browse the repository at this point in the history
Commit 0b6cf6b ("tpm: pass an array of tpm_extend_digest structures to
tpm_pcr_extend()") modifies tpm_pcr_extend() to accept a digest for each
PCR bank. After modification, tpm_pcr_extend() expects that digests are
passed in the same order as the algorithms set in chip->allocated_banks.

This patch fixes two issues introduced in the last iterations of the patch
set: missing initialization of the TPM algorithm ID in the tpm_digest
structures passed to tpm_pcr_extend() by the trusted key module, and
unreleased locks in the TPM driver due to returning from tpm_pcr_extend()
without calling tpm_put_ops().

Cc: [email protected]
Fixes: 0b6cf6b ("tpm: pass an array of tpm_extend_digest structures to tpm_pcr_extend()")
Signed-off-by: Roberto Sassu <[email protected]>
Suggested-by: Jarkko Sakkinen <[email protected]>
Reviewed-by: Jerry Snitselaar <[email protected]>
Reviewed-by: Jarkko Sakkinen <[email protected]>
Signed-off-by: Jarkko Sakkinen <[email protected]>
  • Loading branch information
robertosassu authored and Jarkko Sakkinen committed Sep 24, 2019
1 parent 34cd83b commit 9f75c82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions drivers/char/tpm/tpm-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,22 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
if (!chip)
return -ENODEV;

for (i = 0; i < chip->nr_allocated_banks; i++)
if (digests[i].alg_id != chip->allocated_banks[i].alg_id)
return -EINVAL;
for (i = 0; i < chip->nr_allocated_banks; i++) {
if (digests[i].alg_id != chip->allocated_banks[i].alg_id) {
rc = EINVAL;
goto out;
}
}

if (chip->flags & TPM_CHIP_FLAG_TPM2) {
rc = tpm2_pcr_extend(chip, pcr_idx, digests);
tpm_put_ops(chip);
return rc;
goto out;
}

rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest,
"attempting extend a PCR value");

out:
tpm_put_ops(chip);
return rc;
}
Expand Down
5 changes: 5 additions & 0 deletions security/keys/trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,11 +1228,16 @@ static int __init trusted_shash_alloc(void)

static int __init init_digests(void)
{
int i;

digests = kcalloc(chip->nr_allocated_banks, sizeof(*digests),
GFP_KERNEL);
if (!digests)
return -ENOMEM;

for (i = 0; i < chip->nr_allocated_banks; i++)
digests[i].alg_id = chip->allocated_banks[i].alg_id;

return 0;
}

Expand Down

0 comments on commit 9f75c82

Please sign in to comment.