]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.28/tpm-fix-rc-value-check-in-tpm2_seal_trusted.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.28 / tpm-fix-rc-value-check-in-tpm2_seal_trusted.patch
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
5
6 From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
7
8 commit 7d761119a914ec0ac05ec2a5378d1f86e680967d upstream.
9
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.
14
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>
19
20 ---
21 drivers/char/tpm/tpm.h | 5 +++++
22 drivers/char/tpm/tpm2-cmd.c | 2 +-
23 2 files changed, 6 insertions(+), 1 deletion(-)
24
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
28 }
29 #endif
30
31 +static inline inline u32 tpm2_rc_value(u32 rc)
32 +{
33 + return (rc & BIT(7)) ? rc & 0xff : rc;
34 +}
35 +
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);
43
44 if (rc > 0) {
45 - if ((rc & TPM2_RC_HASH) == TPM2_RC_HASH)
46 + if (tpm2_rc_value(rc) == TPM2_RC_HASH)
47 rc = -EINVAL;
48 else
49 rc = -EPERM;