public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Mario Limonciello <mario.limonciello@amd.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
	Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	stable@vger.kernel.org,
	Thorsten Leemhuis <regressions@leemhuis.info>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tpm: disable hwrng for fTPM on some AMD designs
Date: Tue, 28 Feb 2023 04:39:58 +0200	[thread overview]
Message-ID: <Y/1pfpA2o6GRUIDZ@kernel.org> (raw)
In-Reply-To: <7f5bd6a2-2eed-a27e-8655-181bb37a7c1c@amd.com>

On Mon, Feb 27, 2023 at 08:58:37AM -0600, Mario Limonciello wrote:
> On 2/27/23 08:55, Guenter Roeck wrote:
> > On Mon, Feb 20, 2023 at 12:07:28PM -0600, Mario Limonciello wrote:
> > > AMD has issued an advisory indicating that having fTPM enabled in
> > > BIOS can cause "stuttering" in the OS.  This issue has been fixed
> > > in newer versions of the fTPM firmware, but it's up to system
> > > designers to decide whether to distribute it.
> > > 
> > > This issue has existed for a while, but is more prevalent starting
> > > with kernel 6.1 because commit b006c439d58db ("hwrng: core - start
> > > hwrng kthread also for untrusted sources") started to use the fTPM
> > > for hwrng by default. However, all uses of /dev/hwrng result in
> > > unacceptable stuttering.
> > > 
> > > So, simply disable registration of the defective hwrng when detecting
> > > these faulty fTPM versions.  As this is caused by faulty firmware, it
> > > is plausible that such a problem could also be reproduced by other TPM
> > > interactions, but this hasn't been shown by any user's testing or reports.
> > > 
> > > It is hypothesized to be triggered more frequently by the use of the RNG
> > > because userspace software will fetch random numbers regularly.
> > > 
> > > Intentionally continue to register other TPM functionality so that users
> > > that rely upon PCR measurements or any storage of data will still have
> > > access to it.  If it's found later that another TPM functionality is
> > > exacerbating this problem a module parameter it can be turned off entirely
> > > and a module parameter can be introduced to allow users who rely upon
> > > fTPM functionality to turn it on even though this problem is present.
> > > 
> > > Link: https://www.amd.com/en/support/kb/faq/pa-410
> > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=216989
> > > Link: https://lore.kernel.org/all/20230209153120.261904-1-Jason@zx2c4.com/
> > > Fixes: b006c439d58d ("hwrng: core - start hwrng kthread also for untrusted sources")
> > > Cc: stable@vger.kernel.org
> > > Cc: Jarkko Sakkinen <jarkko@kernel.org>
> > > Cc: Thorsten Leemhuis <regressions@leemhuis.info>
> > > Cc: James Bottomley <James.Bottomley@hansenpartnership.com>
> > > Co-developed-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > > Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> > > ---
> > > v1->v2:
> > >   * Minor style from Jarkko's feedback
> > >   * Move comment above function
> > >   * Explain further in commit message
> > > ---
> > >   drivers/char/tpm/tpm-chip.c | 61 ++++++++++++++++++++++++++++++-
> > >   drivers/char/tpm/tpm.h      | 73 +++++++++++++++++++++++++++++++++++++
> > >   2 files changed, 133 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> > > index 741d8f3e8fb3..1b066d7a6e21 100644
> > > --- a/drivers/char/tpm/tpm-chip.c
> > > +++ b/drivers/char/tpm/tpm-chip.c
> > > @@ -512,6 +512,64 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
> > >   	return 0;
> > >   }
> > > +/*
> > > + * Some AMD fTPM versions may cause stutter
> > > + * https://www.amd.com/en/support/kb/faq/pa-410
> > > + *
> > > + * Fixes are available in two series of fTPM firmware:
> > > + * 6.x.y.z series: 6.0.18.6 +
> > > + * 3.x.y.z series: 3.57.y.5 +
> > > + */
> > > +static bool tpm_amd_is_rng_defective(struct tpm_chip *chip)
> > > +{
> > > +	u32 val1, val2;
> > > +	u64 version;
> > > +	int ret;
> > > +
> > > +	if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
> > > +		return false;
> > > +
> > > +	ret = tpm_request_locality(chip);
> > > +	if (ret)
> > > +		return false;
> > > +
> > > +	ret = tpm2_get_tpm_pt(chip, TPM2_PT_MANUFACTURER, &val1, NULL);
> > > +	if (ret)
> > > +		goto release;
> > > +	if (val1 != 0x414D4400U /* AMD */) {
> > > +		ret = -ENODEV;
> > > +		goto release;
> > > +	}
> > > +	ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_1, &val1, NULL);
> > > +	if (ret)
> > > +		goto release;
> > > +	ret = tpm2_get_tpm_pt(chip, TPM2_PT_FIRMWARE_VERSION_2, &val2, NULL);
> > > +	if (ret)
> > > +		goto release;
> > 
> > This goto is unnecessary.
> > 
> > > +
> > > +release:
> > > +	tpm_relinquish_locality(chip);
> > > +
> > > +	if (ret)
> > > +		return false;
> > > +
> > > +	version = ((u64)val1 << 32) | val2;
> > > +	if ((version >> 48) == 6) {
> > > +		if (version >= 0x0006000000180006ULL)
> > > +			return false;
> > > +	} else if ((version >> 48) == 3) {
> > > +		if (version >= 0x0003005700000005ULL)
> > > +			return false;
> > > +	} else
> > > +		return false;
> > 
> > checkpatch:
> > 
> > CHECK: braces {} should be used on all arms of this statement
> > #200: FILE: drivers/char/tpm/tpm-chip.c:557:
> > +	if ((version >> 48) == 6) {
> > [...]
> > +	} else if ((version >> 48) == 3) {
> > [...]
> > +	} else
> > [...]
> 
> It was requested by Jarko explicitly in v1 to do it this way.
> 
> https://lore.kernel.org/lkml/Y+%2F6G+UlTI7GpW6o@kernel.org/

OK, you're right, it is my bad, I'm sorry about that. Send v3 with that feedback reverted.

BR, Jarkko

      parent reply	other threads:[~2023-02-28  2:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-20 18:07 [PATCH v2] tpm: disable hwrng for fTPM on some AMD designs Mario Limonciello
2023-02-27 14:52 ` Mario Limonciello
2023-02-28  2:37   ` Limonciello, Mario
2023-02-28  2:41     ` Jarkko Sakkinen
2023-02-27 14:55 ` Guenter Roeck
2023-02-27 14:58   ` Mario Limonciello
2023-02-27 15:06     ` Guenter Roeck
2023-02-28  2:39     ` Jarkko Sakkinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y/1pfpA2o6GRUIDZ@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=Jason@zx2c4.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=linux@roeck-us.net \
    --cc=mario.limonciello@amd.com \
    --cc=peterhuewe@gmx.de \
    --cc=regressions@leemhuis.info \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox