From: "plaisthos (Code Review)" Date: Wed, 12 Nov 2025 13:40:10 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="jRtR7qkKYwU="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: Fix construction of invalid pointer in tls_pre_decrypt List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openvpn-devel --jRtR7qkKYwU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable plaisthos has uploaded this change for review. ( http://gerrit.openvpn.net/= c/openvpn/+/1373?usp=3Demail ) Change subject: Fix construction of invalid pointer in tls_pre_decrypt ...................................................................... Fix construction of invalid pointer in tls_pre_decrypt In tls_pre_decrypt we construct a pointer ks with an invalid i if i is TM_S= IZE doing a out-of-bounds access in multi->session. This is a something that exists at least since 2.3.0 (I didn't go further back but probalby exists in earlier version as well as the commits date back to SVN beta21 branch). So we construct the pointer but do not do anything with it if it is inval id as we check i *after* we construct the pointer `ks`. I suspect that the compiler optimises the bug away in any higher optimisati= on level. Assuming there is no optimisation, let's check what is possible. Since we never use the value `ks` if it is invalid, we do not have worry if it ends up invalid or not. The only thing that we have to worry about is whether `session + offsetof(struct tls_session, key[KS_PRIMARY])` is pointing to memory that is valid to read to construct the `ks` pointer. This is outside the tls_multi struct, so this is not guaranteed to be allocated memory but at the same time it is also only few bytes (or few tens/houndred) after the struct, so it will with an extremely high probably be in a memory region that will not cause a segfault. Every time this condition is hit and we construct the invalid pointer, the log message "TLS Error: Unroutable control packet received" is printed at `verb 1` or higher. And this is a quite common log message, which serves as indication as well that a crash is not something that typically happens but either the optimisation fixes or the memory region of the invalid access is valid to read from. Change-Id: Ided1ac7c804487055b175d8766535bead257b7d5 Signed-off-by: Arne Schwabe --- M src/openvpn/ssl.c 1 file changed, 2 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/73/1373/1 diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 398c9ae..e21ac78 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -3729,9 +3729,6 @@ } else { - struct tls_session *session =3D &multi->session[i]; - struct key_state *ks =3D &session->key[KS_PRIMARY]; - /* * Packet must belong to an existing session. */ @@ -3742,6 +3739,8 @@ goto error; } + struct tls_session *session =3D &multi->session[i]; + struct key_state *ks =3D &session->key[KS_PRIMARY]; /* * Verify remote IP address */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1373?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ided1ac7c804487055b175d8766535bead257b7d5 Gerrit-Change-Number: 1373 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-CC: openvpn-devel --jRtR7qkKYwU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

plaisthos has upl= oaded this change for review.

View Change

Fix construction of invalid pointer in tls_pre_decrypt

In tls_pr= e_decrypt we construct a pointer ks with an invalid i if i is TM_SIZE
do= ing a out-of-bounds access in multi->session.

This is a something= that exists at least since 2.3.0 (I didn't go further
back but prob= alby exists in earlier version as well as the commits date
back to SVN b= eta21 branch).

So we construct the pointer but do not do anything wi= th it if it is inval
id as we check i *after* we construct the pointer `= ks`.

I suspect that the compiler optimises the bug away in any highe= r optimisation
level.

Assuming there is no optimisation, let'= s check what is possible.
Since we never use the value `ks` if it is inv= alid, we do not have
worry if it ends up invalid or not. The only thing = that we have to
worry about is whether
`session + offsetof(struct tls= _session, key[KS_PRIMARY])` is pointing
to memory that is valid to read = to construct the `ks` pointer.
This is outside the tls_multi struct, so = this is not guaranteed to be
allocated memory but at the same time it is= also only few bytes (or few
tens/houndred) after the struct, so it will= with an extremely high
probably be in a memory region that will not cau= se a segfault.

Every time this condition is hit and we construct the= invalid pointer,
the log message "TLS Error: Unroutable control pa= cket received" is
printed at `verb 1` or higher. And this is a quit= e common log message,
which serves as indication as well that a crash is= not something that
typically happens but either the optimisation fixes = or the memory
region of the invalid access is valid to read from.
Change-Id: Ided1ac7c804487055b175d8766535bead257b7d5
Signed-off-by: Arn= e Schwabe <arne@...1227...>
---
M src/openvpn/ssl.c
1 file c= hanged, 2 insertions(+), 3 deletions(-)

git pull=
 ssh://gerrit.openvpn.net:29418/openvpn refs/changes/73/1373/1
diff=
 --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 398c9a= e..e21ac78 100644
--- a/src/openvpn/ssl.c
+= ++ b/src/openvpn/ssl.c
@@ -3729,9 +3729,6 @@
}
else
{
- struct tls_session *session =3D= &multi->session[i];
- struct key_state *ks =3D &session->key[KS_PRIMARY];
-
= /*
* Packet must belong to an existing session.=
*/
@@ -3742,6 +3739,8 @@<= br> goto error;
}

+ struct t= ls_session *session =3D &multi->session[i];
+ struct key_state *ks =3D &sessio= n->key[KS_PRIMARY];
/*
= * Verify remote IP address
*/
<= /span>

To view, visit change 1373. To unsubscribe, or for help writ= ing mail filters, visit settings.

=
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ided1ac7c804487055b175d87665= 35bead257b7d5
Gerrit-Change-Number: 1373
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --jRtR7qkKYwU=--