From patchwork Sun Apr 4 22:00:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1711 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id mOewC7nDamCmJgAAIUCqbw (envelope-from ) for ; Mon, 05 Apr 2021 04:00:57 -0400 Received: from proxy10.mail.iad3b.rsapps.net ([172.31.255.6]) by director7.mail.ord1d.rsapps.net with LMTP id gF90C7nDamDAXgAAovjBpQ (envelope-from ) for ; Mon, 05 Apr 2021 04:00:57 -0400 Received: from smtp24.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy10.mail.iad3b.rsapps.net with LMTPS id UO3bBLnDamDnUAAA/F5p9A (envelope-from ) for ; Mon, 05 Apr 2021 04:00:57 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp24.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: 0cec40fe-95e5-11eb-b5d9-525400892b35-1-1 Received: from [216.105.38.7] ([216.105.38.7:33746] helo=lists.sourceforge.net) by smtp24.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 31/35-10864-8B3CA606; Mon, 05 Apr 2021 04:00:56 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1lTK9j-0006aV-4z; Mon, 05 Apr 2021 08:00:19 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lTK9f-0006Zt-I6 for openvpn-devel@lists.sourceforge.net; Mon, 05 Apr 2021 08:00:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RGjU+a/mjmWcIB/o+2brNDoC76gCE3cs250E2xpc+v0=; b=JC7D7RYV/Z9LnojXZF9mItlKGi v8810BFUZNVbbjQIhlG7ZddGhGxQyL6W7eNSHzLAjsxFMgj2U9VXVxlcXo5SRnjmh6I9XCrq7/6lO Vhk/L9NkieIrqOYeh8+1vVEsAxya15nYn9ByC0vNey7dARD7f8FusfCSKhwEw+OP5UfU=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=RGjU+a/mjmWcIB/o+2brNDoC76gCE3cs250E2xpc+v0=; b=m J/HPYORnKM7a1bB7a61IjIXdSfk0Czzy6quLzHN18JaZI5irS4UYWFdoVq4v6x0cw8Ty+vhI1UJKD plpTyw0bhUKeP6A7WZtklBmZMrdYl8CKGh9mJSqjgFtRsRha6WjKSMybGUAsgXKOyrryBBAnvj0F/ Udv7NjZO8YkmBZtk=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1lTK9b-003QUO-1Y for openvpn-devel@lists.sourceforge.net; Mon, 05 Apr 2021 08:00:15 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Mon, 5 Apr 2021 10:00:05 +0200 Message-Id: <20210405080007.1665-1-a@unstable.cc> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1lTK9b-003QUO-1Y Subject: [Openvpn-devel] [PATCH 1/3] openssl: fix EVP_PKEY_CTX memory leak X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Antonio Quartulli A context allocated with EVP_PKEY_CTX_new_id() must be ultimately free'd by Eng VP_PKEY_CTX_free(). Failing to do so will result in a memory leak. This bug was discovered using GCC with "-fsanitize=address". Signed-off-by: Antonio Quartulli Acked-by: Gert Doering --- src/openvpn/crypto_openssl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index f3e86863..d54ca6d2 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -1125,37 +1125,41 @@ bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int secret_len, uint8_t *output, int output_len) { + bool ret = false; EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL); if (!EVP_PKEY_derive_init(pctx)) { - return false; + goto out; } if (!EVP_PKEY_CTX_set_tls1_prf_md(pctx, EVP_md5_sha1())) { - return false; + goto out; } if (!EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, secret, secret_len)) { - return false; + goto out; } if (!EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed, seed_len)) { - return false; + goto out; } size_t out_len = output_len; if (!EVP_PKEY_derive(pctx, output, &out_len)) { - return false; + goto out; } if (out_len != output_len) { - return false; + goto out; } - return true; + ret = true; +out: + EVP_PKEY_CTX_free(pctx); + return ret; } #else /* if OPENSSL_VERSION_NUMBER >= 0x10100000L */ /*