# UAF in OpenSSL up to 3.0.7

BIO_new_NDEF frees its filter BIO on error but leaves dangling pointers in the caller's BIO chain, so a later BIO_pop() triggers use-after-free in OpenSSL CMS/SMIME streaming.

- Payout: $2,400
- Severity: medium
- Program: Internet Bug Bounty
- Found by (vendor credit): Octavio Galland (Max Planck Institute for Security and Privacy), Marcel Böhme (Max Planck Institute for Security and Privacy)
- Found by: ogalland
- Disclosed: 2023-03-18
- CVE: CVE-2023-0215
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1906897
- Library page: https://bugbountylibrary.com/r/h1%3A1906897
- Tags: area:oss domain:oss impact:dos kind:bounty platform:hackerone sev:medium tech:linux technique:source-review vuln:dos vuln:memory-corruption

**Target:** OpenSSL BIO_new_NDEF / ASN.1 streaming (CMS, SMIME, PKCS7)
**Root cause:** On failure (e.g. invalid CMS recipient public key) BIO_new_NDEF frees the newly prepended BIO_f_asn1 filter BIO but does not clean up the caller's BIO chain, leaving internal pointers to freed memory.
**Steps:**
1. Call BIO_new_NDEF with a caller-supplied BIO and an invalid CMS recipient public key so the filter BIO is freed and NULL is returned.
2. Observe the caller's BIO still holds internal pointers to the freed filter BIO.
3. Call BIO_pop() on the BIO (as B64_write_ASN1 does internally).
4. Use-after-free occurs, typically crashing the process.
**Exploitation:** Reachable via public APIs PEM_write_bio_ASN1_stream, PEM_write_bio_CMS_stream, PEM_write_bio_PKCS7_stream, SMIME_write_ASN1/CMS/PKCS7, and the openssl cms/smime CLI apps; trigger error path then BIO_pop to hit freed memory. Most likely outcome is a crash (DoS).
**Insight:** Error paths that free a newly-created wrapper object must also detach it from the caller-owned structure; audit BIO chain manipulation where a helper frees its own filter BIO but returns NULL, leaving dangling links that a later BIO_pop dereferences.

