From patchwork Tue Nov 17 18:31:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5733 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:309f:b0:11b:d6c:f273 with SMTP id f31csp255laa; Tue, 17 Nov 2026 10:32:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHty4rnkxQfwJ2KLv6YQpx4gs6kUWOn4TVCzVgrsjnthlyYzCQ/xF6R8X75g2ZTji4hlEy7OY2oNbg=@openvpn.net X-Received: by 2002:a05:7301:2d33:b0:369:f17d:efb with SMTP id 5a478bee46e88-3810ea113e5mr3032196eec.10.1794940334528; Tue, 17 Nov 2026 10:32:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794940334; cv=none; d=google.com; s=arc-20260327; b=foeG+j3Bu8jeXuESXWzRfih8w7FytCsg+wbjQeRNkoDkWbpt+cxJSuhasp1Tep7yqK qhNxfHoxPKZOCeRozDorYbcGXoh/AQ5KovzPJaBOM5GG4O0oWghZEI4tk56NyEU61M9p jCnUAhylbqLw4iUJsmEJOScpjwON+Z8iD7IKXalL+jteJ3eE0+fpXQqqdBTVdyBzqV6r yO6ctwfNAKlSruuUI+sKiviXPo89Eu9b79mC2mxjhL3CQkQ2trrm4u0nOcySLc0I8B/U 5JMw/7Vv8pAeZsTnZdHqj3OhiU4OoxhpNlcxJT6oTC1wFigHiwA5ip1lSegP0JMsTKUb YIRA== 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=ETg2eK81ktyCoM8HQGBWAlgR2UcATI+3Eyblf6oMrYQ=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=k36NvjhLGphV6JypnvKrkAWYhyVRZqlrzcN+0nnRYEzqCb5LBNYTMxVW29eaXINbIs 1uH69Kj3L9PB6CkQpYZ0h5SuXMKjdjo18oqjMrQ2q85T5NgUhcc4aWzE3rxZKPIofBlP mgEZTfLOtOiWWm0+yyJUM+YxjhmmIkWXDZvbzJ/Z1WmQqCpy2JL4z8HjJXrvsXzWmg+s rVKtxwPFX9xPD22Vg1DHxJJLExIX3R5XLbRacQ8zSG9LbUtqTtQVD1pB2+jRH0AU+sqL 3B60eydSXm0FTnJEORXSlNp2wzc93guovstsqr5mf/mF9/4yy2ZhsumpbWJGaVzqzs6Y YJDA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=XUbNkwo8; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=hzRl9NL5; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=XqXTvqe2; 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 5a478bee46e88-379599bcc02si56885093eec.26.2026.11.17.10.32.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Nov 2026 10:32:14 -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=XUbNkwo8; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=hzRl9NL5; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=XqXTvqe2; 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=ETg2eK81ktyCoM8HQGBWAlgR2UcATI+3Eyblf6oMrYQ=; b=XUbNkwo8LzUAD8 AKmDRxIUtZqN/DIP+tfo2ODnAQMU2zDyR15bpKnK2eVSP9gxEhn79aTV/1VasPDBTNAM/IJaOi4+8 k7OR4PTy1ERzvLnAkXgA4IBXUH/Wu/BLac+iVvoMkjQTtvlUxEhgGb3Zekejb5vvwmC8nb8XoKnS9 T1w=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xTNyX-000000006yG-1Vwg; Tue, 17 Nov 2026 18:32:13 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xTNyV-000000006y8-2K82 for openvpn-devel@lists.sourceforge.net; Tue, 17 Nov 2026 18:32:11 +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=0OOcJow81alwc3FM1/c/3kBwvsj8LxZo8Rghyu+rOps=; b=hzRl9NL5P2Wa4v4qV6Nu4d5d+q d/G5sZxO7kZ3pPcxeCGMeRbrzxXMuwFu+Z2qZaPR8pxK376sl3G0jrZaBLJtA3Zfo0zKtsLjQ5vy8 UqSLmPL8Jt8dX44n3UHeyKUR8B1cd7Xfs8ZphRju+v6UjJA16Q9Vcjd0NpleqyWkyB74=; 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=0OOcJow81alwc3FM1/c/3kBwvsj8LxZo8Rghyu+rOps=; b=XqXTvqe2Z880BC6AYX39sblDmW 2n6kGCzZqU10poOcDlFpw9H8Oyo1jkyxhBeVuclCmw2lDUVGW4gUW/qLoUww/XzHomYkx8JcM2kVE VarlJbYHqsMPkexxBZCPUwL8cVad56J5Ymo8/wb7IGw+HVSKV6Ls1g+/biJ73+pvt8II=; 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 1xTNyU-000000001Sg-2DaY for openvpn-devel@lists.sourceforge.net; Tue, 17 Nov 2026 18:32:11 +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 6AHIW3dB018949 for ; Tue, 17 Nov 2026 19:32:03 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AHIW3jB018948 for openvpn-devel@lists.sourceforge.net; Tue, 17 Nov 2026 19:32:03 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 17 Nov 2026 19:31:57 +0100 Message-ID: <20261117183203.18936-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-2.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: Razvan Cojocaru 0a8e80aa ("Avoid unbounded allocations in pkcs11_mbedtls.c") capped the certificate blob size reported by the PKCS#11 provider only in the mbedTLS backend. pkcs11_management_id_get() still allocated w [...] 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: 1xTNyU-000000001Sg-2DaY Subject: [Openvpn-devel] [PATCH v3] pkcs11: bound certificate size in pkcs11_management_id_get() 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: 1882131356269802949 X-GMAIL-MSGID: 1882131356269802949 From: Razvan Cojocaru 0a8e80aa ("Avoid unbounded allocations in pkcs11_mbedtls.c") capped the certificate blob size reported by the PKCS#11 provider only in the mbedTLS backend. pkcs11_management_id_get() still allocated whatever size the provider returned. Move the limit to pkcs11_backend.h as PKCS11_MAX_CERT_SIZE and check it there too. Change-Id: Ia9f328b1c0ea29adf811a933d1fd22cb32e35e6d Signed-off-by: Razvan Cojocaru Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2121 --- 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/+/2121 This mail reflects revision 3 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/pkcs11.c b/src/openvpn/pkcs11.c index b4bed12..3610224 100644 --- a/src/openvpn/pkcs11.c +++ b/src/openvpn/pkcs11.c @@ -509,6 +509,13 @@ goto cleanup; } + if (certificate_blob_size > PKCS11_MAX_CERT_SIZE) + { + msg(M_WARN, "PKCS#11: Certificate too large: %zu bytes, maximum is %zu", + certificate_blob_size, PKCS11_MAX_CERT_SIZE); + goto cleanup; + } + if ((certificate_blob = (unsigned char *)malloc(certificate_blob_size)) == NULL) { msg(M_FATAL, "PKCS#11: Cannot allocate memory"); diff --git a/src/openvpn/pkcs11_backend.h b/src/openvpn/pkcs11_backend.h index b8b0eb0..972c3a2 100644 --- a/src/openvpn/pkcs11_backend.h +++ b/src/openvpn/pkcs11_backend.h @@ -37,6 +37,20 @@ #include +/* + * Maximum size of a certificate retrieved from a PKCS #11 provider, so that + * the provider cannot 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-safe signature algorithms. + * It is twice the size of a SLH-DSA (aka SPHINCS+) signature plus public key. + * + * However, 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 signatures, so if those ever see use on smartcards, we will + * need to increase this number. + */ +#define PKCS11_MAX_CERT_SIZE ((size_t)100000) + /** * Retrieve PKCS #11 Certificate's DN in a printable format. * diff --git a/src/openvpn/pkcs11_mbedtls.c b/src/openvpn/pkcs11_mbedtls.c index 2183217..3ee3837 100644 --- a/src/openvpn/pkcs11_mbedtls.c +++ b/src/openvpn/pkcs11_mbedtls.c @@ -42,16 +42,6 @@ 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 cannot 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-safe signature algorithms. - * It is twice the size of a SLH-DSA (aka SPHINCS+) signature plus public key. - * - * However, 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 signatures, so - * if those ever see use on smartcards, we will need to increase this number. */ - const size_t max_cert_size = 100000; - unsigned char *cert_blob = NULL; size_t cert_blob_size = 0; bool ret = false; @@ -62,9 +52,10 @@ goto cleanup; } - if (cert_blob_size > max_cert_size) + if (cert_blob_size > PKCS11_MAX_CERT_SIZE) { - msg(M_WARN, "PKCS#11: Certificate too large: %zu bytes, maximum is %zu", cert_blob_size, max_cert_size); + msg(M_WARN, "PKCS#11: Certificate too large: %zu bytes, maximum is %zu", cert_blob_size, + PKCS11_MAX_CERT_SIZE); goto cleanup; }