Skip to content

tpm2_loadexternal: check return value of RAND_bytes#3569

Merged
AndreasFuchsTPM merged 1 commit into
tpm2-software:masterfrom
hyperfinitism:fix/rand-bytes-rc-check
Mar 25, 2026
Merged

tpm2_loadexternal: check return value of RAND_bytes#3569
AndreasFuchsTPM merged 1 commit into
tpm2-software:masterfrom
hyperfinitism:fix/rand-bytes-rc-check

Conversation

@hyperfinitism
Copy link
Copy Markdown
Contributor

RAND_bytes() can fail with return code 0 or -1. If it fails, seed->buffer is not ensured to have sufficient entropy. This PR adds the return value check.

Comment thread tools/tpm2_loadexternal.c Fixed
@hyperfinitism hyperfinitism force-pushed the fix/rand-bytes-rc-check branch from 5ee0c76 to 9764a44 Compare March 21, 2026 15:32
RAND_bytes() can fail with return code 0 or -1 when the OpenSSL CSPRNG has
not been sufficiently seeded.

If RAND_bytes() fails, seed->buffer is left uninitialised. This seed value
is stored in ctx.priv.sensitiveArea.seedValue and used in the consistency
checks by TPM.

Check the return value and return tool_rc_general_error on failure so that
the operation is aborted rather than proceeding with a bad seed.

Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
@hyperfinitism hyperfinitism force-pushed the fix/rand-bytes-rc-check branch from 9764a44 to be2acae Compare March 21, 2026 15:38
@AndreasFuchsTPM AndreasFuchsTPM merged commit a053bdb into tpm2-software:master Mar 25, 2026
23 checks passed
@hyperfinitism hyperfinitism deleted the fix/rand-bytes-rc-check branch April 14, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants