Use after free in GFX (CVE-2026-13805)
A use-after-free exists in the macOS browser process because the string width cache uses a comparator based on Skia typeface unique IDs that can change after a cache purge, corrupting the map and leaving dangling list iterators. An attacker could potentially exploit this by manipulating UI text to trigger cache purges and memory reallocation, leading to remote code execution.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 3 months
Project Fortify, an experimental security project, has identified the following potential security issue. If you're a feature owner CC-ed on this bug, please do your best to review these reports without the Chrome Security team.
Overview: A potential Use-After-Free vulnerability exists in the macOS browser process due to an unstable comparator in gfx::Canvas::StringWidthCache. The cache relies on Skia typeface unique IDs which can change after a Skia cache purge, corrupting the underlying std::map and leaving dangling std::list iterators. An attacker could potentially exploit this by manipulating UI text to trigger cache purges and memory reallocation, leading to remote code execution.
Affected files:
ui/gfx/platform_font_mac.mmui/gfx/platform_font.ccui/gfx/canvas.ccui/gfx/canvas.hbase/containers/lru_cache.h
Estimated timestamp from git blame: 2025-10-18
Mechanism
gfx::Canvas::StringWidthCache uses base::LRUCache, which internally pairs a std::map (for fast lookups) with a std::list (for MRU ordering).
The map's key comparator (StringWidthCacheKeyCompare) compares the string text, and if identical, falls back to PlatformFont::Compare. This function compares fonts using Skia's SkTypeface::uniqueID().
On macOS, PlatformFontMac does not cache the SkTypeface object locally. Instead, it relies on a global Skia cache (gTFCache) via SkMakeTypefaceFromCTFont. This Skia cache has a hard limit of 1024 entries and purges typefaces with a refcount of 1. Because the StringWidthCache keeps the PlatformFontMac object alive, but PlatformFontMac doesn't hold a strong reference to the SkTypeface, the Skia cache will eventually purge it.
When the same PlatformFontMac is queried again, Skia generates a new SkTypeface with a new, incremented uniqueID. This dynamically changes the key of items already sitting inside the std::map, completely breaking the map's strict-weak-ordering invariant.
The Use-After-Free
- When the
LRUCacheevicts an item, it callsindex_.erase(key)on the map andordering_.erase(pos)on the list. - Because the map's binary search tree is corrupted by the shifting IDs, the traversal might fail to find the node, causing
index_.eraseto silently return 0. - However,
ordering_.eraseblindly succeeds and frees thestd::listnode memory. The map now contains a danglingstd::list::iterator. - A subsequent cache
Get()operation can hit this dangling map entry.LRUCachewill then callordering_.splice()to move the freed node to the front of the MRU list. - In
libc++,std::list::spliceperforms an internal unlink operation (__f->__prev_->__next_ = ...). If an attacker reclaims the freed node memory, they control these pointers, yielding a powerful write-what-where memory corruption primitive. Since these are internal container pointers, they are not protected by MiraclePtr (raw_ptr).
Potential Attacker Steps
Note: Our tooling agent does not yet have the ability to run code, so these are suggested steps an attacker could follow to exploit this issue.
- Populate Cache: The attacker manipulates a web page to cause the browser UI (e.g., Tab title via
document.titleand Hover Card) to measure a short string (e.g.,u"A") using two different font sizes. Both enter the cache map. - Purge Skia Cache: The attacker rapidly changes
document.titleto a long string containing characters from over 1024 distinct Unicode scripts. The browser's text shaper forces 1024+ font fallbacks, overflowing Skia's cache and purging the original typefaces. - Invert IDs: The attacker triggers measurements again in a specific order so the new
uniqueIDs invert the original ordering of the map nodes. - Trigger Eviction: The attacker measures 32 new strings, forcing the
LRUCacheto evict its oldest node. The map fails to erase the node, but the list node is freed back to the heap. - Heap Grooming: The attacker uses IPC messages to spray the browser process heap, reclaiming the freed list node and forging the internal
__prev_and__next_pointers. - Trigger UAF: The attacker measures the original string again. The cache retrieves the dangling iterator and calls
splice(), executing the write-what-where primitive to achieve Remote Code Execution in the unsandboxed browser process.
Suggested Fix
The most robust fix is to modify PlatformFontMac to cache its sk_sp<SkTypeface> internally upon creation, exactly like PlatformFontSkia does. This guarantees that as long as the PlatformFontMac object is alive, its Skia typeface (and thus its uniqueID()) remains stable, preserving the std::map ordering invariant.
Alternatively, StringWidthCacheKeyCompare should be rewritten to compare stable metrics (like font size, weight, and font name) instead of relying on the volatile SkTypeface::uniqueID().
Evaluated with Chrome root at commit: 096fc8fdbfacf2546485756d03f160a3d04fcc9b
Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve accuracy over time. And please feel free to reach out to me directly if you have concerns or feedback on the project.
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 cache key comparator relies on Skia typeface unique IDs that are not stable because PlatformFontMac does not hold a strong reference to the SkTypeface, so a Skia cache purge changes the IDs and breaks the map's ordering invariant.
Impact
An attacker could potentially achieve remote code execution in the unsandboxed browser process, though the report notes the tooling agent could not run code and the steps are suggested.
What the attacker needed
MacOS browser process; attacker controls web page content; ability to trigger font fallbacks
The fix
The fix should make PlatformFontMac cache its SkTypeface internally so the unique ID stays stable, or change the comparator to use stable font metrics instead of the volatile unique ID.
How it was found
- Manipulate a web page to make the browser UI measure a short string with two different font sizes, populating the cache.
- Rapidly change the page title to a long string with characters from over 1024 distinct Unicode scripts to overflow Skia's cache and purge the original typefaces.
- Trigger measurements again in a specific order so the new unique IDs invert the original ordering of the map nodes.
- Measure 32 new strings to force the LRU cache to evict its oldest node, freeing the list node while the map still holds a dangling iterator.
- Use IPC messages to spray the browser process heap and reclaim the freed list node, forging internal pointers.
- Measure the original string again to trigger the use-after-free through splice, achieving the write-what-where primitive.
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 a pointer to memory after it has been freed, so an attacker can reuse that memory for their own data. Here, a cache that stores text measurements gets confused when font identifiers change, so it frees a list entry but leaves a stale reference in a map. If an attacker can control the freed memory, they might redirect the program's writes and 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.