From: Jarkko Sakkinen <jarkko@kernel.org>
To: linux-integrity@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko@kernel.org>,
Jonathan McDowell <noodles@meta.com>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Mimi Zohar <zohar@linux.ibm.com>,
David Howells <dhowells@redhat.com>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
keyrings@vger.kernel.org (open list:KEYS-TRUSTED),
linux-security-module@vger.kernel.org (open list:SECURITY
SUBSYSTEM), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v9 02/11] KEYS: trusted: Use get_random_bytes_wait() instead of tpm_get_random()
Date: Sun, 25 Jan 2026 21:25:12 +0200 [thread overview]
Message-ID: <20260125192526.782202-3-jarkko@kernel.org> (raw)
In-Reply-To: <20260125192526.782202-1-jarkko@kernel.org>
Substitute the remaining tpm_get_random() calls in trusted_tpm1.c with
get_random_bytes_wait() thus aligning random number generation for TPM 1.2
with the removal of '.get_random' callback.
Reviewed-by: Jonathan McDowell <noodles@meta.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
security/keys/trusted-keys/trusted_tpm1.c | 18 +++---------------
1 file changed, 3 insertions(+), 15 deletions(-)
diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c
index 7ce7e31bcdfb..3d75bb6f9689 100644
--- a/security/keys/trusted-keys/trusted_tpm1.c
+++ b/security/keys/trusted-keys/trusted_tpm1.c
@@ -371,13 +371,10 @@ static int osap(struct tpm_buf *tb, struct osapsess *s,
unsigned char ononce[TPM_NONCE_SIZE];
int ret;
- ret = tpm_get_random(chip, ononce, TPM_NONCE_SIZE);
+ ret = get_random_bytes_wait(ononce, TPM_NONCE_SIZE);
if (ret < 0)
return ret;
- if (ret != TPM_NONCE_SIZE)
- return -EIO;
-
tpm_buf_reset(tb, TPM_TAG_RQU_COMMAND, TPM_ORD_OSAP);
tpm_buf_append_u16(tb, type);
tpm_buf_append_u32(tb, handle);
@@ -464,15 +461,10 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
memcpy(td->xorwork + SHA1_DIGEST_SIZE, sess.enonce, SHA1_DIGEST_SIZE);
sha1(td->xorwork, SHA1_DIGEST_SIZE * 2, td->xorhash);
- ret = tpm_get_random(chip, td->nonceodd, TPM_NONCE_SIZE);
+ ret = get_random_bytes_wait(td->nonceodd, TPM_NONCE_SIZE);
if (ret < 0)
goto out;
- if (ret != TPM_NONCE_SIZE) {
- ret = -EIO;
- goto out;
- }
-
ordinal = htonl(TPM_ORD_SEAL);
datsize = htonl(datalen);
pcrsize = htonl(pcrinfosize);
@@ -575,14 +567,10 @@ static int tpm_unseal(struct tpm_buf *tb,
}
ordinal = htonl(TPM_ORD_UNSEAL);
- ret = tpm_get_random(chip, nonceodd, TPM_NONCE_SIZE);
+ ret = get_random_bytes_wait(nonceodd, TPM_NONCE_SIZE);
if (ret < 0)
return ret;
- if (ret != TPM_NONCE_SIZE) {
- pr_info("tpm_get_random failed (%d)\n", ret);
- return -EIO;
- }
ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE,
enonce1, nonceodd, cont, sizeof(uint32_t),
&ordinal, bloblen, blob, 0, 0);
--
2.52.0
next prev parent reply other threads:[~2026-01-25 19:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-25 19:25 [PATCH v9 00/11] Streamline TPM2 HMAC sessions Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 01/11] KEYS: trusted: Use get_random-fallback for TPM Jarkko Sakkinen
2026-01-29 16:18 ` Roberto Sassu
2026-02-01 22:25 ` Jarkko Sakkinen
2026-02-20 18:04 ` Mimi Zohar
2026-02-20 18:30 ` Chris Fenner
2026-03-03 21:32 ` Jarkko Sakkinen
2026-03-05 15:37 ` Mimi Zohar
2026-03-18 17:36 ` Chris Fenner
2026-03-19 14:28 ` Mimi Zohar
2026-03-23 5:26 ` Jarkko Sakkinen
2026-03-23 5:34 ` Jarkko Sakkinen
2026-03-23 5:46 ` Jarkko Sakkinen
2026-03-23 5:24 ` Jarkko Sakkinen
2026-03-03 21:30 ` Jarkko Sakkinen
2026-01-25 19:25 ` Jarkko Sakkinen [this message]
2026-01-25 19:25 ` [PATCH v9 03/11] tpm: Change tpm_get_random() opportunistic Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 04/11] tpm2-sessions: Define TPM2_NAME_MAX_SIZE Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 05/11] KEYS: trusted: Open code tpm2_buf_append() Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 06/11] KEYS: trusted: Remove dead branch from tpm2_unseal_cmd Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 07/11] KEYS: trusted: Re-orchestrate tpm2_read_public() calls Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 08/11] tpm2-sessions: Remove the support for more than one authorization Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 09/11] tpm-buf: Remove tpm_buf_append_handle Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 10/11] tpm-buf: Merge TPM_BUF_BOUNDARY_ERROR and TPM_BUF_OVERFLOW Jarkko Sakkinen
2026-01-25 19:25 ` [PATCH v9 11/11] tpm-buf: Implement managed allocations Jarkko Sakkinen
2026-02-08 14:09 ` 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=20260125192526.782202-3-jarkko@kernel.org \
--to=jarkko@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=dhowells@redhat.com \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=noodles@meta.com \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=zohar@linux.ibm.com \
/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