CVE-2024-0727: OpenSSL Denial of Service Vulnerability due to Malformed PKCS12 Files

Issue Summary

Processing a maliciously formatted PKCS12 file may lead OpenSSL to crash, resulting in a potential Denial of Service (DoS) attack. Applications that load files in the PKCS12 format from untrusted sources might terminate abruptly.

Background

A file in PKCS12 format can contain certificates and keys and may come from an untrusted source. The PKCS12 specification allows certain fields to be NULL, but OpenSSL does not correctly check for this case. This can lead to a NULL pointer dereference that results in OpenSSL crashing. If an application processes PKCS12 files from an untrusted source using the OpenSSL APIs, then that application will be vulnerable to this issue.

Here's a code snippet to demonstrate how vulnerable OpenSSL APIs can be exploited

#include <openssl/pkcs12.h>

int main() {
    PKCS12 *p12 = NULL;
    EVP_PKEY *pkey = NULL;
    X509 *cert = NULL;
    STACK_OF(X509) *ca = NULL;

    // Load malicious PKCS12 file
    // Perform proper error checking before proceeding
    FILE *fp = fopen("malicious.p12", "rb");
    p12 = d2i_PKCS12_fp(fp, NULL);
    fclose(fp);

    // Attempt to parse the malicious PKCS12 file
    // This will crash if the file is indeed malicious and the issue is not fixed
    PKCS12_parse(p12, "password", &pkey, &cert, &ca);

    // Cleanup
    PKCS12_free(p12);
    EVP_PKEY_free(pkey);
    X509_free(cert);
    sk_X509_pop_free(ca, X509_free);

    return ;
}

Solutions and Mitigations

It is strongly recommended that you apply the available patches. Ensure you are using the latest version of OpenSSL and testing against the updated libraries.

For more information on this CVE, check out the original references

- OpenSSL Advisory
- CVE Details

Extra Notes

A similar issue has been fixed in SMIME_write_PKCS7(). However, since this function is related to writing data and not processing it, the security impact is considered non-existent.

Additionally, the FIPS modules in OpenSSL versions 3.2, 3.1, and 3. are not affected by this issue. Therefore, FIPS-compliant applications are considered safe from this vulnerability.

Timeline

Published on: 01/26/2024 09:15:07 UTC
Last modified on: 02/08/2024 10:15:13 UTC