Skip to content

Commit 0178f9d

Browse files
committed
tpm: Replace WARN_ONCE() with dev_err_once() in tpm_tis_status()
Do not tear down the system when getting invalid status from a TPM chip. This can happen when panic-on-warn is used. Instead, introduce TPM_TIS_INVALID_STATUS bitflag and use it to trigger once the error reporting per chip. In addition, print out the value of TPM_STS for improved forensics. Link: https://lore.kernel.org/keyrings/[email protected]/ Fixes: 55707d5 ("tpm_tis: Add a check for invalid status") Cc: [email protected] Signed-off-by: Jarkko Sakkinen <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]>
1 parent 5a118a3 commit 0178f9d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

drivers/char/tpm/tpm_tis_core.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,24 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
196196
return 0;
197197

198198
if (unlikely((status & TPM_STS_READ_ZERO) != 0)) {
199-
/*
200-
* If this trips, the chances are the read is
201-
* returning 0xff because the locality hasn't been
202-
* acquired. Usually because tpm_try_get_ops() hasn't
203-
* been called before doing a TPM operation.
204-
*/
205-
WARN_ONCE(1, "TPM returned invalid status\n");
199+
if (!test_and_set_bit(TPM_TIS_INVALID_STATUS, &priv->flags)) {
200+
/*
201+
* If this trips, the chances are the read is
202+
* returning 0xff because the locality hasn't been
203+
* acquired. Usually because tpm_try_get_ops() hasn't
204+
* been called before doing a TPM operation.
205+
*/
206+
dev_err(&chip->dev, "invalid TPM_STS.x 0x%02x, dumping stack for forensics\n",
207+
status);
208+
209+
/*
210+
* Dump stack for forensics, as invalid TPM_STS.x could be
211+
* potentially triggered by impaired tpm_try_get_ops() or
212+
* tpm_find_get_ops().
213+
*/
214+
dump_stack();
215+
}
216+
206217
return 0;
207218
}
208219

drivers/char/tpm/tpm_tis_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ enum tis_defaults {
8383

8484
enum tpm_tis_flags {
8585
TPM_TIS_ITPM_WORKAROUND = BIT(0),
86+
TPM_TIS_INVALID_STATUS = BIT(1),
8687
};
8788

8889
struct tpm_tis_data {
8990
u16 manufacturer_id;
9091
int locality;
9192
int irq;
9293
bool irq_tested;
93-
unsigned int flags;
94+
unsigned long flags;
9495
void __iomem *ilb_base_addr;
9596
u16 clkrun_enabled;
9697
wait_queue_head_t int_queue;

0 commit comments

Comments
 (0)