From: "plaisthos (Code Review)" Date: Wed, 8 May 2024 18:09:45 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <8d0a0a251e08739204f66849157127fec88eb0cc-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="oxCxT5gbuxc="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Workaround issue in LibreSSL crashing when enumerating digests/ciphers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --oxCxT5gbuxc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/586?usp=3Demail to review the following change. Change subject: Workaround issue in LibreSSL crashing when enumerating dige= sts/ciphers ...................................................................... Workaround issue in LibreSSL crashing when enumerating digests/ciphers OpenBSD/LibreSSL reimplemented EVP_get_cipherbyname/EVP_get_digestbyname and broke calling EVP_get_cipherbynid/EVP_get_digestbyname with an invalid nid in the process so that it would segfault. Workaround but doing that NULL check in OpenVPN instead of leaving it to the library. Change-Id: Ia08a9697d0ff41721fb0acf17ccb4cfa23cb3934 Signed-off-by: Arne Schwabe --- M src/openvpn/crypto_openssl.c 1 file changed, 25 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/86/586/1 diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 61c6518..1649ab7 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -387,7 +387,19 @@ #else for (int nid =3D 0; nid < 10000; ++nid) { +#if defined(LIBRESSL_VERSION_NUMBER) + /* OpenBSD/LibreSSL reimplemented EVP_get_cipherbyname and broke + * calling EVP_get_cipherbynid with an invalid nid in the process + * so that it would segfault. */ + const EVP_CIPHER *cipher =3D NULL; + const char *name =3D OBJ_nid2sn(nid); + if (name) + { + cipher =3D EVP_get_cipherbyname(name); + } +#else /* if defined(LIBRESSL_VERSION_NUMBER) */ const EVP_CIPHER *cipher =3D EVP_get_cipherbynid(nid); +#endif /* We cast the const away so we can keep the function prototype * compatible with EVP_CIPHER_do_all_provided */ collect_ciphers((EVP_CIPHER *) cipher, &cipher_list); @@ -441,7 +453,19 @@ #else for (int nid =3D 0; nid < 10000; ++nid) { + /* OpenBSD/LibreSSL reimplemented EVP_get_digestbyname and broke + * calling EVP_get_digestbynid with an invalid nid in the process + * so that it would segfault. */ +#ifdef LIBRESSL_VERSION_NUMBER + const EVP_MD *digest =3D NULL; + const char *name =3D OBJ_nid2sn(nid); + if (name) + { + digest =3D EVP_get_digestbyname(name); + } +#else /* ifdef LIBRESSL_VERSION_NUMBER */ const EVP_MD *digest =3D EVP_get_digestbynid(nid); +#endif if (digest) { /* We cast the const away so we can keep the function prototype @@ -449,7 +473,7 @@ print_digest((EVP_MD *)digest, NULL); } } -#endif +#endif /* if OPENSSL_VERSION_NUMBER >=3D 0x30000000L */ printf("\n"); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/586?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: Ia08a9697d0ff41721fb0acf17ccb4cfa23cb3934 Gerrit-Change-Number: 586 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --oxCxT5gbuxc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

Vi= ew Change

Workaround issue in LibreSSL crashing when enumerating digest=
s/ciphers

OpenBSD/LibreSSL reimplemented EVP_get_cipherbyname/EVP_ge= t_digestbyname
and broke calling EVP_get_cipherbynid/EVP_get_digestbynam= e with an
invalid nid in the process so that it would segfault.

W= orkaround but doing that NULL check in OpenVPN instead of leaving it
to = the library.

Change-Id: Ia08a9697d0ff41721fb0acf17ccb4cfa23cb3934Signed-off-by: Arne Schwabe <arne@...1227...>
---
M src/openvp= n/crypto_openssl.c
1 file changed, 25 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/86/586/1<=
/pre>
+#if defined(LIBRESS=
L_VERSION_NUMBER)
+ = /* OpenBSD/LibreSSL reimplemented EVP_get_cipherbyname and broke
+ * calling EVP_g= et_cipherbynid with an invalid nid in the process
+ * so that it would segfault. */
+ const EVP_CIPHER= *cipher =3D NULL;
+ = const char *name =3D OBJ_nid2sn(nid);
+ if (name)
+ {
+ cipher =3D EVP_get_cipherbyname(name);
<= span style=3D"color: hsl(120, 100%, 40%);">+ }

+#else /* if defined(LIBRESSL_VERSION_NUM= BER) */
const EVP_CIPHER *cipher =3D EVP_get_ciphe= rbynid(nid);
+#endif<= /span>
/* We cast the const away so we can keep the funct= ion prototype
* compatible with EVP_CIPHER_do_all= _provided */
collect_ciphers((EVP_CIPHER *) cipher= , &cipher_list);
@@ -441,7 +453,19 @@
= #else
for (int nid =3D 0; nid < 10000; ++nid)
{
+ = /* OpenBSD/LibreSSL reimplemented EVP_get_digestbyname and broke
+ * calling EVP_g= et_digestbynid with an invalid nid in the process
+ * so that it would segfault. */
+#ifdef LIBRESSL_VERSION_= NUMBER
+ const= EVP_MD *digest =3D NULL;
+ const char *name =3D OBJ_nid2sn(nid);
+ if (name)
+ {
+ digest =3D EVP_get_digestbyname(name);<= /span>
+ }
= +#else /* ifdef LIBRESSL_VERSI= ON_NUMBER */
const EVP_MD *digest =3D EVP_get_dige= stbynid(nid);
+#endif=
if (digest)
{
= /* We cast the const away so we can keep the function pr= ototype
@@ -449,7 +473,7 @@
pr= int_digest((EVP_MD *)digest, NULL);
}
}

-#endif
+#endif /* if OPENSSL_VER= SION_NUMBER >=3D 0x30000000L */
printf("\n&quo= t;);
}


=

To view, visit change 586. To unsubscribe, or for help writing mail filters,= visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia08a9697d0ff41721fb0acf17cc= b4cfa23cb3934
Gerrit-Change-Number: 586
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--oxCxT5gbuxc=--