Skip to content

Commit 55707d5

Browse files
James BottomleyJarkko Sakkinen
authored andcommitted
tpm_tis: Add a check for invalid status
Some TIS based TPMs can return 0xff to status reads if the locality hasn't been properly requested. Detect this condition by checking the bits that the TIS spec specifies must return zero are clear and return zero in that case. Also drop a warning so the problem can be identified in the calling path and fixed (usually a missing try_get_ops()). Signed-off-by: James Bottomley <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent e08c6d3 commit 55707d5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

drivers/char/tpm/tpm_tis_core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
239239
if (rc < 0)
240240
return 0;
241241

242+
if (unlikely((status & TPM_STS_READ_ZERO) != 0)) {
243+
/*
244+
* If this trips, the chances are the read is
245+
* returning 0xff because the locality hasn't been
246+
* acquired. Usually because tpm_try_get_ops() hasn't
247+
* been called before doing a TPM operation.
248+
*/
249+
WARN_ONCE(1, "TPM returned invalid status\n");
250+
return 0;
251+
}
252+
242253
return status;
243254
}
244255

drivers/char/tpm/tpm_tis_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum tis_status {
3434
TPM_STS_GO = 0x20,
3535
TPM_STS_DATA_AVAIL = 0x10,
3636
TPM_STS_DATA_EXPECT = 0x08,
37+
TPM_STS_READ_ZERO = 0x23, /* bits that must be zero on read */
3738
};
3839

3940
enum tis_int_flags {

0 commit comments

Comments
 (0)