Free on address which was not realloc()-ed in js::GetNativeStackBaseImpl after realloc failure at pthread_getattr_np
A crash occurs in Firefox's native stack base helper when the underlying pthread attribute call fails to allocate memory, leaving an internal pointer uninitialised, and a later destroy call frees that invalid address. An attacker able to trigger the allocation failure could cause a segmentation fault, though the reporter could not reproduce it reliably without a patched system library.
Originally disclosed on Mozilla
- Fixed in 16 days
- Paid in 17 days
- Disclosed after 16 days
Created attachment 9500304
log_minidump_00.txt
While fuzzing on Firefox Nightly 32-bit (Official Build) (BuildID=20250707093546) on Arch Linux (with original glibc), I found from minidump.txt it crash at `SIGSEGV / SEGV_ACCERR` during execution of `js::newContext` to `free`.
However, it still hard to reproduce the same, even after multiple tries.
After looking the code, the crash occurs at [NativeStack.cpp](https://searchfox.org/mozilla-central/source/js/src/util/NativeStack.cpp) in the function `js::GetNativeStackBaseImpl`:
'''cpp
void* js::GetNativeStackBaseImpl() {
pthread_getattr_np(thread, &sattr); // 1. realloc failure for &sattr inside pthread_getattr_np
...
...
pthread_attr_destroy(&sattr); // 2. free on address which was not realloc()-ed on &sattr
'''
To reliably reproduce this bug, we can use patched glibc to simulate the `realloc` failure inside `pthread_getattr_np(thread, &sattr)` to return `ENOMEM`, leaving the `&sattr` address not realloc()-ed, then on `pthread_attr_destroy` it free on `&sattr` address (which not realloc()-ed) which cause the crash.
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 return value of pthread_getattr_np is not checked, so when it fails with ENOMEM the attribute structure is left uninitialised and pthread_attr_destroy frees an address that was never allocated.
Impact
The browser could crash with a segmentation fault, but only when the underlying allocation fails, which the reporter found hard to trigger without a patched system library.
What the attacker needed
32-bit Firefox build; memory allocation failure occurs; patched glibc to force the failure
How it was found
- Run a 32-bit Firefox Nightly build on Arch Linux with the original glibc.
- Fuzz the browser until js::newContext is reached and the stack base helper runs.
- Observe a SIGSEGV with SEGV_ACCERR in the minidump.
- To reproduce deterministically, use a patched glibc that makes the attribute call return ENOMEM.
- Watch the destroy call free the unallocated address and crash.
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.
Some programs ask the operating system for information about the current thread's stack. To do that, a system library allocates a small block of memory and fills it in. If that allocation fails, the program still tries to clean up the block as if it existed, which crashes the browser.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.