From: "cron2 (Code Review)" Date: Mon, 2 Mar 2026 21:51:05 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, steffan@...1856..., max@...2606... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="gzyNTMJ48ec="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Avoid unbounded allocations in pkcs11_mbedtls.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: MaxF Cc: plaisthos , syzzer , openvpn-devel --gzyNTMJ48ec= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/15= 49?usp=3Demail ) Change subject: Avoid unbounded allocations in pkcs11_mbedtls.c ...................................................................... Avoid unbounded allocations in pkcs11_mbedtls.c The PKCS#11 provider can crash OpenVPN by making it try to allocate 2^64 bytes for a certificate. To avoid this, set a maximum size for certificates. If the size is exceeded, don't try to allocate memory and instead exit pkcs11_get_x509_cert with an error. The chosen maximum size is 100.000 bytes which is twice the size of a SLH-DSA (aka SPHINCS+) signature. Found-by: ZeroPath (https://zeropath.com/) Reported-by: Joshua Rogers Github: closes OpenVPN/openvpn-private-issues#42 Change-Id: I53d47e4a0d33c380ee95e0e33aecad3db3197940 Signed-off-by: Max Fillinger Acked-by: Arne Schwabe Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1549 Message-Id: <20260302142045.5954-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 807.html Signed-off-by: Gert Doering --- M src/openvpn/pkcs11_mbedtls.c 1 file changed, 16 insertions(+), 0 deletions(-) diff --git a/src/openvpn/pkcs11_mbedtls.c b/src/openvpn/pkcs11_mbedtls.c index 66aefac..bf9d953 100644 --- a/src/openvpn/pkcs11_mbedtls.c +++ b/src/openvpn/pkcs11_mbedtls.c @@ -42,6 +42,16 @@ static bool pkcs11_get_x509_cert(pkcs11h_certificate_t pkcs11_cert, mbedtls_x509_crt *= cert) { + /* We set a maximum size for certificates so that the PKCS provider ca= nnot crash OpenVPN by + * making it try to allocate 2^64 bytes. The maximum of 100.000 bytes = is picked as a round + * number that easily accomodates the currently standardized quantum-s= afe signature algorithms. + * It is twice the size of a SLH-DSA (aka SPHINCS+) signature plus pub= lic key. + * + * However, there are additional digital signature schemes currently o= n the NIST on-ramp + * (e.g., some parameter settings for LESS) that have even larger publ= ic keys or signatures, so + * if those ever see use on smartcards, we will need to increase this = number. */ + const size_t max_cert_size =3D 100000; + unsigned char *cert_blob =3D NULL; size_t cert_blob_size =3D 0; bool ret =3D false; @@ -52,6 +62,12 @@ goto cleanup; } + if (cert_blob_size > max_cert_size) + { + msg(M_WARN, "PKCS#11: Certificate too large: %lu bytes, maximum is= %lu", cert_blob_size, max_cert_size); + goto cleanup; + } + check_malloc_return((cert_blob =3D calloc(1, cert_blob_size))); if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob, &ce= rt_blob_size) !=3D CKR_OK) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1549?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: I53d47e4a0d33c380ee95e0e33aecad3db3197940 Gerrit-Change-Number: 1549 Gerrit-PatchSet: 2 Gerrit-Owner: MaxF Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-CC: syzzer --gzyNTMJ48ec= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Avoid unbounded allocations in pkcs11_mbedtls.c<=
br>
The PKCS#11 provider can crash OpenVPN by making it try to allocate<= br>2^64 bytes for a certificate. To avoid this, set a maximum size for
c= ertificates. If the size is exceeded, don't try to allocate memory and<= br>instead exit pkcs11_get_x509_cert with an error.

The chosen maxim= um size is 100.000 bytes which is twice the size of
a SLH-DSA (aka SPHIN= CS+) signature.

Found-by: ZeroPath (https://zeropath.com/)
Report= ed-by: Joshua Rogers <contact@...2949...>
Github: closes OpenVPN/o= penvpn-private-issues#42

Change-Id: I53d47e4a0d33c380ee95e0e33aecad3= db3197940
Signed-off-by: Max Fillinger <maximilian.fillinger@...2920...= ..>
Acked-by: Arne Schwabe <arne-openvpn@...1227...>
Gerrit = URL: https://gerrit.openvpn.net/c/openvpn/+/1549
Message-Id: <2026030= 2142045.5954-1-gert@...1296...>
URL: https://www.mail-archive.com/ope= nvpn-devel@lists.sourceforge.net/msg35807.html
Signed-off-by: Gert Doeri= ng <gert@...1296...>
---
M src/openvpn/pkcs11_mbedtls.c
1 fi= le changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/openvpn/pkcs11_mbedtls.c b/src/openvpn/pkcs11_mbedtls.c=

index 66aefac..bf9d953 100644
--- a/src/op= envpn/pkcs11_mbedtls.c
+++ b/src/openvpn/pkcs11_mbedtls.c
@@ -42,6 +42,16 @@
static bool
pkcs11_get_x509_cert(pkcs11h_certificate_t pkcs11_cert, mbedtls_x509_c= rt *cert)

{
+ /* We set a maximum size for certificates so that the PKCS pro= vider cannot crash OpenVPN by
+ * making it try to allocate 2^64 bytes. The maximum of 100.0= 00 bytes is picked as a round
+ * number that easily accomodates the currently standardized = quantum-safe signature algorithms.
+ * It is twice the size of a SLH-DSA (aka SPHINCS+) sign= ature plus public key.
+ * How= ever, there are additional digital signature schemes currently on the NIST = on-ramp
+ * (e.g.= , some parameter settings for LESS) that have even larger public keys or si= gnatures, so
+ * = if those ever see use on smartcards, we will need to increase this number. = */
+ const size_t = max_cert_size =3D 100000;
+
unsigned char *cert_blob =3D NULL;
size_t cert_blob_size =3D 0;
bool ret =3D fal= se;
@@ -52,6 +62,12 @@
goto cleanu= p;
}

+ if (cert_blob_size > max_cert_size)+ {
+ msg(M_WARN, "PKCS#11: Certif= icate too large: %lu bytes, maximum is %lu", cert_blob_size, max_cert_= size);
+ goto = cleanup;
+ }
+
che= ck_malloc_return((cert_blob =3D calloc(1, cert_blob_size)));
if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob, &= amp;cert_blob_size) !=3D CKR_OK)

{

To view, visit change 1549. To unsubscribe, or for help writin= g mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I53d47e4a0d33c380ee95e0e33ae= cad3db3197940
Gerrit-Change-Number: 1549
Gerrit-PatchSet: 2
Gerrit-Owner: MaxF <max@...2606...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: cron2 <gert@...1296...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-CC: syzzer <steffan@...1856...> <= /div> = --gzyNTMJ48ec=--