Skip to content

Commit 9764a44

Browse files
committed
fix(tpm2_loadexternal): check return value of RAND_bytes
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>
1 parent d15fc36 commit 9764a44

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

tools/tpm2_loadexternal.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ static tool_rc process_inputs(ESYS_CONTEXT *ectx) {
284284
TPM2B_DIGEST *seed = &ctx.priv.sensitiveArea.seedValue;
285285
seed->size = tpm2_alg_util_get_hash_size(ctx.pub.publicArea.nameAlg);
286286
if (seed->size != 0) {
287-
RAND_bytes(seed->buffer, seed->size);
287+
tmp_rc = RAND_bytes(seed->buffer, seed->size);
288+
if (tmp_rc != 1) {
289+
LOG_ERR("Failed to generate random seed value");
290+
return tool_rc_general_error;
291+
}
288292
}
289293

290294
tpm2_openssl_load_rc load_status = tpm2_openssl_load_private(

0 commit comments

Comments
 (0)