[Openvpn-devel,2/8] ssl_verify: Fix memleak if creating deferred auth control files fails
| Message ID | 20221215190143.2107896-3-arne@rfc2549.org |
|---|---|
| State | Accepted |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:7300:c95:b0:82:e4b3:40a0 with SMTP id p21csp631566dyk;
Thu, 15 Dec 2022 11:02:15 -0800 (PST)
X-Google-Smtp-Source:
AA0mqf4mvG+8U76zC6xxh8nMXrBnjbHEsigvOD4ZPnWx3EF4kd+lN01XNxzZ370r2qlYsV6NQQKC
X-Received: by 2002:a1f:ee4e:0:b0:3bd:f324:5500 with SMTP id
m75-20020a1fee4e000000b003bdf3245500mr17123303vkh.2.1671130935332;
Thu, 15 Dec 2022 11:02:15 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1671130935; cv=none;
d=google.com; s=arc-20160816;
b=LKIyKgCZV/UcexvXDh+SFGMqK7AMkIY5vT1wrk5qywNk21v6SPApv13uyi/PlVdKdP
oIEu9eS2vauUWkArAyXQLpYZg1SmCGddNJVZ8fyKFXjq42DxxMW/QcOxAXg9E6JQxf0n
u4p/JpfXZzSNP7b/N3unqiHDXgmIKk2mgtfxA/zdrxPPPab18JqW5jhcw0S2twqlaW0P
XVZh5HgHAZARSr4QcW3NemCAin8DWRExSP0CzrTdalS2NWRwvPqAk0n7GRfj1hBQ0GMZ
+m1EwtvfdkHTDn4rQxe0bt/yQSoTYnhNBGdO3/Y6eQEvQfSUpjpAEuL1UYFQ0IAWamHm
TbTg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20160816;
h=errors-to:content-transfer-encoding:cc:list-subscribe:list-help
:list-post:list-archive:list-unsubscribe:list-id:precedence:subject
:mime-version:references:in-reply-to:message-id:date:to:from
:dkim-signature:dkim-signature;
bh=XTX+eU+DnU5WAwL/QBJEAUjGQ1ju8tuU8h5NDBaBcS4=;
b=i4Pkc0R+b0mpKmWJmNEC5zr/OFFATroBwiVNC6CXCzuvVsXG+tj87FcaFpF66R15Yh
Sw9kxvAswsJEn0q2PiNp6RIq4YWP/q0FBbeaj7NRyQ395PbKsf15fJ/aLEQ5mKo80vP2
yBA5n43RlYXiqQei1RnYV7Ap0vcVRxm5RF/Ub6mMAGKDZ0DejFGvsn/dfR5qL1XwBhgw
hn0whfMT1VEkxVRCrlUgzXdPx+ga45FOoTXDj4yRI1kSgalTe2XkGzldlNlpQ4fXTa+0
xFgbt6VXTcBRQ3T48COb7OonsqO3aUzbqyFg7RVcDSm1aS+F5zLPeFwvpUMk0nywOsMo
fl4w==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=PNlG99cz;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=L6wwEmTl;
spf=pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net
Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7])
by mx.google.com with ESMTPS id
b143-20020a1f1b95000000b003b7f0e38cd0si1921994vkb.298.2022.12.15.11.02.14
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Thu, 15 Dec 2022 11:02:15 -0800 (PST)
Received-SPF: pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) client-ip=216.105.38.7;
Authentication-Results: mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=PNlG99cz;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=L6wwEmTl;
spf=pass (google.com: domain of
openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as
permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net
Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com)
by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95)
(envelope-from <openvpn-devel-bounces@lists.sourceforge.net>)
id 1p5tUV-0001xc-O7;
Thu, 15 Dec 2022 19:01:59 +0000
Received: from [172.30.20.202] (helo=mx.sourceforge.net)
by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95)
(envelope-from <arne@kamera.blinkt.de>) id 1p5tUS-0001wq-C0
for openvpn-devel@lists.sourceforge.net;
Thu, 15 Dec 2022 19:01:56 +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:References:
In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:
List-Subscribe:List-Post:List-Owner:List-Archive;
bh=n2PEcv+Kb2dBd2nCvjG2qGDplTg78GlTf7dqsklWrSM=; b=PNlG99czMmTUkQnkZwzOGgXurs
MZjEFse4hpygc7f9MDTjhz7ZJiuFy1MTkEtN8//h+sE32y3dj+G3nesNY5AAS/8s/nex2362bG8FX
VfnKCgfJqny9ZRPO0TXTMnTZNvqOqUTHps1lRc74TZA/0hKYrdzZGt1KjAx4JNpIwwzQ=;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x
;
h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
List-Post:List-Owner:List-Archive;
bh=n2PEcv+Kb2dBd2nCvjG2qGDplTg78GlTf7dqsklWrSM=; b=L6wwEmTlKETMFDKG7TRUR7pUVb
91oykHdFB9QEZ9hUkDQqF9K649pIfVGmLXqlZDBZIRoJGpaSxgdJL1AQ5vMTuZ1Im+u73Igmkyja6
WLspmsI53ksjZEBVdyu5cbX+ldbeyrgxyZQZKsV/Ivv7klu3FOsBqmIjFdngsFuIWdAA=;
Received: from mail.blinkt.de ([192.26.174.232])
by sfi-mx-1.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95)
id 1p5tUR-000hyp-Tu for openvpn-devel@lists.sourceforge.net;
Thu, 15 Dec 2022 19:01:56 +0000
Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c])
by mail.blinkt.de with smtp (Exim 4.95 (FreeBSD))
(envelope-from <arne@kamera.blinkt.de>) id 1p5tUF-000Kvy-9b;
Thu, 15 Dec 2022 20:01:43 +0100
Received: (nullmailer pid 2107948 invoked by uid 10006);
Thu, 15 Dec 2022 19:01:43 -0000
From: Arne Schwabe <arne@rfc2549.org>
To: openvpn-devel@lists.sourceforge.net
Date: Thu, 15 Dec 2022 20:01:37 +0100
Message-Id: <20221215190143.2107896-3-arne@rfc2549.org>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20221215190143.2107896-1-arne@rfc2549.org>
References: <20221215190143.2107896-1-arne@rfc2549.org>
MIME-Version: 1.0
X-Spam-Score: 0.3 (/)
X-Spam-Report: Spam detection software,
running on the system "util-spamd-2.v13.lw.sourceforge.com",
has NOT identified this incoming email as spam. The original
message has been attached to this so you can view it or label
similar future email. If you have any questions, see
the administrator of that system for details.
Content preview: From: David Sommerseth <davids@openvpn.net> If the
key_state_gen_auth_control_files()
call fails, the code would just return without freeing the argv container.
Instead the code should jump to an appropriate exit point where memory is
being rel [...]
Content analysis details: (0.3 points, 6.0 required)
pts rule name description
---- ----------------------
--------------------------------------------------
0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record
0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level
mail domains are different
0.0 SPF_NONE SPF: sender does not publish an SPF Record
X-Headers-End: 1p5tUR-000hyp-Tu
Subject: [Openvpn-devel] [PATCH 2/8] ssl_verify: Fix memleak if creating
deferred auth control files fails
X-BeenThere: openvpn-devel@lists.sourceforge.net
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <openvpn-devel.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive:
<http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel>
List-Post: <mailto:openvpn-devel@lists.sourceforge.net>
List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe>
Cc: David Sommerseth <davids@openvpn.net>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: openvpn-devel-bounces@lists.sourceforge.net
X-getmail-retrieved-from-mailbox: Inbox
X-GMAIL-THRID: =?utf-8?q?1752307792098682429?=
X-GMAIL-MSGID: =?utf-8?q?1752307792098682429?=
|
| Series |
Improvement/fixes based on Trail of Bits audit
|
|
Commit Message
Arne Schwabe
Dec. 15, 2022, 7:01 p.m. UTC
From: David Sommerseth <davids@openvpn.net> If the key_state_gen_auth_control_files() call fails, the code would just return without freeing the argv container. Instead the code should jump to an appropriate exit point where memory is being released. Also adjust the related comment, to indicate that these deferred auth control files are really pre-created. Signed-off-by: David Sommerseth <davids@openvpn.net> Reported-by: Trial of Bits (TOB-OVPN-2) Signed-off-by: Arne Schwabe <arne@rfc2549.org> --- src/openvpn/ssl_verify.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Comments
Am 15.12.2022 um 20:01 schrieb Arne Schwabe: > From: David Sommerseth <davids@openvpn.net> > > If the key_state_gen_auth_control_files() call fails, the code would > just return without freeing the argv container. Instead the code should > jump to an appropriate exit point where memory is being released. > > Also adjust the related comment, to indicate that these deferred auth > control files are really pre-created. > > Signed-off-by: David Sommerseth <davids@openvpn.net> > > Reported-by: Trial of Bits (TOB-OVPN-2) Typo here: Should be Trail of Bits (my mistake)
Acked-by: Gert Doering <gert@greenie.muc.de> As agreed on the security@ list - this covers all possible leaks, and is fully "normal OpenVPN style". I didn't test actual file creation failures, but I *did* test regular server operation with plugins and scripts, and that all still works fine. As instructed, I've fixed the "Trial" to read "Trail of Bits" :-) Your patch has been applied to the master and release/2.6 branch. release/2.5 and older do not contain this code (no async/deferred --verify-auth-user-pass scripts yet) - that was only added in 2021 via commit 28e6103096ae8. commit 0567da5377704cf64bd2599f2d49aa478d386941 (master) commit cdfdfb3da0ce714f43b23f679a8ef9b36ab9f370 (release/2.6) Author: David Sommerseth Date: Thu Dec 15 20:01:37 2022 +0100 ssl_verify: Fix memleak if creating deferred auth control files fails Signed-off-by: David Sommerseth <davids@openvpn.net> Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <20221215190143.2107896-3-arne@rfc2549.org> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25737.html Signed-off-by: Gert Doering <gert@greenie.muc.de> -- kind regards, Gert Doering
diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 76cb9f19b..228cf16e1 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -1358,12 +1358,13 @@ verify_user_pass_script(struct tls_session *session, struct tls_multi *multi, setenv_str(session->opt->es, "password", up->password); } - /* generate filename for deferred auth control file */ + /* pre-create files for deferred auth control */ if (!key_state_gen_auth_control_files(&ks->script_auth, session->opt)) { msg(D_TLS_ERRORS, "TLS Auth Error (%s): " "could not create deferred auth control file", __func__); - return OPENVPN_PLUGIN_FUNC_ERROR; + retval = OPENVPN_PLUGIN_FUNC_ERROR; + goto error; } /* call command */ @@ -1412,6 +1413,7 @@ done: platform_unlink(tmp_file); } +error: argv_free(&argv); gc_free(&gc); return retval;