From: "cron2 (Code Review)" Date: Wed, 12 Nov 2025 13:03:07 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <867319a2c4c4d9047084685783047307fdb92616-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="ZvvVGoye3jM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Do not underestimate number of encrypted/decrypted AEAD blocks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --ZvvVGoye3jM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/13= 58?usp=3Demail ) Change subject: Do not underestimate number of encrypted/decrypted AEAD blo= cks ...................................................................... Do not underestimate number of encrypted/decrypted AEAD blocks Even though the current code typically counts all the encrypted/decrypted traffic, this is only the case because of the specific implementation of OpenSSL at the moment. Instead of counting the length returned by one call only, count all the encrypted/decrypted bytes. Other implementations that use AES-GCM (like IPSec, MacSEC, TLS 1.2) (currently) do not honour these usage limits at all. This is the reason that I also currently do not consider the lack/improper validation in our code to be a security vulnerability. In the current state implementations/protoc= ol that lack this feature altogether are not considered vulnerable. Reported by: Change-Id: I429d768fb33ef2c58484287d4091440ad8599053 Signed-off-by: Arne Schwabe Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1358 Message-Id: <20251112112133.1325-1-gert@...1296...> Signed-off-by: Gert Doering --- M src/openvpn/crypto.c 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 307d1ee..8049b3a 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -152,15 +152,15 @@ ASSERT(cipher_ctx_update(ctx->cipher, BEND(&work), &outlen, BPTR(buf),= BLEN(buf))); ASSERT(buf_inc_len(&work, outlen)); - /* update number of plaintext blocks encrypted. Use the (x + (n-1))/n = trick - * to round up the result to the number of blocks used */ - const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; - opt->key_ctx_bi.encrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= )) / blocksize; - /* Flush the encryption buffer */ ASSERT(cipher_ctx_final(ctx->cipher, BEND(&work), &outlen)); ASSERT(buf_inc_len(&work, outlen)); + /* update number of plaintext blocks encrypted. Use the (x + (n-1))/n = trick + * to round up the result to the number of blocks used */ + const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; + opt->key_ctx_bi.encrypt.plaintext_blocks +=3D (BLEN(&work) + (blocksiz= e - 1)) / blocksize; + /* if the tag is at end the end, allocate it now */ if (use_epoch_data_format) { @@ -580,11 +580,10 @@ goto error_exit; } - /* update number of plaintext blocks decrypted. Use the (x + (n-1))/n = trick * to round up the result to the number of blocks used. */ const int blocksize =3D AEAD_LIMIT_BLOCKSIZE; - opt->key_ctx_bi.decrypt.plaintext_blocks +=3D (outlen + (blocksize - 1= )) / blocksize; + opt->key_ctx_bi.decrypt.plaintext_blocks +=3D (BLEN(&work) + (blocksiz= e - 1)) / blocksize; *buf =3D work; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1358?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: I429d768fb33ef2c58484287d4091440ad8599053 Gerrit-Change-Number: 1358 Gerrit-PatchSet: 4 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel --ZvvVGoye3jM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Do not underestimate number of encrypted/decrypt=
ed AEAD blocks

Even though the current code typically counts all the= encrypted/decrypted
traffic, this is only the case because of the speci= fic implementation
of OpenSSL at the moment.

Instead of counting = the length returned by one call only, count all
the encrypted/decrypted = bytes.

Other implementations that use AES-GCM (like IPSec, MacSEC, T= LS 1.2)
(currently) do not honour these usage limits at all. This is the= reason that
I also currently do not consider the lack/improper validati= on in our code
to be a security vulnerability. In the current state impl= ementations/protocol
that lack this feature altogether are not considere= d vulnerable.

Reported by: <stephan@...2953...>

Change-= Id: I429d768fb33ef2c58484287d4091440ad8599053
Signed-off-by: Arne Schwab= e <arne@...1227...>
Acked-by: Gert Doering <gert@...1296...>=
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1358
Message-Id: = <20251112112133.1325-1-gert@...1296...>
Signed-off-by: Gert Doerin= g <gert@...1296...>
---
M src/openvpn/crypto.c
1 file change= d, 6 insertions(+), 7 deletions(-)

diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c
index 307d1ee..8049b3a 100644
--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.c
@@ -152,15 +152,1= 5 @@
ASSERT(cipher_ctx_update(ctx->cipher, BEND(&am= p;work), &outlen, BPTR(buf), BLEN(buf)));
ASSERT(b= uf_inc_len(&work, outlen));

- /* update number of plaintext blocks encryp= ted. Use the (x + (n-1))/n trick
- * to round up the result to the number of blocks used */
- const int blocksize = =3D AEAD_LIMIT_BLOCKSIZE;
- opt->key_ctx_bi.encrypt.plaintext_blocks +=3D (outlen + (blocksi= ze - 1)) / blocksize;
-=
/* Flush the encryption buffer */
= ASSERT(cipher_ctx_final(ctx->cipher, BEND(&work), &outlen));
ASSERT(buf_inc_len(&work, outlen));

+ /* update num= ber of plaintext blocks encrypted. Use the (x + (n-1))/n trick
+ * to round up the result to= the number of blocks used */

+ const int blocksize =3D AEAD_LIMIT_BLOCKSIZE;
+ opt->key_ctx_bi.encrypt.plai= ntext_blocks +=3D (BLEN(&work) + (blocksize - 1)) / blocksize;
+
/* if = the tag is at end the end, allocate it now */
if (use_= epoch_data_format)
{
@@ -580,11 +580,1= 0 @@
goto error_exit;
}


- /* update number of plaintext blocks decrypted. Use the (x + (= n-1))/n trick
* to round up the result to the number = of blocks used. */
const int blocksize =3D AEAD_LIMIT_= BLOCKSIZE;
- opt->= ;key_ctx_bi.decrypt.plaintext_blocks +=3D (outlen + (blocksize - 1)) / bloc= ksize;
+ opt->k= ey_ctx_bi.decrypt.plaintext_blocks +=3D (BLEN(&work) + (blocksize - 1))= / blocksize;

*buf =3D work;<= br>

To view, visit change 1358. To u= nsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I429d768fb33ef2c58484287d409= 1440ad8599053
Gerrit-Change-Number: 1358
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --ZvvVGoye3jM=--