Skip to content

Commit

Permalink
tpm: fix RC value check in tpm2_seal_trusted
Browse files Browse the repository at this point in the history
The error code handling is broken as any error code that has the same
bits set as TPM_RC_HASH passes. Implemented tpm2_rc_value() helper to
parse the error value from FMT0 and FMT1 error codes so that these types
of mistakes are prevented in the future.

Fixes: 5ca4c20 ("keys, trusted: select hash algorithm for TPM2 chips")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
  • Loading branch information
Jarkko Sakkinen committed Feb 3, 2017
1 parent 419a16d commit 7d76111
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions drivers/char/tpm/tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
}
#endif

static inline inline u32 tpm2_rc_value(u32 rc)
{
return (rc & BIT(7)) ? rc & 0xff : rc;
}

int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash);
int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max);
Expand Down
2 changes: 1 addition & 1 deletion drivers/char/tpm/tpm2-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
tpm_buf_destroy(&buf);

if (rc > 0) {
if ((rc & TPM2_RC_HASH) == TPM2_RC_HASH)
if (tpm2_rc_value(rc) == TPM2_RC_HASH)
rc = -EINVAL;
else
rc = -EPERM;
Expand Down

0 comments on commit 7d76111

Please sign in to comment.