Skip to content

Commit

Permalink
hcrypto PKCS#11 backend: don't leak sessions on digest reinit
Browse files Browse the repository at this point in the history
Clients of the EVP API can reinitialize message digest contexts
without destroying them. The PKCS#11 backend assumed they were
only used once, and was leaking session handles upon reinitialization.
This fix disposes of any existing PKCS#11 message digest context
in the initialization method.

(cherry picked from commit 9518f29)
  • Loading branch information
lhoward authored and jaltman committed May 15, 2019
1 parent 7c785cc commit c381868
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/hcrypto/evp-pkcs11.c
Expand Up @@ -364,12 +364,18 @@ p11_cleanup(EVP_CIPHER_CTX *ctx)
return 1;
}

static int
p11_md_cleanup(EVP_MD_CTX *ctx);

static int
p11_md_hash_init(CK_MECHANISM_TYPE mechanismType, EVP_MD_CTX *ctx)
{
struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
CK_RV rv;

if (p11ctx->hSession != CK_INVALID_HANDLE)
p11_md_cleanup(ctx);

rv = p11_session_init(mechanismType, &p11ctx->hSession);
if (rv == CKR_OK) {
CK_MECHANISM mechanism = { mechanismType, NULL, 0 };
Expand Down

0 comments on commit c381868

Please sign in to comment.