Skip to content
Memory corruption Disclosed report Advanced CVE-2023-0215

UAF in OpenSSL up to 3.0.7

A use-after-free flaw in OpenSSL's BIO_new_NDEF function occurs when an error condition leaves a dangling pointer in the BIO chain. An attacker could trigger a crash by supplying invalid data, such as a malformed CMS recipient public key.

ogalland Follow

Originally disclosed on HackerOne

Bounty$2,400 Medium View original
  • Triaged in 17 hours
  • Fixed in 3 days
  • Paid in 3 days
  • Disclosed after 4 days

Summary by the program

Use-after-free following BIO_new_NDEF (CVE-2023-0215)

Severity: Moderate

The public API function BIO_new_NDEF is a helper function used for streaming ASN.1 data via a BIO. It is primarily used internally to OpenSSL to support the SMIME, CMS and PKCS7 streaming capabilities, but may also be called directly by end user applications.

The function receives a BIO from the caller, prepends a new BIO_f_asn1 filter BIO onto the front of it to form a BIO chain, and then returns the new head of the BIO chain to the caller. Under certain conditions, for example if a CMS recipient public key is invalid, the new filter BIO is freed and the function returns a NULL result indicating a failure. However, in this case, the BIO chain is not properly cleaned up and the BIO passed by the caller still retains internal pointers to the previously freed filter BIO. If the caller then goes on to call BIO_pop() on the BIO then a use-after-free will occur. This will most likely result in a crash.

This scenario occurs directly in the internal function B64_write_ASN1() which may cause BIO_new_NDEF() to be called and will subsequently call BIO_pop() on the BIO. This internal function is in turn called by the public API functions PEM_write_bio_ASN1_stream, PEM_write_bio_CMS_stream, PEM_write_bio_PKCS7_stream, SMIME_write_ASN1, SMIME_write_CMS and SMIME_write_PKCS7.

Other public API functions that may be impacted by this include i2d_ASN1_bio_stream, BIO_new_CMS, BIO_new_PKCS7, i2d_CMS_bio_stream and i2d_PKCS7_bio_stream.

The OpenSSL cms and smime command line applications are similarly affected.

OpenSSL 3.0, 1.1.1 and 1.0.2 are vulnerable to this issue.

OpenSSL 3.0 users should upgrade to OpenSSL 3.0.8. OpenSSL 1.1.1 users should upgrade to OpenSSL 1.1.1t. OpenSSL 1.0.2 users should upgrade to OpenSSL 1.0.2zg (premium support customers only).

This issue was reported on 29th November 2022 by Octavio Galland and Marcel Böhme (Max Planck Institute for Security and Privacy). The fix was developed by Viktor Dukhovni and Matt Caswell.

Full Security Advisory: https://www.openssl.org/news/secadv/20230207.txt

The original report as published on HackerOne, by ogalland. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the error path in BIO_new_NDEF frees the newly created filter BIO but fails to remove it from the caller's BIO chain, leaving a dangling pointer.

Impact

This will most likely result in a crash, and the issue affects OpenSSL 3.0, 1.1.1 and 1.0.2 as well as the cms and smime command line applications.

What the attacker needed

Invalid CMS recipient public key; caller invokes BIO_pop()

The fix

Users should upgrade to OpenSSL 3.0.8, 1.1.1t or 1.0.2zg to address the issue.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A use-after-free is a memory bug where a program frees an object but keeps a pointer to it, then later uses that pointer. Here, OpenSSL frees a filter object during an error but leaves a pointer to it in a chain, so a later cleanup step touches freed memory and likely crashes the program.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.