Commit 9f75c822 authored by Roberto Sassu's avatar Roberto Sassu Committed by Jarkko Sakkinen

KEYS: trusted: correctly initialize digests and fix locking issue

Commit 0b6cf6b9 ("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: stable@vger.kernel.org
Fixes: 0b6cf6b9 ("tpm: pass an array of tpm_extend_digest structures to tpm_pcr_extend()")
Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Suggested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
parent 34cd83bb
...@@ -320,18 +320,22 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, ...@@ -320,18 +320,22 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
if (!chip) if (!chip)
return -ENODEV; return -ENODEV;
for (i = 0; i < chip->nr_allocated_banks; i++) for (i = 0; i < chip->nr_allocated_banks; i++) {
if (digests[i].alg_id != chip->allocated_banks[i].alg_id) if (digests[i].alg_id != chip->allocated_banks[i].alg_id) {
return -EINVAL; rc = EINVAL;
goto out;
}
}
if (chip->flags & TPM_CHIP_FLAG_TPM2) { if (chip->flags & TPM_CHIP_FLAG_TPM2) {
rc = tpm2_pcr_extend(chip, pcr_idx, digests); rc = tpm2_pcr_extend(chip, pcr_idx, digests);
tpm_put_ops(chip); goto out;
return rc;
} }
rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest, rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest,
"attempting extend a PCR value"); "attempting extend a PCR value");
out:
tpm_put_ops(chip); tpm_put_ops(chip);
return rc; return rc;
} }
......
...@@ -1228,11 +1228,16 @@ static int __init trusted_shash_alloc(void) ...@@ -1228,11 +1228,16 @@ static int __init trusted_shash_alloc(void)
static int __init init_digests(void) static int __init init_digests(void)
{ {
int i;
digests = kcalloc(chip->nr_allocated_banks, sizeof(*digests), digests = kcalloc(chip->nr_allocated_banks, sizeof(*digests),
GFP_KERNEL); GFP_KERNEL);
if (!digests) if (!digests)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < chip->nr_allocated_banks; i++)
digests[i].alg_id = chip->allocated_banks[i].alg_id;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment