Skip to content
Memory corruption Disclosed report Advanced CVE-2026-4725

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.

varde Follow

Originally disclosed on Mozilla

  • 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.

C++
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:

Text
f8345be3cabc1944760d536c4a43192a02000406
Sun Feb 15 23:53:08 2026 +0000

Attack Scenario

A compromised content process:

  1. Creates a PCanvas actor via CanvasManagerChild.
  2. Serializes 3 recorded events into shared memory:
    • CANVAS_DRAW_TARGET_CREATION (initializes translator draw target)
    • SETCURRENTDRAWTARGET (sets active draw target)
    • PAUSE_TRANSLATION (puts translator into Paused state)
  3. Calls SendInitTranslator to start GPU-side translation.
  4. Waits for the translator to reach Paused state (required by SetDataSurfaceBuffer).
  5. Creates a 4096-byte shared memory region (memfd with MFD_ALLOW_SEALING).
  6. 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.
  7. Calls SendSetDataSurfaceBuffer(1, sealed_handle).
  8. GPU process enters SetDataSurfaceBuffer:
    • mDataSurfaceShmems[1] inserts a new entry and takes a C++ reference.
    • Map() fails (EPERM due to F_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:

Text
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:

Bash
./mach mochitest dom/bindings/test/test_canvas_uaf.html

Expected result: ASan reports a heap-use-after-free in the GPU process.

The original report as published on Mozilla's Bugzilla, by varde. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

  1. Create a PCanvas actor from the content process.
  2. Send recorded events that create a draw target, set it current, and pause translation.
  3. Start GPU-side translation and wait for the paused state.
  4. Create a shared memory region and seal a clone of its handle against writes.
  5. Send the sealed handle as a data surface buffer.
  6. 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.

More by varde

View all

3 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.