Use-after-free on freebl3!SHA256_Update_Native at sha256-x86.c on OOM
On 32-bit Firefox, after exhausting memory, repeatedly creating RTCPeerConnection and Worker objects caused a use-after-free of the certificate data held by RTCCertificate. The freed memory was later read by SHA256_Update_Native, producing an access violation at a fill-pattern address.
Originally disclosed on Mozilla
- Fixed in 2 months
- Paid in 2 months
- Disclosed after 2 months
Created attachment 9326471 testcase1.html
On Firefox 32-bit after filling memory around 2700mb, then call new RTCPeerConnection() and new Worker the tab able to crash at ACCESS_VIOLATION_READ on SHA256_Update_Native at sha256-x86.c on address 0xe5e5e5e5, the address can be changed dynamically to e.g. 0xe5eff000, 0xe5f0000, 0xe6901000, and more.
The testcase is currently intermittent, it commonly crash at mozalloc_abort breakpoint rather than SHA256_Update_Native, I'll post update when I found more reliable testcase.
After spent some time debugging through WinDbg, on the stack PeerConnectionImpl::SetCertificate(mozilla::dom::RTCCertificate& aCertificate) the aCertificate->mCertificate sub-variable e.g. extensions, emailAddr, keyUsage, derCert, and more value is already set at 0xe5e5e5e5, then that mCertificate is passed to SHA256_Update_Native causing the ACCESS_VIOLATION_READ.
When looking at RTCCertificate.cpp code, it looks like the code is called from another thread, on the WebCryptoTask::Run() there are code comment "// Run heavy crypto operations on the thread pool, off the original thread.".
I then add printf to print address of mCertificate from RTCCertificate!SignCertificate and PeerConnectionImpl::SetCertificate to match the address, when calling simple function new RTCPeerConnection() both mCertificate address is match, but when visiting the testcase which do repeatedly in loop, the mCertificate address is out of sync, it looks like the RTCCertificate is generate too excessive mCertificate, then older mCertificate is freed, after that the PeerConnectionImpl::SetCertificate is still taking the old (freed) mCertificate address rather than fresh mCertificate which causing the use-after-free.
Tested on:
- Firefox 113.0a1 (2023-04-01) (32-bit)
- Firefox 111.0.1 (32-bit)
Steps to reproduce:
- Open Firefox 32-bit
- Visit attached testcase1.html on HTTPS site
- After a while the tabs is crashed
- Analyze the crash dump
If Firefox crash at EXCEPTION_BREAKPOINT, try again until it crashes at EXCEPTION_ACCESS_VIOLATION.
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 a race between certificate generation on a worker thread pool and PeerConnectionImpl::SetCertificate, so a stale, already-freed certificate pointer is used.
Impact
The tab could crash with an access violation; the report does not claim any further exploitation beyond the crash.
What the attacker needed
32-bit Firefox; memory filled to about 2700 MB; victim visits a crafted page
How it was found
- Open 32-bit Firefox.
- Visit the attached testcase on an HTTPS site.
- Wait until the tab crashes.
- Analyse the crash dump.
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.
When a program frees a block of memory, it should stop using it. Here the browser kept a pointer to certificate data that had already been released, and later read from it while hashing. That kind of mistake is called a use-after-free, and it can crash the browser or, in worse cases, let an attacker influence what the program reads.
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.