From patchwork Thu Mar 27 15:36:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4199 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:6c6:b0:60a:d70a:d3c7 with SMTP id j6csp109136maw; Thu, 27 Mar 2025 08:36:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW1mDiGVtFBzi8m8EuXezuOqYXrMk52qGrRZhVg2FWHLasqTkKSSrbNcXi/KSxjAKOzoeTXciLfjYk=@openvpn.net X-Google-Smtp-Source: AGHT+IFjB3AiQvE3a7SVavrnqohV57WNQ5i2LhSrRdU4WZ7uv4jp/mflvas3ndialsPEqRkyfP9k X-Received: by 2002:a92:c245:0:b0:3d2:b509:af44 with SMTP id e9e14a558f8ab-3d5ccdd1c28mr48214095ab.8.1743089788830; Thu, 27 Mar 2025 08:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743089788; cv=none; d=google.com; s=arc-20240605; b=UMZfy4f3F3ZXfCUSQWrfRcCJPTFgU96qu/VdRW0kpMilFhdP5GxhD1lKXCYluQj+EW g6hLzmOMOJjS0gRpH/mVNezc5Ih5U72pHFLSHfYPJHXVDxrdtGV6X/SuaZVjKAe0jOoI R3ptZ3C0i2XZ+RTGGiRdgf4umTlSkPCR8XJtgLOqlZPafNBOuWRNQJWBljmAID499PL7 nIdEyvJWa6KsxMWUCAlm+0VE0mo5EtzzJW275Mc99VdzQ3ZO+8rotQuozroQyyEwEVMo C8RfreVpfK7NPp/MNMy+ZlNxsY20pvBfbMIFRyt9jyz4137MUjSVe5nRkhOPfwUwfL2l oUrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding: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=wzq8oBt8LwQQu3qK3EyLunCabOnPoltErtHnANUrAkc=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=frQf/OHoEPRkeruLKPuWyOH8DpDUpCPAFcy/Rifx8dSGM/XsBUH3qbgGNMlk/RZ7bV chL/g0bt9WTwbLVddk0/KwM3LE47v+BxHa7vPJMssAgod76OZwyyprRPeYRE3m34T8Hz zaY/3338jpZ4d5EYb+aNI1uIROlCBTeBkvs8tSxvt8IBA3WkHf8Q7DDjCdEbMVnZLBYa RVrE9oahibIZI1BSNh54S20kAZqqJWECqKMt5VcRHtDcheEDmI6m9YF0QUrmuNINRk6R VJwmO34s1viwiZxI+uRgd2i2YIbY0D90Jb8XWCidFCjeyg3WlMcmAWijN48l38YKVGjC HiQQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=QP5fIlgr; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="RaQb/6+I"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 8926c6da1cb9f-4f46489bb8fsi20901173.133.2025.03.27.08.36.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Mar 2025 08:36:28 -0700 (PDT) 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=QP5fIlgr; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="RaQb/6+I"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de 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 ) id 1txpHN-0002gF-K6; Thu, 27 Mar 2025 15:36:25 +0000 Received: from [172.30.29.66] (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 ) id 1txpHM-0002g9-L9 for openvpn-devel@lists.sourceforge.net; Thu, 27 Mar 2025 15:36:24 +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:To:From:Sender:Reply-To:Cc: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=I7snTJz4nEWpxva1GUnhIsj3VxLab4MZp5ftxR8Y06g=; b=QP5fIlgrcmOAVOkxqNx+gUPSPj 0+EU6zGcIKLHmFXDZ9bMlC3vuTzonscztr8H07SbtL45m8zzMgNQncusDkmBJP6uVK4TloTkGtt8M xZ8GdWKUfDEhh1Pg/STHf2ELm/gcPt8Xa1204Uocc6ns/NgbM+aDm2GER77ZHqtS/VsU=; 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:To:From:Sender:Reply-To:Cc: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=I7snTJz4nEWpxva1GUnhIsj3VxLab4MZp5ftxR8Y06g=; b=RaQb/6+IuikLUe5O/IC1rGdEPW wfk6KtCA6ftQJoZV5szVTuBSNByk7Xfck4IhspyU8moLJrwRkKZGOdUQRu2h+AHr6NAcUVzjApXoU HfJ7g0sjnU/Lgr//+OxsNXUjEVi4t/4meK/CLbgCec3FsQyy4WWNnV7KeawUByXIc8Qk=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1txpHB-0002Re-Bw for openvpn-devel@lists.sourceforge.net; Thu, 27 Mar 2025 15:36:24 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 52RFa6BD015358 for ; Thu, 27 Mar 2025 16:36:06 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 52RFa6cY015355 for openvpn-devel@lists.sourceforge.net; Thu, 27 Mar 2025 16:36:06 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 27 Mar 2025 16:36:00 +0100 Message-ID: <20250327153606.15282-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.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: Arne Schwabe In case when key_state_export_keying_material fails we left a half-initialised tls_wrap_reneg structure in the tls_session. Later calls to try to free this structure causes freeing of invalid memory l [...] Content analysis details: (0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in bl.score.senderscore.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-Headers-End: 1txpHB-0002Re-Bw Subject: [Openvpn-devel] [PATCH v1] Do not leave half-initialised key wrap struct when dynamic tls-crypt fails 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1827762118350100109?= X-GMAIL-MSGID: =?utf-8?q?1827762118350100109?= From: Arne Schwabe In case when key_state_export_keying_material fails we left a half-initialised tls_wrap_reneg structure in the tls_session. Later calls to try to free this structure causes freeing of invalid memory locations. To test: make key_state_export_keying_material return false even though HAVE_EXPORT_KEYING_MATERIAL is defined and connect to a server supporting dynamic tls-crypt (2.6.0+) Change-Id: I54073f8b63894a62699f6ecdc90a77f9f131205b Signed-off-by: Arne Schwabe Acked-by: MaxF --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/921 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): MaxF diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index eb7b03d..9e9807d 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -97,6 +97,15 @@ bool tls_session_generate_dynamic_tls_crypt_key(struct tls_session *session) { + struct key2 rengokeys; + if (!key_state_export_keying_material(session, EXPORT_DYNAMIC_TLS_CRYPT_LABEL, + strlen(EXPORT_DYNAMIC_TLS_CRYPT_LABEL), + rengokeys.keys, sizeof(rengokeys.keys))) + { + return false; + } + rengokeys.n = 2; + session->tls_wrap_reneg.opt = session->tls_wrap.opt; session->tls_wrap_reneg.mode = TLS_WRAP_CRYPT; session->tls_wrap_reneg.cleanup_key_ctx = true; @@ -108,16 +117,6 @@ session->opt->replay_time, "TLS_WRAP_RENEG", session->key_id); - - struct key2 rengokeys; - if (!key_state_export_keying_material(session, EXPORT_DYNAMIC_TLS_CRYPT_LABEL, - strlen(EXPORT_DYNAMIC_TLS_CRYPT_LABEL), - rengokeys.keys, sizeof(rengokeys.keys))) - { - return false; - } - rengokeys.n = 2; - if (session->tls_wrap.mode == TLS_WRAP_CRYPT || session->tls_wrap.mode == TLS_WRAP_AUTH) {