Skip to content

Commit f3c82ad

Browse files
author
Jarkko Sakkinen
committed
tpm: fix checks for policy digest existence in tpm2_seal_trusted()
In my original patch sealing with policy was done with dynamically allocated buffer that I changed later into an array so the checks in tpm2-cmd.c became invalid. This patch fixes the issue. Fixes: 5beb0c4 ("keys, trusted: seal with a TPM2 authorization policy") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Acked-by: Peter Huewe <peterhuewe@gmx.de>
1 parent e5be990 commit f3c82ad

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

‎drivers/char/tpm/tpm2-cmd.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,16 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
478478
tpm_buf_append_u8(&buf, payload->migratable);
479479

480480
/* public */
481-
if (options->policydigest)
482-
tpm_buf_append_u16(&buf, 14 + options->digest_len);
483-
else
484-
tpm_buf_append_u16(&buf, 14);
485-
481+
tpm_buf_append_u16(&buf, 14 + options->policydigest_len);
486482
tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH);
487483
tpm_buf_append_u16(&buf, hash);
488484

489485
/* policy */
490-
if (options->policydigest) {
486+
if (options->policydigest_len) {
491487
tpm_buf_append_u32(&buf, 0);
492-
tpm_buf_append_u16(&buf, options->digest_len);
488+
tpm_buf_append_u16(&buf, options->policydigest_len);
493489
tpm_buf_append(&buf, options->policydigest,
494-
options->digest_len);
490+
options->policydigest_len);
495491
} else {
496492
tpm_buf_append_u32(&buf, TPM2_ATTR_USER_WITH_AUTH);
497493
tpm_buf_append_u16(&buf, 0);

‎include/keys/trusted-type.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct trusted_key_options {
3838
unsigned char pcrinfo[MAX_PCRINFO_SIZE];
3939
int pcrlock;
4040
uint32_t hash;
41-
uint32_t digest_len;
41+
uint32_t policydigest_len;
4242
unsigned char policydigest[MAX_DIGEST_SIZE];
4343
uint32_t policyhandle;
4444
};

‎security/keys/trusted.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
744744
unsigned long handle;
745745
unsigned long lock;
746746
unsigned long token_mask = 0;
747+
unsigned int digest_len;
747748
int i;
748749
int tpm2;
749750

@@ -752,7 +753,6 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
752753
return tpm2;
753754

754755
opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1;
755-
opt->digest_len = hash_digest_size[opt->hash];
756756

757757
while ((p = strsep(&c, " \t"))) {
758758
if (*p == '\0' || *p == ' ' || *p == '\t')
@@ -812,8 +812,6 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
812812
for (i = 0; i < HASH_ALGO__LAST; i++) {
813813
if (!strcmp(args[0].from, hash_algo_name[i])) {
814814
opt->hash = i;
815-
opt->digest_len =
816-
hash_digest_size[opt->hash];
817815
break;
818816
}
819817
}
@@ -825,13 +823,14 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
825823
}
826824
break;
827825
case Opt_policydigest:
828-
if (!tpm2 ||
829-
strlen(args[0].from) != (2 * opt->digest_len))
826+
digest_len = hash_digest_size[opt->hash];
827+
if (!tpm2 || strlen(args[0].from) != (2 * digest_len))
830828
return -EINVAL;
831829
res = hex2bin(opt->policydigest, args[0].from,
832-
opt->digest_len);
830+
digest_len);
833831
if (res < 0)
834832
return -EINVAL;
833+
opt->policydigest_len = digest_len;
835834
break;
836835
case Opt_policyhandle:
837836
if (!tpm2)

0 commit comments

Comments
 (0)