Use-after-free in CanvasTranslator::SetDataSurfaceBuffer via dangling reference after map clear, reachable from content process through PCanvas
A reference to an entry in a map is kept while a failure path clears that same map, leaving the reference dangling and causing a use-after-free read and write. A compromised content process could trigger this in the GPU process by sending a sealed shared-memory handle that makes the mapping call fail.
- Fixed in 3 days
- Paid in 3 days
- Disclosed after 3 days
Created attachment 9545454 repro.patch
Root Cause
CanvasTranslator::SetDataSurfaceBuffer (gfx/layers/ipc/CanvasTranslator.cpp, line 420-430) takes a reference to an entry in std::map mDataSurfaceShmems, then on Map() failure clears the entire map via DataSurfaceBufferWillChange(0, false), and continues to use the now-dangling reference.
auto& dataSurfaceShmem = mDataSurfaceShmems[aId]; // line 420: ref
dataSurfaceShmem.mShmem = aBufferHandle.Map(); // line 421: fails
if (!dataSurfaceShmem.mShmem) {
DataSurfaceBufferWillChange(0, false); // line 424: clear()
dataSurfaceShmem.mShmem = aBufferHandle.Map(); // line 426: UAF write
if (!dataSurfaceShmem.mShmem) { // line 427: UAF read
return false;
}
}
DataSurfaceBufferWillChange(0, false) with aId=0 and aKeepAlive=false enters the else branch at line 339, iterates entries, and calls mDataSurfaceShmems.clear() (line 361).
This destroys the DataSurfaceShmem entry that dataSurfaceShmem still references. Lines 426-427 then operate on freed memory.
The move-assignment on line 426 invokes MappingBase::operator= which performs std::swap on freed mMemory and mSize members, causing both UAF read and UAF write.
Triggerability
A compromised content process can reliably trigger this by sending a MutableSharedMemoryHandle whose underlying memfd has been sealed with F_SEAL_WRITE.
The seal causes the GPU process's mmap(PROT_WRITE) to fail with EPERM, making Map() return a null mapping on both attempts while the reference-invalidation path is taken.
Tested on Firefox commit:
f8345be3cabc1944760d536c4a43192a02000406
Sun Feb 15 23:53:08 2026 +0000
Attack Scenario
A compromised content process:
- Creates a
PCanvasactor viaCanvasManagerChild. - Serializes 3 recorded events into shared memory:
CANVAS_DRAW_TARGET_CREATION(initializes translator draw target)SETCURRENTDRAWTARGET(sets active draw target)PAUSE_TRANSLATION(puts translator intoPausedstate)
- Calls
SendInitTranslatorto start GPU-side translation. - Waits for the translator to reach
Pausedstate (required bySetDataSurfaceBuffer). - Creates a 4096-byte shared memory region (memfd with
MFD_ALLOW_SEALING). - Clones the handle and seals the clone with
fcntl(F_ADD_SEALS, F_SEAL_WRITE). The seal applies to the underlying inode, so the original handle is also affected. - Calls
SendSetDataSurfaceBuffer(1, sealed_handle). - GPU process enters
SetDataSurfaceBuffer:mDataSurfaceShmems[1]inserts a new entry and takes a C++ reference.Map()fails (EPERMdue toF_SEAL_WRITE).DataSurfaceBufferWillChange(0, false)clears the map and frees the entry.- The dangling reference is used for a second
Map()attempt: UAF write + read.
Reproduction
Build Firefox with ASan:
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-debug
ac_add_options --enable-address-sanitizer
ac_add_options --disable-jemalloc
ac_add_options --disable-crashreporter
ac_add_options --disable-elf-hack
ac_add_options --disable-install-strip
ac_add_options --enable-debug
Apply the attached patch and rebuild, then run:
./mach mochitest dom/bindings/test/test_canvas_uaf.html
Expected result: ASan reports a heap-use-after-free in the GPU process.
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
The code holds a reference into a std::map and then calls a helper that clears the map on the error path, so the reference is invalidated before it is reused.
Impact
A compromised content process could cause a use-after-free read and write in the GPU process, which may lead to memory corruption or a crash.
What the attacker needed
Compromised content process; ability to create a PCanvas actor; sealed shared memory handle
How it was found
- Create a PCanvas actor from the content process.
- Send recorded events that create a draw target, set it current, and pause translation.
- Start GPU-side translation and wait for the paused state.
- Create a shared memory region and seal a clone of its handle against writes.
- Send the sealed handle as a data surface buffer.
- Observe the mapping failure, the map clear, and the use-after-free under ASan.
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 program here keeps a pointer to an item stored in a container, then empties the container, which destroys the item. The pointer now points at freed memory, and the code still reads and writes through it. A malicious page process could arrange for this to happen inside the more privileged graphics process.
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.