From: "cron2 (Code Review)" Date: Fri, 31 Oct 2025 11:19:22 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: <56e6cbc34744b2efe990b08c006724a4275183b6-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="ARQUZZ1TviM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Zeroize tls-crypt-v2 client keys List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: MaxF Cc: plaisthos , flichtenheld , openvpn-devel --ARQUZZ1TviM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/13= 15?usp=3Demail ) Change subject: Zeroize tls-crypt-v2 client keys ...................................................................... Zeroize tls-crypt-v2 client keys Joshua Rogers sent in a bug report generated with ZeroPath that the tls-crypt-v2 client key is loaded before running the verify script. If the verify script fails, the key is not zeroized. While investigating this report, I found that free_tls_pre_decrypt_state never zeroizes tls_wrap_tmp.original_wrap_keydata. So also when the check is successful, key data will remain in memory when it is no longer needed. This commit moves the tls-crypt-v2-verify check before loading the key. If it fails, original_wrap_keydata is zeroized. Also, in free_tls_pre_decrypt_state, if a key has been loaded, original_wrap_keydata is zeroized. Reported-By: Joshua Rogers Found-by: ZeroPath (https://zeropath.com/) Change-Id: Icfcbf8ee20c1c0016eb98b570f24b9325b157c5c Signed-off-by: Max Fillinger Acked-by: Arne Schwabe Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1315 Message-Id: <20251031100819.24855-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 103.html Signed-off-by: Gert Doering --- M src/openvpn/ssl_pkt.c M src/openvpn/tls_crypt.c 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/openvpn/ssl_pkt.c b/src/openvpn/ssl_pkt.c index 825719c..d7f7ac3 100644 --- a/src/openvpn/ssl_pkt.c +++ b/src/openvpn/ssl_pkt.c @@ -280,6 +280,7 @@ if (state->tls_wrap_tmp.cleanup_key_ctx) { free_key_ctx_bi(&state->tls_wrap_tmp.opt.key_ctx_bi); + secure_memzero(&state->tls_wrap_tmp.original_wrap_keydata, sizeof(= state->tls_wrap_tmp.original_wrap_keydata)); } } diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index 51b4eb3..a808de3 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -642,6 +642,12 @@ return false; } + if (opt && opt->tls_crypt_v2_verify_script && !tls_crypt_v2_verify_met= adata(ctx, opt)) + { + secure_memzero(&ctx->original_wrap_keydata, sizeof(ctx->original_w= rap_keydata)); + return false; + } + /* Load the decrypted key */ ctx->mode =3D TLS_WRAP_CRYPT; ctx->cleanup_key_ctx =3D true; @@ -652,11 +658,6 @@ /* Remove client key from buffer so tls-crypt code can unwrap message = */ ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key)))); - if (opt && opt->tls_crypt_v2_verify_script) - { - return tls_crypt_v2_verify_metadata(ctx, opt); - } - return true; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1315?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Icfcbf8ee20c1c0016eb98b570f24b9325b157c5c Gerrit-Change-Number: 1315 Gerrit-PatchSet: 3 Gerrit-Owner: MaxF Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --ARQUZZ1TviM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Zeroize tls-crypt-v2 client keys

Joshua R= ogers sent in a bug report generated with ZeroPath that the
tls-crypt-v2= client key is loaded before running the verify script. If
the verify sc= ript fails, the key is not zeroized.

While investigating this report= , I found that free_tls_pre_decrypt_state
never zeroizes tls_wrap_tmp.or= iginal_wrap_keydata. So also when the
check is successful, key data will= remain in memory when it is no longer
needed.

This commit moves = the tls-crypt-v2-verify check before loading the key.
If it fails, origi= nal_wrap_keydata is zeroized. Also, in
free_tls_pre_decrypt_state, if a = key has been loaded,
original_wrap_keydata is zeroized.

Reported-= By: Joshua Rogers <contact@...2949...>
Found-by: ZeroPath (https:/= /zeropath.com/)

Change-Id: Icfcbf8ee20c1c0016eb98b570f24b9325b157c5c=
Signed-off-by: Max Fillinger <max@...2606...>
Acked-by: Arne S= chwabe <arne-openvpn@...1227...>
Gerrit URL: https://gerrit.openvp= n.net/c/openvpn/+/1315
Message-Id: <20251031100819.24855-1-gert@...1711...= 96...>
URL: https://www.mail-archive.com/openvpn-devel@...1357...= rge.net/msg34103.html
Signed-off-by: Gert Doering <gert@...1296...>= ;
---
M src/openvpn/ssl_pkt.c
M src/openvpn/tls_crypt.c
2 files= changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/openvpn/ssl_pkt.c b/src/openvpn/ssl_pkt.c
index 825719c..d7f7ac3 100644
--- a/src/openvpn/ssl_pkt.= c
+++ b/src/openvpn/ssl_pkt.c
@@ -280,6 +28= 0,7 @@
if (state->tls_wrap_tmp.cleanup_key_ctx)

{
free_key_ctx_bi(&state->= ;tls_wrap_tmp.opt.key_ctx_bi);
+ secure_memzero(&state->tls_wrap_tmp.original_wrap= _keydata, sizeof(state->tls_wrap_tmp.original_wrap_keydata));
= }
}

diff --gi= t a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c
index= 51b4eb3..a808de3 100644
--- a/src/openvpn/tls_crypt.c
+++ b/src/openvpn/tls_crypt.c
@@ -642,6 +642,12= @@
return false;
}
+ if (opt= && opt->tls_crypt_v2_verify_script && !tls_crypt_v2_ver= ify_metadata(ctx, opt))
+ {
+ se= cure_memzero(&ctx->original_wrap_keydata, sizeof(ctx->original_wr= ap_keydata));
+ = return false;
+ = }
+
= /* Load the decrypted key */
ctx->mode =3D TLS_= WRAP_CRYPT;
ctx->cleanup_key_ctx =3D true;@@ -652,11 +658,6 @@
/* Remove client key from= buffer so tls-crypt code can unwrap message */
ASSERT= (buf_inc_len(buf, -(BLEN(&wrapped_client_key))));

- if (opt && op= t->tls_crypt_v2_verify_script)
- {
- = return tls_crypt_v2_verify_metadata(ctx, opt);
- }
-
return true;
}

To view, visit change 1315. To un= subscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icfcbf8ee20c1c0016eb98b570f2= 4b9325b157c5c
Gerrit-Change-Number: 1315
Gerrit-PatchSet: 3
Gerrit-Owner: MaxF <max@...2606...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --ARQUZZ1TviM=--