UAF in FontFaceSet::Load
A use-after-free in FontFaceSet::Load occurs because the method stores raw pointers to FontFace objects in an array, then calls FontFace::Load which can trigger a promise resolution that runs user-controlled JavaScript (via an overwritten then getter) and frees those FontFace objects. A subsequent iteration over the array then dereferences dangling pointers, leading to a crash and potentially arbitrary code execution.
Originally disclosed on Mozilla
- Fixed in 24 days
- Paid in 28 days
- Disclosed after 24 days
Created attachment 9487727 poc.zip
Root Cause Analysis
In FontFaceSet::Load, mImpl->FindMatchingFontFaces[1] stores pointers of FontFace in the non-refcounted array nsTArray<FontFace*> faces. This is fine as long as those FontFace instances are not freed in the remaining code of FontFaceSet::Load. Unfortunately, that's not the case here.
already_AddRefed<Promise> FontFaceSet::Load(JSContext* aCx,
const nsACString& aFont,
const nsAString& aText,
ErrorResult& aRv) {
FlushUserFontSet();
nsTArray<RefPtr<Promise>> promises;
nsTArray<FontFace*> faces;
mImpl->FindMatchingFontFaces(aFont, aText, faces, aRv); // [1]
if (aRv.Failed()) {
return nullptr;
}
for (FontFace* f : faces) {
RefPtr<Promise> promise = f->Load(aRv); // [2], call to FontFace::Load
if (aRv.Failed()) {
return nullptr;
}
if (!promises.AppendElement(promise, fallible)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
}
return Promise::All(aCx, promises, aRv);
}
In f->Load(aRv)[2], it calls EnsurePromise[3] and eventually calls mLoaded->MaybeResolve(this)[4] to setup resolution of this in a promise then callback. This is a variant of CVE-2024-9680 where user can intercept the setup procedure by overwriting the getter of FontFace.prototype.then and freeing the associated FontFace instances within the getter. Thus, after returning from the call to f->Load(aRv), the FontFace pointers saved in the faces array could now consist of dangling pointers, and next call to f->Load(aRv) will then trigger a Use-After-Free vulnerability.
Promise* FontFace::Load(ErrorResult& aRv) {
EnsurePromise(); // [3]
if (!mLoaded) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
mImpl->Load(aRv);
return mLoaded;
}
void FontFace::EnsurePromise() {
if (mLoaded || !mImpl || !GetOwnerGlobal()) {
return;
}
ErrorResult rv;
mLoaded = Promise::Create(GetOwnerGlobal(), rv);
if (mImpl->Status() == FontFaceLoadStatus::Loaded) {
mLoaded->MaybeResolve(this); // [4]
} else if (mLoadedRejection != NS_OK) {
mLoaded->MaybeReject(mLoadedRejection);
}
}
Exploitability
The attacker can exploit this by finding and using another structure to occupy the freed FontFace instance, causing type confusion when f->Load() is called. This could allow attacker to forge the data or even the virtual function table in the structure, resulting in arbitrary code execution in the worst case.
In poc.js we demonstrate a crash on access to 0x4141414141414141, which is caused by FontFaceImpl::Load trying to fetch the virtual function table address of its member.
void FontFaceImpl::Load(ErrorResult& aRv) {
mFontFaceSet->FlushUserFontSet(); // crashed here
...
}
We're unable to find a way to exploit this vulnerability without a address leak. However, a dedicated attacker could possibly find a suitable structure for address leak or direct leak address by another vulnerability to exploit this UAF.
Reproduction
- Unzip the attachment
- Run
python3 -m http.server 8000 - Visit
http://localhost:8000/poc.html
Environment
Tested on Firefox 138.0.3, Ubuntu 24.04 x86_64
Credit
LJP (@ljp_tw) and HexRabbit (@h3xr4bb1t) from DEVCORE Research Team
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 code stores non-refcounted raw pointers to FontFace objects in a local array, and a call to FontFace::Load can trigger user JavaScript that frees those objects, leaving dangling pointers.
Impact
The attacker could cause a crash and, with additional effort such as an address leak, potentially achieve arbitrary code execution.
What the attacker needed
Victim visits a malicious page; Firefox browser
How it was found
- Unzip the attachment
- Run a local HTTP server on port 8000
- Visit the proof-of-concept HTML page in Firefox
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 bug where a program keeps using a piece of memory after it has been freed. Here, the browser saves a list of font objects, then runs some JavaScript that can delete those objects, and afterwards it still tries to use them. This can crash the browser and, in the worst case, let an attacker run their own code.
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.