diff options
| author | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2017-01-25 16:00:22 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-05-14 08:00:13 -0400 |
| commit | 326f9b0a39d3a27221dafc46e9862c7a1aa8fb19 (patch) | |
| tree | 9a68eb639991a2f7262d97aa6bbfe5bcac734b3e /drivers/char | |
| parent | a941f261c8f16faa22d3fcd16842f6d8c2723eac (diff) | |
tpm: fix RC value check in tpm2_seal_trusted
commit 7d761119a914ec0ac05ec2a5378d1f86e680967d upstream.
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: 5ca4c20cfd37 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/char')
| -rw-r--r-- | drivers/char/tpm/tpm.h | 5 | ||||
| -rw-r--r-- | drivers/char/tpm/tpm2-cmd.c | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 4d183c97f6a6..aa4299cf7e5a 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h | |||
| @@ -518,6 +518,11 @@ static inline void tpm_add_ppi(struct tpm_chip *chip) | |||
| 518 | } | 518 | } |
| 519 | #endif | 519 | #endif |
| 520 | 520 | ||
| 521 | static inline inline u32 tpm2_rc_value(u32 rc) | ||
| 522 | { | ||
| 523 | return (rc & BIT(7)) ? rc & 0xff : rc; | ||
| 524 | } | ||
| 525 | |||
| 521 | int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); | 526 | int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); |
| 522 | int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash); | 527 | int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash); |
| 523 | int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max); | 528 | int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max); |
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 7df55d58c939..17896d654033 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c | |||
| @@ -529,7 +529,7 @@ out: | |||
| 529 | tpm_buf_destroy(&buf); | 529 | tpm_buf_destroy(&buf); |
| 530 | 530 | ||
| 531 | if (rc > 0) { | 531 | if (rc > 0) { |
| 532 | if ((rc & TPM2_RC_HASH) == TPM2_RC_HASH) | 532 | if (tpm2_rc_value(rc) == TPM2_RC_HASH) |
| 533 | rc = -EINVAL; | 533 | rc = -EINVAL; |
| 534 | else | 534 | else |
| 535 | rc = -EPERM; | 535 | rc = -EPERM; |
