From patchwork Tue Dec 1 16:17:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5832 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp14953976lad; Tue, 1 Dec 2026 08:17:28 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGX+oGEh2AQFR1dDfv9b3CM8PZyYtgJHl0NdOX3Ed7LAXyDL6/f/yUtu/uKSSu+g0nUa+3mNJI6p+g=@openvpn.net X-Received: by 2002:a05:6808:23c3:b0:576:4595:9828 with SMTP id 5614622812f47-57a0ccdfdc0mr37024916b6e.59.1796141848368; Tue, 01 Dec 2026 08:17:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796141848; cv=none; d=google.com; s=arc-20260327; b=dyE7wDQflGXQoXqkhCjxkkrsSlUS40qT1GtjvE5oGM8Kr1q0CoUIg6Qn+1aV1tvs3l VcCqxGcpB6EXFMLBzd0dNF+VwljePVlRmSi+5X/St+rjeQz8FwSTPZJwUbexaKX6QsRF vbogfmZq6HXtlK05Nc9wWciiOcEhPxd5J9uW2FgpklNef4Rhwv6n/5dleH33SQnrCm1+ vl6SzP4oKB7GVSRi0vaI1AcTyJ9GuCE6fUNQF/cXmwmmGzPv8J2bfYmj4VLLBSwPQ8yI umCCPETq+r30hdBcO/MZVrNW5r3vw3Ihnteqr0mAt1lWgN+1KM6l7c3zW3J4nD5U1Atq gT3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=nkPsXDo45ekzXaNLP8xHkfokataPqXpF3Q1MiwbK/kQ=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=OG5VdLLe12EvhJNZnYD7wJzIV5IMzTq7LYfnqxRg6C7ccooTPHOaZIewKACADAhdIL L0Q0ZI0euhMq8qPbI+Z2G1ZU/u9j4hSlwA4QbpLmNZrjv9FYaBs+W+6TseEEpeWbRwF0 Oy0Dzd49woTtg8S0adHtUwWwi0NfQpsPOgNH1L6e801kqtGcUmg3vb+tJrmiKj7yPV7C 0I6azZz4wgb8EWeOqaQF0QJo+pi0xQ7avqk1Mx6ki1EFu5aWt4FRPKdfcjVPXf4oI86j Vxglx7CF07zJmBNLbFMoLqp+x4GCxzBqnz4hkM80BQy26oSvtXTXrDa6zFc8WJuUJ75Z oiMA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=jgKFt4E3; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RXHzRnrP; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=KhEbEO+7; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-4bc60a95d68si61495649fac.142.2026.12.01.08.17.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Dec 2026 08:17:28 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=jgKFt4E3; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RXHzRnrP; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=KhEbEO+7; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=nkPsXDo45ekzXaNLP8xHkfokataPqXpF3Q1MiwbK/kQ=; b=jgKFt4E32VULx3 Id4iNggj4TPI54w/6XVrbRzHhMxl8ft8eAXEBLkU60gOpSraJbuJTrOmWzq9Vcyjy4gprG25nL+mm dbHHbiVapOK+OrDqyJxQ74uMVDyQ8C6y/mqShLyW2Cy7Yiw+VuWYgZ4pfW9Z4A1Nn+YBLJrfnjrKq XwY=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xYQXl-000000002TU-2ugs; Tue, 01 Dec 2026 16:17:25 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xYQXj-000000002TF-28zm for openvpn-devel@lists.sourceforge.net; Tue, 01 Dec 2026 16:17:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=QX9rtQ6HtpEORVg5Mffm5RlfJL1p7GID18dykFWSnU4=; b=RXHzRnrPnE8gN4fYdqRKouv6Ur Ew7X1efNih57AO+6Jwb/6EcQQuET3mDQicIEu4RfCkyeW6ycTn4YQepmXtRIWXj+OO/MuYgI3oKfo +sTtpTDMQCSNTGmDx6/69AhWVwZ+kHGBLftyJ6S4uw183+U/dsz5iWE4UIcYIK2ah2EI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=QX9rtQ6HtpEORVg5Mffm5RlfJL1p7GID18dykFWSnU4=; b=KhEbEO+7BIB/nXJ4D0HvKpyl7M WillM2+GukXfdRT9khWu1L7Sg4AwafVA8Xg7RzjwzZfSxibD1+5gU5wCR+TlQhbRGpEChKrjsmT1r iGGoC4sQ+6MSYv59XkZvDJHa8dXGDgxWOazbuemH9vQkrZF5gAfPRypbNfTF9XuFRFME=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xYQXg-000000003va-17GX for openvpn-devel@lists.sourceforge.net; Tue, 01 Dec 2026 16:17:23 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6B1GHDvG009845 for ; Tue, 1 Dec 2026 17:17:13 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6B1GHDsP009844 for openvpn-devel@lists.sourceforge.net; Tue, 1 Dec 2026 17:17:13 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 1 Dec 2026 17:17:07 +0100 Message-ID: <20261201161712.9829-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Max Fillinger Arturs Parker and Jim Biniyaz, ResilientX Security, reported that OpenVPN with the Mbed TLS backend can be DoS'd by sending certificates with extremely large (8 KB) serial numbers, because the functio [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xYQXg-000000003va-17GX Subject: [Openvpn-devel] [PATCH v14] Reject certificates with too large serial numbers X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1883391234909613559 X-GMAIL-MSGID: 1883391234909613559 From: Max Fillinger Arturs Parker and Jim Biniyaz, ResilientX Security, reported that OpenVPN with the Mbed TLS backend can be DoS'd by sending certificates with extremely large (8 KB) serial numbers, because the functions for writing these serial numbers in decimal are inefficient. This could be fixed by checking the serial number size before printing, but we decided instead to check the certificates immediately (both in Mbed TLS and OpenSSL) and refuse them if their serial number is too large. This is because someone sending a certificate with an excessively long serial number is likely up to no good, and we would rather not wait to find out if they can also cause problems in other places. We use 40 bytes as the limit for serial numbers, which is twice the maximum allowed by RFC 5280. CVE: 2026-135412 Reported-by: Arturs Parker and Jim Biniyaz, ResilientX Security Github: OpenVPN/openvpn-private-issues/issues/187 Change-Id: I6c6dfed1557608d5b1442fb008bf84fa4f948579 Signed-off-by: Max Fillinger Acked-by: Steffan Karger Gerrit URL: https://gerrit.openvpn.net/c/openvpn-private/+/2325 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn-private/+/2325 This mail reflects revision 14 of this Change. Acked-by according to Gerrit (reflected above): Steffan Karger diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h index e77bc4a..39f39b0 100644 --- a/src/openvpn/ssl_verify.h +++ b/src/openvpn/ssl_verify.h @@ -53,6 +53,20 @@ /** Maximum length of common name */ #define TLS_USERNAME_LEN 64 +/** + * Maximum length for serial numbers. + * + * RFC 5280 says that conformant CAs must not issue certificates with serial + * numbers longer than 20 bytes. To be generous, we allow double that amount. + * + * Note that the OpenSSL and Mbed TLS backends calculate the serial size + * slightly differently, with Mbed TLS taking the length of the DER encoded + * number in the certificate, and OpenSSL the size of the bignum representation. + * For some numbers, there is a 1 byte difference in the sizes of these + * representations. + */ +#define MAX_SERIAL_SIZE 40 + /** Structure containing the hash for a single certificate */ struct cert_hash { diff --git a/src/openvpn/ssl_verify_mbedtls.c b/src/openvpn/ssl_verify_mbedtls.c index bba2f2f..3e0a4ea 100644 --- a/src/openvpn/ssl_verify_mbedtls.c +++ b/src/openvpn/ssl_verify_mbedtls.c @@ -43,6 +43,19 @@ #define MAX_SUBJECT_LENGTH 256 +/** + * Check the size of a certificate serial number. + * + * @param cert Certificate to check. + * + * @return True if the size of the serial number is acceptable. + */ +static bool +backend_x509_serial_size_ok(const mbedtls_x509_crt *cert) +{ + return cert->serial.len <= MAX_SERIAL_SIZE; +} + int verify_callback(void *session_obj, mbedtls_x509_crt *cert, int cert_depth, uint32_t *flags) { @@ -54,6 +67,14 @@ session->verified = false; + if (!backend_x509_serial_size_ok(cert)) + { + *flags |= MBEDTLS_X509_BADCERT_OTHER; + msg(D_TLS_ERRORS, "VERIFY ERROR: depth=%d, Certificate with excessively long serial, maximum is %d bytes.", + cert_depth, MAX_SERIAL_SIZE); + goto cleanup; + } + /* Remember certificate hash */ struct buffer cert_fingerprint = x509_get_sha256_fingerprint(cert, &gc); cert_hash_remember(session, cert_depth, &cert_fingerprint); @@ -112,6 +133,7 @@ *flags |= MBEDTLS_X509_BADCERT_OTHER; } +cleanup: gc_free(&gc); /* diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c index 731ab3e..ee29691 100644 --- a/src/openvpn/ssl_verify_openssl.c +++ b/src/openvpn/ssl_verify_openssl.c @@ -46,6 +46,28 @@ #include #include +/** + * Check the size of a certificate serial number. + * + * @param cert Certificate to check. + * + * @return True if the size of the serial number is acceptable. + */ +static bool +backend_x509_serial_size_ok(const X509 *cert) +{ + bool size_ok = false; + const ASN1_INTEGER *asn1_i = X509_get0_serialNumber(cert); + BIGNUM *bn_serial = ASN1_INTEGER_to_BN(asn1_i, NULL); + if (bn_serial != NULL) + { + int size = BN_num_bytes(bn_serial); + size_ok = size <= MAX_SERIAL_SIZE; + } + BN_free(bn_serial); + return size_ok; +} + int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) { @@ -61,6 +83,13 @@ ASSERT(session); X509 *current_cert = X509_STORE_CTX_get_current_cert(ctx); + if (!backend_x509_serial_size_ok(current_cert)) + { + msg(D_TLS_ERRORS, "VERIFY ERROR: depth=%d, Certificate with excessively long serial, maximum is %d bytes.", + X509_STORE_CTX_get_error_depth(ctx), MAX_SERIAL_SIZE); + goto cleanup; + } + struct buffer cert_hash = x509_get_sha256_fingerprint(current_cert, &gc); cert_hash_remember(session, X509_STORE_CTX_get_error_depth(ctx), &cert_hash);