Inappropriate Implementation in Memory Allocator (CVE-2024-5839)
A reference-count overflow in Chromium's memory allocator (MiraclePtr) could be triggered from one thread while another thread freed the object, allowing a use-after-free. An attacker could then spray the heap and hijack control flow, as shown by a crash with a controlled instruction pointer.
- Fix shipped in 30 days
Steps to reproduce the problem
- git apply patch.diff
- copy uaf111.h and uaf111.cc to content/browser/permissions/
- compile asan build chromium and release build chromium.
- python ./copy_mojojs_bindings.py src/out/asan
- python -m SimpleHttpServer
For asan build chromium to reproduce: 6. rm -rf /tmp/abcd1234;out/asan/chrome --user-data-dir=/tmp/abcd1234 --enable-blink-features=MojoJS http://localhost:8000/TestUaf.html
Then you will see the asan log and the miracle ptr status is: protected. For release build version to reproduce: 6.rm -rf /tmp/abcd1234;out/asan/chrome --user-data-dir=/tmp/abcd1234 --enable-blink-features=MojoJS 7. Use gdb to attach the browser process. 8. Browse the TestUaf.html then you will see the crash log in gdb. The log shows the control flow has been hjacked to 0x4141414141414141.
Problem Description
In the Acquire function. It adds the refcounted of count_ in [1] and then check whether the refcounted overflow in [2]. However, Assume we have such a situation:
- We have a object and it's refcounted is equal to kPtrCountMask.
- The refcounted add in thread 1 and trigger the overflow.
- Since the check will not immediatly crash the other thread of the browser. (In my test, other thread will be shut down in nearly 180ms in my computer).
180ms is too long for computer. We can execute too many codes. Thus we can free the object in thread 2. Now the PtrCount is 0 because the overflow happend, so we can truely free the object. Then we can spray the heap and hjack the overflow in thread 2.
PA_ALWAYS_INLINE void Acquire() { CheckCookieIfSupported();
CountType old_count = count_.fetch_add(kPtrInc, std::memory_order_relaxed); --------------[1]
// Check overflow.
PA_CHECK((old_count & kPtrCountMask) != kPtrCountMask); -----------------[2]
}
Additional Comments
Note: The patch for in_slot_metadata.h is just to trigger Ptrcount overflow quickly. And I implement a mojo interface to test the MiraclePtr in the other patch.
Summary
MiraclePtr bypass due to PtrCount overflow
Custom Questions
Type of crash:
MiraclePtr Bypass
Crash state:
See attachments
Reporter credit:
MiraclePtr bypass bug
Additional Data
Category: Security
Chrome Channel: Stable
Regression: N/A
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 Acquire function increments the reference count and only checks for overflow after the increment, so a racing thread can observe a wrapped count and free the object while it is still referenced.
Impact
An attacker could cause a use-after-free and potentially hijack control flow, though the text notes the overflow check does not crash immediately and the other thread shuts down after roughly 180ms, giving a limited window.
What the attacker needed
Ability to run a crafted web page; MojoJS feature enabled; precise timing across threads
How it was found
- Apply the provided patch and add the test files to the permissions directory.
- Build both an ASan and a release version of Chromium.
- Copy the MojoJS bindings into the ASan build output and start a local web server.
- Launch the ASan build with MojoJS enabled and load the test page to see the ASan log.
- Launch the release build, attach a debugger to the browser process, and load the test page.
- Observe the crash log showing the control flow was hijacked to a controlled address.
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 track how many parts of the code are using an object, and free it when that number drops to zero. If that counter can be made to wrap around to zero while the object is still in use, the program frees it too early and later writes into memory that has been reused. Here the attacker does that and then fills the freed space with their own data to take over 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.