Return-Path: Received: from bastet.se.axis.com (bastet.se.axis.com [195.60.68.11]) by mail.server123.net (Postfix) with ESMTP for ; Tue, 11 Oct 2016 11:07:51 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id 34B60180DE for ; Tue, 11 Oct 2016 10:59:01 +0200 (CEST) Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id xECoVhdfQ6rT for ; Tue, 11 Oct 2016 10:59:00 +0200 (CEST) Received: from boulder02.se.axis.com (boulder02.se.axis.com [10.0.8.16]) by bastet.se.axis.com (Postfix) with ESMTPS id 713F51807D for ; Tue, 11 Oct 2016 10:59:00 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57F261A08D for ; Tue, 11 Oct 2016 10:59:00 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D1921A08C for ; Tue, 11 Oct 2016 10:59:00 +0200 (CEST) Received: from thoth.se.axis.com (unknown [10.0.2.173]) by boulder02.se.axis.com (Postfix) with ESMTP for ; Tue, 11 Oct 2016 10:59:00 +0200 (CEST) Received: from XBOX01.axis.com (xbox01.axis.com [10.0.5.15]) by thoth.se.axis.com (Postfix) with ESMTP id 41CBF2B8 for ; Tue, 11 Oct 2016 10:59:00 +0200 (CEST) From: Per Johansson Message-ID: <013264df-4995-c513-0826-51478746dd67@axis.com> Date: Tue, 11 Oct 2016 10:58:59 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------DA062BBEC241B7A0A0A16405" Subject: [dm-crypt] Memory leak when using openssl backend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: dm-crypt@saout.de --------------DA062BBEC241B7A0A0A16405 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Hi I have found a memory leak when using openssl backend. I don't know if this is the proper way to report it. The problem is that crypt_hash_init() and crypt_hash_restart() calls EVP_DigestInit() but crypt_hash_final() calls EVP_DigestFinal_ex(). This results in that the context struct is zeroed when crypt_hash_restart() calls EVP_DigestInit(), and the memory allocated by the previous call to EVP_DigestInit() is lost. The version of openssl we use is 1.0.2g. This leak might not occur in later versions of openssl that has changed how those functions work. I have attached a suggested fix that only uses the _ex versions of the EVP functions. /Per --------------DA062BBEC241B7A0A0A16405 Content-Type: text/x-patch; name="0001-Fix-memory-leak-when-using-openssl-backend.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-memory-leak-when-using-openssl-backend.patch" From c706d110be72bb78ff270d23ea9e3c7892bd98ba Mon Sep 17 00:00:00 2001 From: Per x Johansson Date: Tue, 11 Oct 2016 10:34:11 +0200 Subject: [PATCH] Fix memory leak when using openssl backend Fixes a memory leak when using openssl backend caused by mismatched calls to EVP_DigestInit and EVP_DigestFinal_ex. --- lib/crypto_backend/crypto_openssl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/crypto_backend/crypto_openssl.c b/lib/crypto_backend/crypto_openssl.c index 5e4345b..9f9069d 100644 --- a/lib/crypto_backend/crypto_openssl.c +++ b/lib/crypto_backend/crypto_openssl.c @@ -95,7 +95,8 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name) return -EINVAL; } - if (EVP_DigestInit(&h->md, h->hash_id) != 1) { + EVP_MD_CTX_init(&h->md); + if (EVP_DigestInit_ex(&h->md, h->hash_id, NULL) != 1) { free(h); return -EINVAL; } @@ -107,7 +108,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name) static int crypt_hash_restart(struct crypt_hash *ctx) { - if (EVP_DigestInit(&ctx->md, ctx->hash_id) != 1) + if (EVP_DigestInit_ex(&ctx->md, ctx->hash_id, NULL) != 1) return -EINVAL; return 0; -- 2.1.4 --------------DA062BBEC241B7A0A0A16405--