Skip to content

Commit 7d76111

Browse files
author
Jarkko Sakkinen
committed
tpm: fix RC value check in tpm2_seal_trusted
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>
1 parent 419a16d commit 7d76111

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

drivers/char/tpm/tpm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ static inline void tpm_add_ppi(struct tpm_chip *chip)
519519
}
520520
#endif
521521

522+
static inline inline u32 tpm2_rc_value(u32 rc)
523+
{
524+
return (rc & BIT(7)) ? rc & 0xff : rc;
525+
}
526+
522527
int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
523528
int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash);
524529
int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max);

drivers/char/tpm/tpm2-cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
546546
tpm_buf_destroy(&buf);
547547

548548
if (rc > 0) {
549-
if ((rc & TPM2_RC_HASH) == TPM2_RC_HASH)
549+
if (tpm2_rc_value(rc) == TPM2_RC_HASH)
550550
rc = -EINVAL;
551551
else
552552
rc = -EPERM;

0 commit comments

Comments
 (0)