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

Heap use-after-free in `SharedRGBImage::GetAsSourceSurface()` during concurrent `MediaRecorder` conversion

A lazily cached image surface in Firefox's SharedRGBImage was stored in an unsynchronised reference pointer, so two MediaRecorder worker threads could read and replace it at the same time. A reader could then use a surface that had already been freed, giving a heap use-after-free during image conversion.

r00tdaddy Follow

Originally disclosed on Mozilla

  • Fixed in 3 days
  • Paid in 37 days
  • Disclosed after 3 days

Created attachment 9621403 mozilla-sharedrgb-poc-bundle.zip

Description

SharedRGBImage::GetAsSourceSurface() lazily caches a SourceSurface in an unsynchronized RefPtr. A page can load an alpha VP8 WebM, call captureStream(), and start multiple MediaRecorder instances on the same track. Separate WebrtcWorker task queues then call the getter concurrently on the same SharedRGBImage.

TSan naturally reports a race between the cache read at SharedRGBImage.cpp:115 and replacement at line 151. A debugger-assisted ASan run on an unmodified official build confirms an 8-byte heap use-after-free at offset zero of a freed 120-byte SourceSurfaceSkia in ImageConversion.cpp:185. The debugger only controlled thread scheduling. The stale operation is the virtual call surface->GetDataSurface(); heap replacement and instruction-pointer control were not demonstrated.

Builds tested

  • Audited source: 45135a4adb3c83c65c090e9c613775a5e193aba5
  • Official Linux TSan Nightly 155.0a1: BuildID 20260803160643, SourceStamp 4ad59735680077294c8f9c6dc5e0c3f74ee5693b
  • Official Linux ASan Nightly 155.0a1: BuildID 20260731085738, SourceStamp 47f3b1d601409c7cd2c5dee876eaef22b18ae9d5

The Linux sanitizer runs force in-content decoding by disabling the RDD, utility, and GPU decoder routes. Source analysis indicates the analogous route is used by default on Android for alpha VPX: MediaCodec rejects alpha video and falls back to VPXDecoder. I have not reproduced this on an unmodified stock Android build, and I am not claiming the default desktop RDD route is affected.

The historical container runs also used MOZ_DISABLE_CONTENT_SANDBOX=1 only because Firefox was nested inside an outer sandbox. The portable launchers do not set it. Both racing accesses occur on worker threads in one content process.

Of the attached preferences, media.rdd-process.enabled=false and media.rdd-vpx.enabled=false establish the relevant desktop topology; media.recorder.video.frame_drops=false increases stress. The remaining preferences are harness conveniences or defaults and are retained so the recorded run can be reproduced exactly.

Reproduction

Keep the attached files in one directory. The launchers also accept the HTML and WebM under a poc/ subdirectory. Set FIREFOX_BIN to an extracted official Mozilla TSan build and run:

Bash
export FIREFOX_BIN=/path/to/tsan/firefox
export LLVM_SYMBOLIZER=/path/to/tsan/llvm-symbolizer
bash mozilla-repro-tsan.sh

The attached run reported within seconds:

Text
WARNING: ThreadSanitizer: data race
  Read of size 8: SharedRGBImage::GetAsSourceSurface(), SharedRGBImage.cpp:115
  Previous write of size 8: SharedRGBImage::GetAsSourceSurface(), SharedRGBImage.cpp:151

For the ASan stress case:

Bash
export FIREFOX_BIN=/path/to/asan/firefox
bash mozilla-repro-asan.sh

The confirmed ASan run used GDB only to pause a reader after its raw cache load, let an already-running writer publish and release the old surface, and resume the reader. No source, binary, register, or heap value was changed. The attached GDB file is a post-crash thread/backtrace capture; the manual scheduling commands were not retained, so the ASan launcher should be treated as the stress input, not a deterministic replay of the exact UAF. A separate no-debugger run reached an invalid destroyed-surface mutex; I treat that only as corroboration. The TSan race reproduction requires no debugger.

ASan's decisive stacks are:

Text
USE:   ConvertToI420(), ImageConversion.cpp:185
FREE:  RefPtr assignment in SharedRGBImage::GetAsSourceSurface(), line 151
ALLOC: DrawTargetSkia::Snapshot(), called from SharedRGBImage.cpp:134

Root cause

  1. Two workers observe an empty cache and create surfaces S1 and S2.
  2. W1 publishes S1; after its caller reference drops, the cache owns the last reference.
  3. A reader loads the raw S1 pointer while copying the cache, before AddRef.
  4. W2 publishes S2; assignment releases and frees S1.
  5. The reader resumes with S1 and reaches surface->GetDataSurface().

Atomic object refcounting does not make the cache-pointer load and subsequent AddRef indivisible with replacement. The main-thread assertion at line 113 is debug-only and does not synchronize these production callers.

Suggested fix

Use the locked first-writer-wins cache pattern already used by PlanarYCbCrImage and NVImage: copy the cached strong reference while holding the mutex, construct a candidate outside the lock, publish only if the cache is still empty, and extract the cached reference under the lock during destruction. A regression test can use one alpha-WebM capture track and two or more independent recorders.

The original report as published on Mozilla's Bugzilla, by r00tdaddy. 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 cached SourceSurface reference was read and replaced without synchronisation, so the raw pointer load and the following AddRef were not atomic with respect to replacement and release.

Impact

The stale virtual call could crash the content process; heap replacement and instruction-pointer control were not demonstrated, and the default desktop RDD decoding route is not claimed to be affected.

What the attacker needed

Alpha VP8 WebM file; page calls captureStream(); two or more MediaRecorder instances; in-content decoding (RDD disabled)

The fix

The cache should use the locked first-writer-wins pattern already used by PlanarYCbCrImage and NVImage, copying and publishing the strong reference under the mutex.

How it was found

  1. Load an alpha VP8 WebM in a page and call captureStream() on it.
  2. Start two or more MediaRecorder instances on the same track.
  3. Worker task queues call GetAsSourceSurface() concurrently on the same image.
  4. One worker publishes a new surface and frees the old one while a reader still holds the stale pointer.
  5. The reader calls GetDataSurface() on the freed surface, triggering the use-after-free.

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.

When a page records video, Firefox converts frames between formats on background threads. This code kept a cached copy of a converted image in a shared slot without a lock, so one thread could free the old copy while another was still reading it. Using memory after it has been freed can crash the browser and, in principle, let an attacker run their own code, though that was not shown here.

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 r00tdaddy

View all

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