tpm_tis: Add a check for invalid status
Subsystems (2)
James Bottomley
maintainerPATCH 1/1 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()).
---
This is the patch I've been using to catch and kill all the points in the stack where we're not properly using get/put ops on the tpm chip.
drivers/char/tpm/tpm_tis_core.c | 11 +++++++++++ drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 12 insertions(+)
drivers/char/tpm/tpm_tis_core.c +11 -0
@@ -239,6 +239,17 @@ static u8 tpm_tis_status(struct tpm_chip *chip)if (rc <0 )return 0 ; +if (unlikely ((status &TPM_STS_READ_ZERO ) !=0 )) { +/* +* If this trips, the chances are the read is +* returning 0xff because the locality hasn't been +* acquired. Usually because tpm_try_get_ops() hasn't +* been called before doing a TPM operation. +*/ +WARN_ONCE (1 ,"TPM returned invalid status\n" ); +return 0 ; + } +return status; }
drivers/char/tpm/tpm_tis_core.h +1 -0
@@ -34,6 +34,7 @@ enum tis_status {TPM_STS_GO =0x20 ,TPM_STS_DATA_AVAIL =0x10 ,TPM_STS_DATA_EXPECT =0x08 , + TPM_STS_READ_ZERO = 0x23, /* bits that must be zero on read */ }; enum tis_int_flags {
Signature · 1 line
2.26.2
Jason Gunthorpe
reviewerQuoted 11 lines · James Bottomley
Some TIS based TPMs can return
0xffto 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 missingtry_get_ops()).Signed-off-by James Bottomley <[email protected]>This is the patch I've been using to catch and kill all the points in the stack where we're not properly using get/put ops on the tpm chip.
If this is a problem add a lockdep on ops_sem in various places too?
Jason
James Bottomley
maintainerQuoted 8 lines · Jason Gunthorpe
Quoted 7 lines · James Bottomley
Some TIS based TPMs can return
0xffto 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 missingtry_get_ops()).
Quoted 8 lines
Quoted 6 lines
Signed-off-by: James Bottomley <
[email protected]>This is the patch I've been using to catch and kill all the points in the stack where we're not properly using get/put ops on the tpm chip.
If this is a problem add a lockdep on
ops_semin various places too?
It's not really possible because of the init issue with checking the interrupt. That originally had no locking at all (it doesn't need any because the TPM device isn't publicly exposed at the point the check is done). If the patch to add get/put around the tpm2_get_tpm_pt is acceptable, then perhaps we could because I think that's the last unguarded use of tpm_tis_status.
James
Jarkko Sakkinen
Reviewed-byQuoted 18 lines · James Bottomley
Quoted 8 lines · Jason Gunthorpe
Quoted 7 lines · James Bottomley
Some TIS based TPMs can return
0xffto 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 missingtry_get_ops()).Quoted 8 lines
Quoted 6 lines
Signed-off-by: James Bottomley <
[email protected]>This is the patch I've been using to catch and kill all the points in the stack where we're not properly using get/put ops on the tpm chip.
If this is a problem add a lockdep on
ops_semin various places too?
Quoted 8 lines
It's not really possible because of the init issue with checking the interrupt. That originally had no locking at all (it doesn't need any because the TPM device isn't publicly exposed at the point the check is done). If the patch to add get/put around the
tpm2_get_tpm_ptis acceptable, then perhaps we could because I think that's the last unguarded use oftpm_tis_status.James
I think this sanity check would not hurt at all.
We should also improve the testing coverage. E.g. there is zero coverage for trusted keys. It can easily lead weird conclusions if there is no common test to run.
I touched that over here:
https://lore.kernel.org/linux-integrity/[email protected]/
Anyway, I will apply this for sure.
/Jarkko
Quoted 34 lines · Jarkko Sakkinen
Quoted 18 lines · James Bottomley
Quoted 8 lines · Jason Gunthorpe
Quoted 7 lines · James Bottomley
Some TIS based TPMs can return
0xffto 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 missingtry_get_ops()).Quoted 8 lines
Quoted 6 lines
Signed-off-by: James Bottomley <
[email protected]>This is the patch I've been using to catch and kill all the points in the stack where we're not properly using get/put ops on the tpm chip.
If this is a problem add a lockdep on
ops_semin various places too?Quoted 8 lines
It's not really possible because of the init issue with checking the interrupt. That originally had no locking at all (it doesn't need any because the TPM device isn't publicly exposed at the point the check is done). If the patch to add get/put around the
tpm2_get_tpm_ptis acceptable, then perhaps we could because I think that's the last unguarded use oftpm_tis_status.James
I think this sanity check would not hurt at all.
We should also improve the testing coverage. E.g. there is zero coverage for trusted keys. It can easily lead weird conclusions if there is no common test to run.
Quoted 7 lines
I touched that over here:
https://lore.kernel.org/linux-integrity/[email protected]/
Anyway, I will apply this for sure.
Reviewed-by Jarkko Sakkinen <[email protected]>
Has been applied.
/Jarkko