mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: <jarkko@kernel.org>, <peterhuewe@gmx.de>
Cc: <linux-kernel@vger.kernel.org>, <linux-integrity@vger.kernel.org>,
	<Jason@zx2c4.com>, <dragonn@op.pl>,
	Mario Limonciello <mario.limonciello@amd.com>
Subject: [PATCH 2/3] tpm: Add command line for not trusting tpm for RNG
Date: Wed, 2 Aug 2023 20:50:14 -0500	[thread overview]
Message-ID: <20230803015015.915-3-mario.limonciello@amd.com> (raw)
In-Reply-To: <20230803015015.915-1-mario.limonciello@amd.com>

The kernel supports random.cpu=off and random.bootloader=off.
As TPM RNG is also registered as a hwrng, add the ability to
prevent registering the TPM RNG.

Suggested-by: Mateusz Schyboll <dragonn@op.pl>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 Documentation/admin-guide/kernel-parameters.txt |  5 +++++
 drivers/char/tpm/tpm-chip.c                     | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a1457995fd41c..9ff602c09f55c 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4672,6 +4672,11 @@
 			passed by the bootloader (if available) to
 			initialize the kernel's RNG.
 
+	random.trust_tpm=off
+			[KNL] Disable trusting the use of the TPM's
+			random number generator (if available) to
+			initialize the kernel's RNG.
+
 	randomize_kstack_offset=
 			[KNL] Enable or disable kernel stack offset
 			randomization, which provides roughly 5 bits of
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 8f61b784810d6..8fb42232bd7a5 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -32,6 +32,13 @@ struct class *tpm_class;
 struct class *tpmrm_class;
 dev_t tpm_devt;
 
+static bool trust_tpm __initdata = true;
+static int __init parse_trust_tpm(char *arg)
+{
+	return kstrtobool(arg, &trust_tpm);
+}
+early_param("random.trust_tpm", parse_trust_tpm);
+
 static int tpm_request_locality(struct tpm_chip *chip)
 {
 	int rc;
@@ -523,6 +530,9 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
 
 static int tpm_add_hwrng(struct tpm_chip *chip)
 {
+	if (!trust_tpm)
+		chip->flags |= TPM_CHIP_FLAG_HWRNG_DISABLED;
+
 	if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM) || tpm_is_firmware_upgrade(chip) ||
 	    chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED)
 		return 0;
-- 
2.34.1


  parent reply	other threads:[~2023-08-03  1:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03  1:50 [PATCH 0/3] More changes related to TPM RNG handling Mario Limonciello
2023-08-03  1:50 ` [PATCH 1/3] tpm: Add a missing check for TPM_CHIP_FLAG_HWRNG_DISABLED Mario Limonciello
2023-08-03  8:59   ` Jarkko Sakkinen
2023-08-03 11:35     ` Mario Limonciello
2023-08-03 13:50       ` Jason A. Donenfeld
2023-08-04 22:52         ` Jarkko Sakkinen
2023-08-03  1:50 ` Mario Limonciello [this message]
2023-08-03 13:42   ` [PATCH 2/3] tpm: Add command line for not trusting tpm for RNG Jason A. Donenfeld
2023-08-03  1:50 ` [PATCH 3/3] tpm: Drop CONFIG_HW_RANDOM_TPM Mario Limonciello
2023-08-03  7:22   ` Paul Menzel
2023-08-03  9:03     ` Jarkko Sakkinen
2023-08-03 11:45     ` Mario Limonciello
2023-08-03  9:01   ` Jarkko Sakkinen

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=20230803015015.915-3-mario.limonciello@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Jason@zx2c4.com \
    --cc=dragonn@op.pl \
    --cc=jarkko@kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /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

all inboxes | Powered by JetHome®