Skip to content

Commit

Permalink
Erase temporary buffer in EVP_PKEY_get_bn_param()
Browse files Browse the repository at this point in the history
Function EVP_PKEY_get_bn_param() uses temporary buffer (on stack or
heap allocated) to store serialized bignum, but after deserializing it
into BIGNUM*, the buffer is not erased and may contain sensitive data.

This change makes sure the buffer is erased if it was successfully
filled before. Unfortunately, it does not distinguish between public and
private key components, and will always erase the buffer.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #20639)

(cherry picked from commit 34e4a96)
  • Loading branch information
iamnotacake authored and t8m committed Apr 4, 2023
1 parent a974542 commit 5fc9872
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crypto/evp/p_lib.c
Expand Up @@ -2178,7 +2178,14 @@ int EVP_PKEY_get_bn_param(const EVP_PKEY *pkey, const char *key_name,
goto err;
ret = OSSL_PARAM_get_BN(params, bn);
err:
OPENSSL_free(buf);
if (buf != NULL) {
if (OSSL_PARAM_modified(params))
OPENSSL_clear_free(buf, buf_sz);
else
OPENSSL_free(buf);
} else if (OSSL_PARAM_modified(params)) {
OPENSSL_cleanse(buffer, params[0].data_size);
}
return ret;
}

Expand Down

0 comments on commit 5fc9872

Please sign in to comment.