Re: [PATCH] tpm_tis: work around status register bug in STMicroelectronics TPM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2020-04-16 at 20:09 +0300, Jarkko Sakkinen wrote:
> On Wed, Apr 15, 2020 at 04:51:39PM -0700, James Bottomley wrote:
> > On Wed, 2020-04-15 at 15:45 -0700, Omar Sandoval wrote:
> > > From: Omar Sandoval <osandov@xxxxxx>
> > > 
> > > We've encountered a particular model of STMicroelectronics TPM
> > > that
> > > transiently returns a bad value in the status register. This
> > > causes
> > > the kernel to believe that the TPM is ready to receive a command
> > > when
> > > it actually isn't, which in turn causes the send to time out in
> > > get_burstcount(). In testing, reading the status register one
> > > extra
> > > time convinces the TPM to return a valid value.
> > 
> > Interesting, I've got a very early upgradeable nuvoton that seems
> > to be
> > behaving like this.
> > 
> > > Signed-off-by: Omar Sandoval <osandov@xxxxxx>
> > > ---
> > >  drivers/char/tpm/tpm_tis_core.c | 12 ++++++++++++
> > >  1 file changed, 12 insertions(+)
> > > 
> > > diff --git a/drivers/char/tpm/tpm_tis_core.c
> > > b/drivers/char/tpm/tpm_tis_core.c
> > > index 27c6ca031e23..277a21027fc7 100644
> > > --- a/drivers/char/tpm/tpm_tis_core.c
> > > +++ b/drivers/char/tpm/tpm_tis_core.c
> > > @@ -238,6 +238,18 @@ static u8 tpm_tis_status(struct tpm_chip
> > > *chip)
> > >  	rc = tpm_tis_read8(priv, TPM_STS(priv->locality),
> > > &status);
> > >  	if (rc < 0)
> > >  		return 0;
> > > +	/*
> > > +	 * Some STMicroelectronics TPMs have a bug where the
> > > status
> > > register is
> > > +	 * sometimes bogus (all 1s) if read immediately after
> > > the
> > > access
> > > +	 * register is written to. Bits 0, 1, and 5 are always
> > > supposed to read
> > > +	 * as 0, so this is clearly invalid. Reading the
> > > register a
> > > second time
> > > +	 * returns a valid value.
> > > +	 */
> > > +	if (unlikely(status == 0xff)) {
> > > +		rc = tpm_tis_read8(priv, TPM_STS(priv-
> > > >locality),
> > > &status);
> > > +		if (rc < 0)
> > > +			return 0;
> > > +	}
> > 
> > You theorize that your case is fixed by the second read, but what
> > if it
> > isn't and the second read also returns 0xff?  Shouldn't we have a
> > line
> > here saying
> > 
> > if (unlikely(status == 0xff))
> > 	status = 0;
> > 
> > So if we get a second 0xff we just pretend the thing isn't ready?
> 
> If it eventually settles, would it be better to poll it for a while?

Omar said they'd never seen the double read fail, so I don't think
polling would be helpful in this case.  If we do get a double read of
0xff I think returning 0 is correct which basically means the TPM isn't
ready and the caller needs to wait a bit.  If you look, most of the
callers of tpm_tis_status will do their own wait and retry in this
case, so effectively we're getting the caller to poll for us.

James


> Also, the commit message is ambiguous. "bad value" can be any random
> bit sequence.
> 
> /Jarkko
> 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux