1 From 7d761119a914ec0ac05ec2a5378d1f86e680967d Mon Sep 17 00:00:00 2001
2 From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
3 Date: Wed, 25 Jan 2017 23:00:22 +0200
4 Subject: tpm: fix RC value check in tpm2_seal_trusted
6 From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
8 commit 7d761119a914ec0ac05ec2a5378d1f86e680967d upstream.
10 The error code handling is broken as any error code that has the same
11 bits set as TPM_RC_HASH passes. Implemented tpm2_rc_value() helper to
12 parse the error value from FMT0 and FMT1 error codes so that these types
13 of mistakes are prevented in the future.
15 Fixes: 5ca4c20cfd37 ("keys, trusted: select hash algorithm for TPM2 chips")
16 Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
17 Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 drivers/char/tpm/tpm.h | 5 +++++
22 drivers/char/tpm/tpm2-cmd.c | 2 +-
23 2 files changed, 6 insertions(+), 1 deletion(-)
25 --- a/drivers/char/tpm/tpm.h
26 +++ b/drivers/char/tpm/tpm.h
27 @@ -518,6 +518,11 @@ static inline void tpm_add_ppi(struct tp
31 +static inline inline u32 tpm2_rc_value(u32 rc)
33 + return (rc & BIT(7)) ? rc & 0xff : rc;
36 int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
37 int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash);
38 int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max);
39 --- a/drivers/char/tpm/tpm2-cmd.c
40 +++ b/drivers/char/tpm/tpm2-cmd.c
41 @@ -529,7 +529,7 @@ out:
42 tpm_buf_destroy(&buf);
45 - if ((rc & TPM2_RC_HASH) == TPM2_RC_HASH)
46 + if (tpm2_rc_value(rc) == TPM2_RC_HASH)