From: "cron2 (Code Review)" Date: Thu, 9 Jan 2025 21:25:58 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: <8f3822baac0b4bfb5a2f3c918fc579a66a4eb410-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="x4OWHwdUZcM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Do not attempt to decrypt packets anymore after 2**36 failed decryptions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld , MaxF Cc: openvpn-devel --x4OWHwdUZcM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#6) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/843?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by MaxF Change subject: Do not attempt to decrypt packets anymore after 2**36 faile= d decryptions ...................................................................... Do not attempt to decrypt packets anymore after 2**36 failed decryptions To avoid attacks (especially on Chacha20-Poly1305) we do not allow decryption anymore after 2**36 failed verifications. After 2**35, we trigger a renegotiation (to avoid that situation). For the theoretical background, see - https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/ - RFC 9147 (DTLS 1.3) section 4.5.3 "AEAD limits" - https://eprint.iacr.org/2024/051.pdf Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190 Signed-off-by: Arne Schwabe Acked-by: MaxF Message-Id: <20250109174928.17862-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30= 387.html Signed-off-by: Gert Doering --- M src/openvpn/crypto.c M src/openvpn/crypto.h M src/openvpn/ssl.c 3 files changed, 41 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/43/843/6 diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index df38cdd..ee9b0c6 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -405,7 +405,13 @@ { static const char error_prefix[] =3D "AEAD Decrypt error"; struct packet_id_net pin =3D { 0 }; - const struct key_ctx *ctx =3D &opt->key_ctx_bi.decrypt; + struct key_ctx *ctx =3D &opt->key_ctx_bi.decrypt; + + if (cipher_decrypt_verify_fail_exceeded(ctx)) + { + CRYPT_DROP("Decryption failed verification limit reached."); + } + int outlen; struct gc_arena gc; @@ -511,6 +517,7 @@ if (!cipher_ctx_final_check_tag(ctx->cipher, BPTR(&work) + outlen, &outlen, tag_ptr, tag_size)) { + ctx->failed_verifications++; CRYPT_DROP("packet tag authentication failed"); } ASSERT(buf_inc_len(&work, outlen)); diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 3ad31c5..fe81c7f 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -209,6 +209,8 @@ * with the current key in number of 128 bit blocks (only used for * AEAD ciphers) */ uint64_t plaintext_blocks; + /** number of failed verification using this cipher */ + uint64_t failed_verifications; }; #define KEY_DIRECTION_BIDIRECTIONAL 0 /* same keys for both directions */ @@ -661,6 +663,32 @@ cipher_get_aead_limits(const char *ciphername); /** + * Check if the number of failed decryption is over the acceptable limit. + */ +static inline bool +cipher_decrypt_verify_fail_exceeded(const struct key_ctx *ctx) +{ + /* Use 2**36, same as DTLS 1.3. Strictly speaking this only guarantees + * the security margin for packets up to 2^10 blocks (16384 bytes) + * but we accept slightly lower security bound for the edge + * of Chacha20-Poly1305 and packets over 16k as MTUs over 16k are + * extremely rarely used */ + return ctx->failed_verifications > (1ull << 36); +} + +/** + * Check if the number of failed decryption is approaching the limit and we + * should try to move to a new key + */ +static inline bool +cipher_decrypt_verify_fail_warn(const struct key_ctx *ctx) +{ + /* Use 2**35, half the amount after which we refuse to decrypt */ + return ctx->failed_verifications > (1ull << 35); +} + + +/** * Blocksize used for the AEAD limit caluclation * * Since cipher_ctx_block_size() is not reliable and will return 1 in many diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index cf7f34f..e4a7b57 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -3005,6 +3005,11 @@ return true; } + if (cipher_decrypt_verify_fail_warn(&key_ctx_bi->decrypt)) + { + return true; + } + return false; } /* -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/843?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: I81440ac28a1ad553652e201234e5ddfe03a8c190 Gerrit-Change-Number: 843 Gerrit-PatchSet: 6 Gerrit-Owner: plaisthos Gerrit-Reviewer: MaxF Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --x4OWHwdUZcM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #6 to the change originally cr= eated by plaisthos.

View Change

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

Do not attempt to decrypt packets anymore after 2**36=
 failed decryptions

To avoid attacks (especially on Chacha20-Poly130= 5) we do not allow
decryption anymore after 2**36 failed verifications.<= br>
After 2**35, we trigger a renegotiation (to avoid that situation).
For the theoretical background, see

- https://datatracker.i= etf.org/doc/draft-irtf-cfrg-aead-limits/
- RFC 9147 (DTLS 1.3) sectio= n 4.5.3 "AEAD limits"
- https://eprint.iacr.org/2024/051.pd= f

Change-Id: I81440ac28a1ad553652e201234e5ddfe03a8c190
Signed-off= -by: Arne Schwabe <arne@...1227...>
Acked-by: MaxF <max@...2853...= ...>
Message-Id: <20250109174928.17862-1-gert@...1296...>
UR= L: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg3038= 7.html
Signed-off-by: Gert Doering <gert@...1296...>
---
M s= rc/openvpn/crypto.c
M src/openvpn/crypto.h
M src/openvpn/ssl.c
3 f= iles changed, 41 insertions(+), 1 deletion(-)

git pull ssh://gerr=
it.openvpn.net:29418/openvpn refs/changes/43/843/6
diff --git a/src=
/openvpn/crypto.c b/src/openvpn/crypto.c
index df38cdd..ee9= b0c6 100644
--- a/src/openvpn/crypto.c
+++ = b/src/openvpn/crypto.c
@@ -405,7 +405,13 @@
{
static const char error_prefix[] =3D "AEAD De= crypt error";
struct packet_id_net pin =3D { 0 };=
- const struct key_= ctx *ctx =3D &opt->key_ctx_bi.decrypt;
+ struct key_ctx *ctx =3D &opt->key_ctx_= bi.decrypt;
+<= br>+ if (cipher_decrypt_veri= fy_fail_exceeded(ctx))
+ CRY= PT_DROP("Decryption failed verification limit reached.");<= br>+ }
+
int outlen;<= br> struct gc_arena gc;

@@ -511= ,6 +517,7 @@
if (!cipher_ctx_final_check_tag(ctx->c= ipher, BPTR(&work) + outlen,
= &outlen, tag_ptr, tag_size))
{+ ctx->failed_verif= ications++;
CRYPT_DROP("packet tag authentica= tion failed");
}
ASSERT(buf_= inc_len(&work, outlen));
diff --git a/src/openvpn/crypt= o.h b/src/openvpn/crypto.h
index 3ad31c5..fe81c7f 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/= crypto.h
@@ -209,6 +209,8 @@
* with t= he current key in number of 128 bit blocks (only used for
= * AEAD ciphers) */
uint64_t plaintext_blocks;
+ /** number of faile= d verification using this cipher */
+ uint64_t failed_verifications;
};

#define KEY_DIRECTION_BIDIRECTIONAL 0 /* sam= e keys for both directions */
@@ -661,6 +663,32 @@ cipher_get_aead_limits(const char *ciphername);
<= /span>
/**
= + * Check if the number of failed decryption is over the acceptable limit.<= /span>
+ */
+static inline bool
+cipher_decrypt_verify_fail_exceeded(c= onst struct key_ctx *ctx)
+{
+ /* Use 2= **36, same as DTLS 1.3. Strictly speaking this only guarantees
+ * the security margin for p= ackets up to 2^10 blocks (16384 bytes)

+ * but we accept slightly lower security bound for t= he edge
+ * of Ch= acha20-Poly1305 and packets over 16k as MTUs over 16k are
+ * extremely rarely used */

+ return ctx->failed= _verifications > (1ull << 36);
+}
+/**
+ * Check if the number of failed= decryption is approaching the limit and we
+ * should try to move to a new key
+ */
+static inline bool
+cipher_decrypt_verify_fail_warn(const struct key_ctx = *ctx)
+{
+ /* Use 2**35, half the amoun= t after which we refuse to decrypt */
+ return ctx->failed_verifications > (1ull <&= lt; 35);
+}+
+
+/**
* Blocksize used for the AEAD limit caluclati= on
*
* Since cipher_ctx_block_size() is= not reliable and will return 1 in many
diff --git a/src/op= envpn/ssl.c b/src/openvpn/ssl.c
index cf7f34f..e4a7b57 1006= 44
--- a/src/openvpn/ssl.c
+++ b/src/openvp= n/ssl.c
@@ -3005,6 +3005,11 @@
ret= urn true;
}

+ if (cipher_decrypt_verify_fail_warn(&= ;key_ctx_bi->decrypt))
+ {
+ = return true;
+ }
+
= return false;
}
/*

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I81440ac28a1ad553652e201234e= 5ddfe03a8c190
Gerrit-Change-Number: 843
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: MaxF <max@...2606...> <= /div>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--x4OWHwdUZcM=--