CVE-2022-4450: Double free after calling PEM_read_bio_ex
A double-free vulnerability was found in OpenSSL's PEMreadbioex function. The function PEMreadbioex() reads a PEM file from a BIO and parses and decodes the "name" (for example, "CERTIFICATE"), any header data, and the payload data. If the function succeeds, then the "nameout," "header," and "data" arguments are populated with pointers to buffers containing the relevant decoded data. The caller is responsible for freeing those buffers. Constructing a PEM file that results in 0 bytes of payload data is possible. In this case, PEMreadbioex() will return a failure code but will populate the header argument with a pointer to a freed buffer. A double-free will occur if the caller also frees this buffer. This will most likely lead to a crash. This could be exploited by an attacker who can supply malicious PEM files for parsing to achieve a denial of service attack.
Other sources
OpenSSL is vulnerable to a denial of service, caused by a double-free error related to the improper handling of specific PEM data by the PEMreadbioex() function. By sending specially crafted PEM files for parsing, a remote attacker could exploit this vulnerability to cause the system to crash.
— IBM
The function PEMreadbioex() reads a PEM file from a BIO and parses and decodes the "name" (e.g. "CERTIFICATE"), any header data and the payload data. If the function succeeds then the "nameout", "header" and "data" arguments are populated with pointers to buffers containing the relevant decoded data. The caller is responsible for freeing those buffers. It is possible to construct a PEM file that results in 0 bytes of payload data. In this case PEMreadbioex() will return a failure code but will populate the header argument with a pointer to a buffer that has already been freed. If the caller also frees this buffer then a double free will occur. This will most likely lead to a crash. This could be exploited by an attacker who has the ability to supply malicious PEM files for parsing to achieve a denial of service attack.
The functions PEMreadbio() and PEMread() are simple wrappers around PEMreadbioex() and therefore these functions are also directly affected.
These functions are also called indirectly by a number of other OpenSSL functions including PEMX509INFOreadbioex() and SSLCTXuseserverinfofile() which are also vulnerable. Some OpenSSL internal uses of these functions are not vulnerable because the caller does not free the header argument if PEMreadbioex() returns a failure code. These locations include the PEMreadbioTYPE() functions as well as the decoders introduced in OpenSSL 3.0.
— GitHub
The function PEMreadbioex() reads a PEM file from a BIO and parses and decodes the "name" (e.g. "CERTIFICATE"), any header data and the payload data. If the function succeeds then the "nameout", "header" and "data" arguments are populated with pointers to buffers containing the relevant decoded data. The caller is responsible for freeing those buffers. It is possible to construct a PEM file that results in 0 bytes of payload data. In this case PEMreadbioex() will return a failure code but will populate the header argument with a pointer to a buffer that has already been freed. If the caller also frees this buffer then a double free will occur. This will most likely lead to a crash. This could be exploited by an attacker who has the ability to supply malicious PEM files for parsing to achieve a denial of service attack.
The functions PEMreadbio() and PEMread() are simple wrappers around PEMreadbioex() and therefore these functions are also directly affected.
These functions are also called indirectly by a number of other OpenSSL functions including PEMX509INFOreadbioex() and SSLCTXuseserverinfofile() which are also vulnerable. Some OpenSSL internal uses of these functions are not vulnerable because the caller does not free the header argument if PEMreadbioex() returns a failure code. These locations include the PEMreadbioTYPE() functions as well as the decoders introduced in OpenSSL 3.0.
The OpenSSL asn1parse command line application is also impacted by this issue.
— NVD
Affected Software
Remediation
Event History
Parent advisories
This vulnerability appears in the following advisories.
Frequently Asked Questions
What is CVE-2022-4450?
CVE-2022-4450 is a double-free vulnerability found in OpenSSL's PEM_read_bio_ex function.
What is the severity of CVE-2022-4450?
CVE-2022-4450 has a severity level of high (7).
Which software is affected by CVE-2022-4450?
OpenSSL versions from 1.1.1 to 1.1.1t, OpenSSL versions from 3.0.0 to 3.0.8, Stormshield Network Security versions from 4.0.0 to 4.3.16, and Stormshield Network Security versions from 4.4.0 to 4.6.3 are affected.
How does CVE-2022-4450 impact OpenSSL?
CVE-2022-4450 allows an attacker to trigger a double-free vulnerability in OpenSSL's PEM_read_bio_ex function, potentially leading to arbitrary code execution.
Are there any references for CVE-2022-4450?
Yes, you can find references for CVE-2022-4450 at the following links: [1](https://bugzilla.redhat.com/show_bug.cgi/show_bug.cgi?id=2167906), [2](https://bugzilla.redhat.com/show_bug.cgi/show_bug.cgi?id=2167909), [3](https://bugzilla.redhat.com/show_bug.cgi/show_bug.cgi?id=2167907).