From: "cron2 (Code Review)" Date: Thu, 17 Oct 2024 07:01:26 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., steffan@...1856..., max@...2606... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="B0Sg73Bx5YE="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Improve data channel crypto error messages List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: syzzer , plaisthos , flichtenheld , MaxF Cc: openvpn-devel --B0Sg73Bx5YE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= syzzer. ( http://gerrit.openvpn.net/c/openvpn/+/774?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by MaxF Change subject: Improve data channel crypto error messages ...................................................................... Improve data channel crypto error messages * Make decryption error messages better understandable. * Increase verbosity level for authentication errors, because those can be expected on bad connections. Change-Id: I0fd48191babe4fe5c56f10eb3ba88182ffb075d1 Signed-off-by: Steffan Karger Acked-by: MaxF Message-Id: <20241017064955.23959-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29= 569.html Signed-off-by: Gert Doering --- M src/openvpn/crypto.c M src/openvpn/crypto.h 2 files changed, 12 insertions(+), 9 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/74/774/2 diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 12ad0b9..064e59e 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -459,14 +459,14 @@ if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf), data_len)) { - CRYPT_ERROR("cipher update failed"); + CRYPT_ERROR("packet decryption failed"); } ASSERT(buf_inc_len(&work, outlen)); if (!cipher_ctx_final_check_tag(ctx->cipher, BPTR(&work) + outlen, &outlen, tag_ptr, tag_size)) { - CRYPT_ERROR("cipher final failed"); + CRYPT_DROP("packet tag authentication failed"); } ASSERT(buf_inc_len(&work, outlen)); @@ -538,7 +538,7 @@ /* Compare locally computed HMAC with packet HMAC */ if (memcmp_constant_time(local_hmac, BPTR(buf), hmac_len)) { - CRYPT_ERROR("packet HMAC authentication failed"); + CRYPT_DROP("packet HMAC authentication failed"); } ASSERT(buf_advance(buf, hmac_len)); @@ -572,26 +572,26 @@ /* ctx->cipher was already initialized with key & keylen */ if (!cipher_ctx_reset(ctx->cipher, iv_buf)) { - CRYPT_ERROR("cipher init failed"); + CRYPT_ERROR("decrypt initialization failed"); } /* Buffer overflow check (should never happen) */ if (!buf_safe(&work, buf->len + cipher_ctx_block_size(ctx->cip= her))) { - CRYPT_ERROR("potential buffer overflow"); + CRYPT_ERROR("packet too big to decrypt"); } /* Decrypt packet ID, payload */ if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR= (buf), BLEN(buf))) { - CRYPT_ERROR("cipher update failed"); + CRYPT_ERROR("packet decryption failed"); } ASSERT(buf_inc_len(&work, outlen)); /* Flush the decryption buffer */ if (!cipher_ctx_final(ctx->cipher, BPTR(&work) + outlen, &outl= en)) { - CRYPT_ERROR("cipher final failed"); + CRYPT_DROP("packet authentication failed, dropping."); } ASSERT(buf_inc_len(&work, outlen)); diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 61184bc..d91de74 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -288,8 +288,11 @@ * security operation functions. */ }; -#define CRYPT_ERROR(format) \ - do { msg(D_CRYPT_ERRORS, "%s: " format, error_prefix); goto error_exit= ; } while (false) +#define CRYPT_ERROR_EXIT(flags, format) \ + do { msg(flags, "%s: " format, error_prefix); goto error_exit; } while= (false) + +#define CRYPT_ERROR(format) CRYPT_ERROR_EXIT(D_CRYPT_ERRORS, format) +#define CRYPT_DROP(format) CRYPT_ERROR_EXIT(D_MULTI_DROPPED, format) /** * Minimal IV length for AEAD mode ciphers (in bytes): -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/774?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I0fd48191babe4fe5c56f10eb3ba88182ffb075d1 Gerrit-Change-Number: 774 Gerrit-PatchSet: 2 Gerrit-Owner: syzzer Gerrit-Reviewer: MaxF Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --B0Sg73Bx5YE= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #2 to the change originally cr= eated by syzzer.

View Change

The following approvals got outdated an= d were removed: Code-Review+2 by MaxF

Improve data channel crypto error messages

* = Make decryption error messages better understandable.
* Increase verbos= ity level for authentication errors, because those can
be expected on= bad connections.

Change-Id: I0fd48191babe4fe5c56f10eb3ba88182ffb075= d1
Signed-off-by: Steffan Karger <steffan@...1856...>
Acked-by:= MaxF <max@...2606...>
Message-Id: <20241017064955.23959-1-gert= @...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1466...= urceforge.net/msg29569.html
Signed-off-by: Gert Doering <gert@...1726...= ...>
---
M src/openvpn/crypto.c
M src/openvpn/crypto.h
2 fil= es changed, 12 insertions(+), 9 deletions(-)

git pull ssh://gerri=
t.openvpn.net:29418/openvpn refs/changes/74/774/2
diff --git a/src/=
openvpn/crypto.c b/src/openvpn/crypto.c
index 12ad0b9..064e= 59e 100644
--- a/src/openvpn/crypto.c
+++ b= /src/openvpn/crypto.c
@@ -459,14 +459,14 @@
if (!cipher_ctx_update(ctx->cipher, BPTR(&work), &outlen, = BPTR(buf),
data_len)) {
- = CRYPT_ERROR("cipher update failed");
+ CRYPT_ERROR("packet decryption fail= ed");
}

AS= SERT(buf_inc_len(&work, outlen));
if (!cipher_ctx_= final_check_tag(ctx->cipher, BPTR(&work) + outlen,
= &outlen, tag_ptr, tag_size))=
{
- = CRYPT_ERROR("cipher final failed");
+ CRYPT_DROP("packet tag authentica= tion failed");
}
ASSERT(buf_= inc_len(&work, outlen));

@@ -538,7 +5= 38,7 @@
/* Compare locally computed HMAC with = packet HMAC */
if (memcmp_constant_time(local_= hmac, BPTR(buf), hmac_len))
{
- CRYPT_ERROR("pack= et HMAC authentication failed");
+ CRYPT_DROP("packet HMAC authenticati= on failed");
}
ASSERT(buf_advance(buf, hmac_len));
@@= -572,26 +572,26 @@
/* ctx->cipher was alre= ady initialized with key & keylen */
if (!= cipher_ctx_reset(ctx->cipher, iv_buf))
{
- CRYPT_ER= ROR("cipher init failed");
+ CRYPT_ERROR("decrypt initialization f= ailed");
}

/* Buffer overflow check (should never happen) */
if (!buf_safe(&work, buf->len + cipher_ctx_bloc= k_size(ctx->cipher)))
{
- CRYPT_ERROR("potenti= al buffer overflow");
+ CRYPT_ERROR("packet too big to decrypt");<= /span>
}

= /* Decrypt packet ID, payload */
if (!ciphe= r_ctx_update(ctx->cipher, BPTR(&work), &outlen, BPTR(buf), BLEN(= buf)))
{
- CRYPT_ERROR("cipher update failed"= ;);
+ = CRYPT_ERROR("packet decryption failed");
= }
ASSERT(buf_inc_len(&work, outlen));=

/* Flush the decryption buf= fer */
if (!cipher_ctx_final(ctx->cipher, B= PTR(&work) + outlen, &outlen))
{

- CRYPT_ERROR= ("cipher final failed");
+ CRYPT_DROP("packet authentication faile= d, dropping.");
}
= ASSERT(buf_inc_len(&work, outlen));

<= span>diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index 61184bc..d91de74 100644
--- a/src/openvpn/crypto.h=
+++ b/src/openvpn/crypto.h
@@ -288,8 +288,= 11 @@
* security operat= ion functions. */
};

-#define CRYPT_ERROR(format) \
<= span style=3D"color: hsl(0, 100%, 40%);">- do { msg(D_CRYPT_ERRORS, &quo= t;%s: " format, error_prefix); goto error_exit; } while (false)=
+#define CRYPT_ERROR_EXIT(f= lags, format) \
+ = do { msg(flags, "%s: " format, error_prefix); goto error_exit; } = while (false)
+
+#define CRYPT_ERROR(forma= t) CRYPT_ERROR_EXIT(D_CRYPT_ERRORS, format)
+#define CRYPT_DROP(format) CRYPT_ERROR_EXIT(D_MULTI= _DROPPED, format)

/**
= * Minimal IV length for AEAD mode ciphers (in bytes):

To view, visit change 774. To unsubscribe, or for help writing ma= il filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0fd48191babe4fe5c56f10eb3ba= 88182ffb075d1
Gerrit-Change-Number: 774
Gerrit-PatchSet: 2
Gerrit-Owner: syzzer <steffan@...1856...>= ;
Gerrit-Reviewer: MaxF <max@...2606...> <= /div>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--B0Sg73Bx5YE=--