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

[macOS] AppleVTEncoder stale CVPixelBuffer pointer lets VideoToolbox read freed or reallocated canvas storage

Firefox's AppleVTEncoder hands CoreVideo a borrowed pointer into a temporary canvas mapping, then releases the mapping while VideoToolbox may still read it asynchronously. A page can mutate and resize a canvas so the old backing is freed or unmapped, causing VideoToolbox to read stale memory and crash the content process.

Hyeonjun Ahn Follow

Originally disclosed on Mozilla

  • Fixed in 19 days
  • Paid in 2 months
  • Disclosed after 19 days

Created attachment 9620788 worker-race.html

Summary

AppleVTEncoder gives CoreVideo a no-copy pixel pointer obtained from a temporary canvas-surface mapping. Firefox retains the mutable DataSourceSurface, but snapshot detachment can replace its backing image, so that reference no longer owns the allocation identified by CoreVideo's cached pointer. Page-controlled mutation and resizing can then free or unmap the old backing while VideoToolbox consumes the pointer asynchronously.

Root Cause Analysis

Source: 0e9cfbb4fca901314b1b18f871ae23d5adb16c0f

1. AppleVTEncoder gives CoreVideo a borrowed pixel address

For non-planar input, AppleVTEncoder::CreateCVPixelBuffer() obtains a DataSourceSurface, maps it, and passes the mapped address directly to CVPixelBufferCreateWithBytes():

C++
// firefox/dom/media/platforms/apple/AppleVTEncoder.cpp:1162-1189
RefPtr<gfx::SourceSurface> surface = aSource->GetAsSourceSurface();
if (!surface) {
  LOGE("Failed to get SourceSurface");
  return nullptr;
}

RefPtr<gfx::DataSourceSurface> dataSurface = surface->GetDataSurface();
if (!dataSurface) {
  LOGE("Failed to get DataSurface");
  return nullptr;
}

gfx::DataSourceSurface::ScopedMap map(dataSurface,
                                      gfx::DataSourceSurface::READ);
if (NS_WARN_IF(!map.IsMapped())) {
  LOGE("Failed to map DataSurface");
  return nullptr;
}

CVPixelBufferRef buffer = nullptr;
gfx::DataSourceSurface* dss = dataSurface.forget().take();
CVReturn rv = CVPixelBufferCreateWithBytes(
    kCFAllocatorDefault, dss->GetSize().Width(), dss->GetSize().Height(),
    pixelFormat, map.GetData(), map.GetStride(), ReleaseSurface, dss, nullptr,
    &buffer);
if (rv == kCVReturnSuccess) {
  return buffer;
}

CVPixelBufferCreateWithBytes() wraps caller-provided storage rather than copying the pixels into CoreVideo-owned memory. CoreVideo can therefore keep using the exact value returned by map.GetData() until it invokes the release callback.

2. The release callback retains the surface object, not the mapping

Firefox transfers one DataSourceSurface reference into the callback context:

C++
// firefox/dom/media/platforms/apple/AppleVTEncoder.cpp:1056-1059
static void ReleaseSurface(void* aReleaseRef, const void* aBaseAddress) {
  RefPtr<gfx::DataSourceSurface> released =
      dont_AddRef(static_cast<gfx::DataSourceSurface*>(aReleaseRef));
}

The callback merely releases that object. It does not retain or validate aBaseAddress, and it does not keep the ScopedMap alive. Keeping a mutable surface object alive is not equivalent to keeping the particular allocation or mapping represented by map.GetData() alive.

The map is a local variable. Returning from CreateCVPixelBuffer() destroys it and calls Unmap():

C++
// firefox/gfx/2d/2D.h:753-781
class ScopedMap final {
 public:
  ScopedMap(DataSourceSurface* aSurface, MapType aType)
      : mSurface(aSurface), mIsMapped(aSurface->Map(aType, &mMap)) {}

  ~ScopedMap() {
    if (mIsMapped) {
      mSurface->Unmap();
    }
  }
  ...
};

After this point, canvas code may detach or destroy the backing storage even though the CVPixelBuffer still caches its old address.

3. Canvas mutation can detach the snapshot from that address

The shared-memory crash PoC uses VideoFrame(OffscreenCanvas). That constructor obtains the canvas snapshot and wraps the same SourceSurface in SourceSurfaceImage:

C++
// firefox/dom/media/webcodecs/VideoFrame.cpp:1687-1708
SurfaceFromElementResult res = nsLayoutUtils::SurfaceFromOffscreenCanvas(
    &aOffscreenCanvas, nsLayoutUtils::SFE_WANT_FIRST_FRAME_IF_IMAGE);
if (res.mIsWriteOnly) {
  aRv.ThrowSecurityError("The canvas is not same-origin");
  return nullptr;
}

RefPtr<gfx::SourceSurface> surface = res.GetSourceSurface();
if (NS_WARN_IF(!surface)) {
  aRv.ThrowInvalidStateError("The canvas' surface acquisition failed");
  return nullptr;
}
...
RefPtr<layers::SourceSurfaceImage> image =
    new layers::SourceSurfaceImage(surface.get());
auto r = InitializeFrameWithResourceAndSize(global, aInit, image.forget());

The Basic-Skia reuse PoC deliberately uses createImageBitmap(HTMLCanvasElement) followed by VideoFrame(ImageBitmap). For a 2D canvas with no crop or transformation options, ImageBitmap creation passes the acquired canvas surface through without forcing a copy:

C++
// firefox/dom/canvas/ImageBitmap.cpp:1272-1299
RefPtr<SourceSurface> surface = GetSurfaceFromElement(
    aGlobal, aCanvasEl, &writeOnly, aOptions, &alphaType, aRv);
...
bool needToReportMemoryAllocation = false;
bool mustCopy = false;
...
return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions,
                                 writeOnly, needToReportMemoryAllocation,
                                 mustCopy, alphaType, aRv);

The VideoFrame(ImageBitmap) constructor then wraps the retained DataSourceSurface directly:

C++
// firefox/dom/media/webcodecs/VideoFrame.cpp:1727-1750
UniquePtr<ImageBitmapCloneData> data = aImageBitmap.ToCloneData();
if (!data || !data->mSurface) {
  aRv.ThrowInvalidStateError(
      "The ImageBitmap is closed or its surface acquisition failed");
  return nullptr;
}
...
RefPtr<layers::SourceSurfaceImage> image =
    new layers::SourceSurfaceImage(data->mSurface.get());
auto r = InitializeFrameWithResourceAndSize(global, aInit, image.forget());

For a raster Skia draw target, a snapshot may directly reference the draw target's existing pixels:

C++
// firefox/gfx/2d/DrawTargetSkia.cpp:400-416
RefPtr<SourceSurfaceSkia> snapshot = mSnapshot;
if (mSurface && !snapshot) {
  snapshot = new SourceSurfaceSkia();
  sk_sp<SkImage> image;
  SkPixmap pixmap;
  if (mSurface->peekPixels(&pixmap)) {
    image = SkImages::RasterFromPixmap(pixmap, nullptr, nullptr);
  } else {
    image = mSurface->makeImageSnapshot();
  }
  if (!snapshot->InitFromImage(image, aFormat, this)) {
    return nullptr;
  }
  mSnapshot = snapshot;
}

Before modifying the draw target, Firefox detaches externally retained snapshots:

C++
// firefox/gfx/2d/DrawTargetSkia.cpp:2236-2260
void DrawTargetSkia::DetachAllSnapshots() {
  MutexAutoLock lock(mSnapshotLock);
  if (mSnapshot) {
    if (mSnapshot->hasOneRef()) {
      mSnapshot = nullptr;
      return;
    }

    mSnapshot->DrawTargetWillChange();
    mSnapshot = nullptr;
    if (mSurface) {
      mSurface->notifyContentWillChange(
          SkSurface::kRetain_ContentChangeMode);
    }
  }
}

void DrawTargetSkia::MarkChanged() {
  DetachAllSnapshots();
  mIsClear = false;
}

DrawTargetWillChange() moves the retained SourceSurfaceSkia to a copied image and disconnects it from the original draw target:

C++
// firefox/gfx/2d/SourceSurfaceSkia.cpp:217-231
void SourceSurfaceSkia::DrawTargetWillChange() {
  MutexAutoLock lock(mChangeMutex);
  if (mDrawTarget.exchange(nullptr)) {
    SkPixmap pixmap;
    if (mImage->peekPixels(&pixmap)) {
      mImage = ReadSkImage(mImage, pixmap.info(), pixmap.rowBytes());
      if (!mImage) {
        gfxCriticalError() << "Failed copying Skia raster snapshot";
      }
    }
  }
}

The C++ surface object retained by ReleaseSurface() is still alive, but it now refers to the copied image. The raw address already stored in CoreVideo does not follow this replacement. Changing the canvas dimensions then drops the old buffer provider:

C++
// firefox/dom/canvas/CanvasRenderingContext2D.cpp:2129-2133,1337-1353
void CanvasRenderingContext2D::ClearTarget(int32_t aWidth, int32_t aHeight) {
  bool freeBuffer = aWidth != mWidth || aHeight != mHeight;
  ResetBitmap(freeBuffer);
  ...
}

void CanvasRenderingContext2D::ResetBitmap(bool aFreeBuffer) {
  ...
  bool forceReset = true;
  ReturnTarget(forceReset);
  mTarget = nullptr;
  if (aFreeBuffer) {
    mBufferProvider = nullptr;
  }
  ...
}

4. The submitted OffscreenCanvas trigger releases a Mach mapping

The tested OffscreenCanvas normally selects the shared canvas provider:

C++
// firefox/dom/canvas/CanvasRenderingContext2D.cpp:2007-2021
} else if (mOffscreenCanvas) {
  if (!StaticPrefs::gfx_offscreencanvas_shared_provider()) {
    return false;
  }
  ...
  aOutProvider = PersistentBufferProviderShared::Create(
      GetSize(), GetSurfaceFormat(), imageBridge,
      !mAllowAcceleration || UseSoftwareRendering(),
      mOffscreenCanvas->GetWindowID());
}

That provider allocates a shared-memory texture:

C++
// firefox/gfx/layers/BufferTexture.cpp:596-617
Maybe<uint32_t> bufSize =
    ImageDataSerializer::ComputeRGBBufferSize(aSize, aFormat);
...
mozilla::ipc::Shmem shm;
if (!aAllocator->AllocUnsafeShmem(bufSize.value(), &shm)) {
  return nullptr;
}
...
RefPtr shmemHolder =
    MakeRefPtr<ShmemTextureData::ShmemHolder>(aAllocator, shm);
return new ShmemTextureData(descriptor, aMoz2DBackend, shmemHolder, isClear);

On macOS, destroying that backing removes its virtual-memory mapping with vm_deallocate():

C++
// firefox/ipc/glue/SharedMemoryPlatform_mach.cpp:177-184
void Platform::Unmap(void* aMemory, size_t aSize) {
  vm_address_t vm_address = toVMAddress(aMemory);
  kern_return_t kr =
      vm_deallocate(mach_task_self(), vm_address, round_page(aSize));
  if (kr != KERN_SUCCESS) {
    LOG_ERROR("Failed to deallocate shared memory. %s (%x)\n",
              mach_error_string(kr), kr);
  }
}

Consequently, the natural crash from this particular PoC is most precisely a use-after-unmap of canvas shared memory. This also explains why ASan reports a read SEGV on unknown address rather than a canonical heap-use-after-free: the stale address is not an ASan-managed heap allocation, and the faulting load occurs inside Apple's uninstrumented vImage framework.

5. VideoToolbox consumes the pointer asynchronously

ProcessEncode() passes the CVPixelBuffer to VideoToolbox:

C++
// firefox/dom/media/platforms/apple/AppleVTEncoder.cpp:932-957
AutoCVBufferRef<CVImageBufferRef> buffer(
    CreateCVPixelBuffer(aSample->mImage));
if (!buffer) {
  LOGE("Failed to allocate buffer");
  mError =
      MediaResult(NS_ERROR_OUT_OF_MEMORY, "failed to allocate buffer"_ns);
  MaybeResolveOrRejectEncodePromise();
  return;
}

OSStatus status = VTCompressionSessionEncodeFrame(
    mSession, buffer,
    CMTimeMake(aSample->mTime.ToMicroseconds(), USECS_PER_S),
    CMTimeMake(aSample->mDuration.ToMicroseconds(), USECS_PER_S), frameProps,
    aSample->mKeyframe ? kForcedKeyframeRefcon : nullptr, &info);

The call can return while VideoToolbox still retains and converts the input. The page can then mutate and resize the originating canvas. That detaches the snapshot and destroys the old backing, but VideoToolbox still has its original base address. A later vImage conversion reads through that stale address.

The complete fault sequence is therefore:

  1. A page submits a canvas-backed VideoFrame to VideoEncoder.
  2. AppleVTEncoder wraps the mapped pixel address in a no-copy CVPixelBuffer.
  3. CreateCVPixelBuffer() returns and destroys the only ScopedMap.
  4. Page-controlled canvas mutation detaches the snapshot, and resizing drops the old backing provider.
  5. VideoToolbox asynchronously reads the address cached before that backing was destroyed.

Reproduction Steps

Host: macOS 26.5.1 (25F80), arm64 Source: 0e9cfbb4fca901314b1b18f871ae23d5adb16c0f Crash build: Firefox 155.0a1 ASan, BuildID 20260731225340

Build firefox with:

Text
mk_add_options MOZ_OBJDIR=/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser

ac_add_options --enable-project=browser
ac_add_options --enable-address-sanitizer
ac_add_options --disable-install-strip
ac_add_options --disable-jemalloc
ac_add_options --disable-crashreporter
ac_add_options --disable-profiling

# Keep stack use reasonable while retaining useful line information.
ac_add_options --enable-optimize="-O1"
ac_add_options --enable-debug-symbols=-gline-tables-only

# Optional but useful for GC-sensitive SpiderMonkey reproduction work.
ac_add_options --enable-gczeal

Serve repro.html:

Shell
python3 -m http.server 8000 --bind 127.0.0.1

Prepare profile:

Shell
profile_dir=$(mktemp -d /tmp/firefox-applevt-unpatched.XXXXXX)

"$profile_dir/user.js":

user_pref("browser.shell.checkDefaultBrowser", false);
user_pref("browser.startup.firstrunSkipsHomepage", true);
user_pref("browser.startup.homepage_override.mstone", "ignore");
user_pref("datareporting.policy.dataSubmissionEnabled", false);
user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);
user_pref("media.use-remote-encoder.video", false);

Execute:

Shell
repro_dir=/Users/deayzl/firefox-bug-bounty/findings/2026-07-30-applevtencoder-offscreen-snapshot-uaf-read
firefox_bin=/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/firefox
profile_dir="$(mktemp -d /tmp/firefox-applevt-unpatched.XXXXXX)"

cp "$repro_dir/user.js" "$profile_dir/user.js"

ASAN_OPTIONS='detect_leaks=0:abort_on_error=1:halt_on_error=1:symbolize=1' \
"$firefox_bin" \
  --no-remote \
  --profile "$profile_dir" \
  'http://127.0.0.1:8000/worker-race.html?workers=8&frames=2000' \
  2>&1 | tee asan.log

Result:

LOG
2026-08-01 12:59:48.638 Nightly GPU Helper[60996:38789468] Failure on line 688 in function id scheduleApplicationNotification(LSNotificationCode, NSWorkspaceNotificationCenter *): noErr == _LSModifyNotification(notificationID, 1, &code, 0, NULL, NULL, NULL)
2026-08-01 12:59:48.744 Nightly GPU Helper[60996:38789468] Error received in message reply handler: Connection invalid
2026-08-01 12:59:48.744 Nightly GPU Helper[60996:38789500] Connection Invalid error for service com.apple.hiservices-xpcservice.
UNSUPPORTED (log once): POSSIBLE ISSUE: unit 1 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable
console.error: (new TypeError("can't access property \"find\", this._searchProviderInfo is null", "moz-src:///browser/components/search/SearchSERPTelemetry.sys.mjs", 1209))
AddressSanitizer:DEADLYSIGNAL
=================================================================
==61018==ERROR: AddressSanitizer: SEGV on unknown address 0x0001223e0000 (pc 0x000193b22b3c bp 0x000171941a90 sp 0x000171941800 T40)
==61018==The signal is caused by a READ memory access.
==61018==WARNING: failed to spawn external symbolizer (errno: 9)
==61018==WARNING: failed to spawn external symbolizer (errno: 9)
==61018==WARNING: failed to spawn external symbolizer (errno: 9)
==61018==WARNING: failed to spawn external symbolizer (errno: 9)
==61018==WARNING: failed to spawn external symbolizer (errno: 9)
==61018==WARNING: Failed to use and restart external symbolizer!
    #0 0x000193b22b3c in vConvert_ARGB8888To420Yp8_CbCr8_vec+0x2ac (/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage:arm64+0x297b3c)
    #1 0x00019bc45ee0 in VTPixelTransferSessionCanUseMetalInTheBackground+0x20944 (/System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox:arm64+0x4eee0)
    #2 0x00019c0d1e50 in VTPixelTransferSessionFlush+0x3b0 (/System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox:arm64+0x4dae50)
    #3 0x00019c0c8220 in VTParavirtualizedJPEGSessionGetTypeID+0x7fc (/System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox:arm64+0x4d1220)
    #4 0x00019bc451b0 in VTPixelTransferSessionCanUseMetalInTheBackground+0x1fc14 (/System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox:arm64+0x4e1b0)
    #5 0x00019bbf9344 in VTPixelTransferSessionTransferImage+0x1d0 (/System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox:arm64+0x2344)
    ...
    #12 0x000189a1c740 in _dispatch_worker_thread+0x108 (/usr/lib/system/libdispatch.dylib:arm64+0x13740)
    #13 0x0001036080fc in asan_thread_start(void*)+0x48 (/Users/deayzl/.mozbuild/clang/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:arm64+0x500fc)
    #14 0x000189bc5c54 in _pthread_start+0x84 (/usr/lib/system/libsystem_pthread.dylib:arm64+0x6c54)
    #15 0x000189bc0c18 in thread_start+0x4 (/usr/lib/system/libsystem_pthread.dylib:arm64+0x1c18)

==61018==Register values:
 x[0] = 0x000000011d2f8200   x[1] = 0x0000000000000280   x[2] = 0x000000011d2f8480   x[3] = 0x000000011d2f8200  
 x[4] = 0x0000000000000280   x[5] = 0x00000001223e0000   x[6] = 0x00000000000000ff   x[7] = 0x0000000000000000  
 x[8] = 0x0000000000000000   x[9] = 0x00000000000001e0  x[10] = 0x0000000000000000  x[11] = 0x00000001223e0a00  
x[12] = 0x000000011d2f8480  x[13] = 0x0000000000000a00  x[14] = 0x0000000000000280  x[15] = 0x00000000ffffccef  
x[16] = 0x0000000000000005  x[17] = 0x00000001223e0000  x[18] = 0x0000000000000000  x[19] = 0x00000000000007f0  
x[20] = 0x0000000000004000  x[21] = 0x00000001223e0a00  x[22] = 0x00000000ffffccef  x[23] = 0x000000011d343200  
x[24] = 0x0000000000000280  x[25] = 0x000000011d343200  x[26] = 0x0000000000000080  x[27] = 0x00000000fffff31e  
x[28] = 0x000000011d2f8200     fp = 0x0000000171941a90     lr = 0x0000000000000a00     sp = 0x0000000171941800  
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage:arm64+0x297b3c) in vConvert_ARGB8888To420Yp8_CbCr8_vec+0x2ac
Thread T40 created by T35 here:
    #0 0x000103602e70 in pthread_create+0x58 (/Users/deayzl/.mozbuild/clang/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:arm64+0x4ae70)
    #1 0x000189a186d0 in _dispatch_root_queue_poke_slow+0x21c (/usr/lib/system/libdispatch.dylib:arm64+0xf6d0)
    #2 0x000189a1c8e0 in _dispatch_root_queue_drain+0xc8 (/usr/lib/system/libdispatch.dylib:arm64+0x138e0)
    #3 0x000189a1c740 in _dispatch_worker_thread+0x108 (/usr/lib/system/libdispatch.dylib:arm64+0x13740)
    #4 0x0001036080fc in asan_thread_start(void*)+0x48 (/Users/deayzl/.mozbuild/clang/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:arm64+0x500fc)
    #5 0x000189bc5c54 in _pthread_start+0x84 (/usr/lib/system/libsystem_pthread.dylib:arm64+0x6c54)
    #6 0x000189bc0c18 in thread_start+0x4 (/usr/lib/system/libsystem_pthread.dylib:arm64+0x1c18)

Thread T35 created by T31 here:
    #0 0x000103602e70 in pthread_create+0x58 (/Users/deayzl/.mozbuild/clang/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:arm64+0x4ae70)
    #1 0x000189a186d0 in _dispatch_root_queue_poke_slow+0x21c (/usr/lib/system/libdispatch.dylib:arm64+0xf6d0)
    #2 0x00018989e3c4 in _xpc_connection_init+0x2c0 (/usr/lib/system/libxpc.dylib:arm64+0xb3c4)
    #3 0x00018989e034 in _xpc_connection_activate_if_needed+0x21c (/usr/lib/system/libxpc.dylib:arm64+0xb034)
    #4 0x0001898a087c in xpc_connection_resume+0x64 (/usr/lib/system/libxpc.dylib:arm64+0xd87c)
    ...
    #19 0x000125706004 in mozilla::ipc::MessagePumpForNonMainThreads::Run(base::MessagePump::Delegate*)+0x184 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0x2302004)
    #20 0x00012560e728 in MessageLoop::Run()+0x168 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0x220a728)
    #21 0x0001254f3e68 in nsThread::ThreadFunc(void*)+0x2a8 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0x20efe68)
    #22 0x0001030efc90 in _pt_root+0x384 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/libnss3.dylib:arm64+0x3e7c90)
    #23 0x0001036080fc in asan_thread_start(void*)+0x48 (/Users/deayzl/.mozbuild/clang/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:arm64+0x500fc)
    #24 0x000189bc5c54 in _pthread_start+0x84 (/usr/lib/system/libsystem_pthread.dylib:arm64+0x6c54)
    #25 0x000189bc0c18 in thread_start+0x4 (/usr/lib/system/libsystem_pthread.dylib:arm64+0x1c18)

Thread T31 created by T0 here:
    #0 0x000103602e70 in pthread_create+0x58 (/Users/deayzl/.mozbuild/clang/lib/clang/21/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:arm64+0x4ae70)
    #1 0x0001030e1ed4 in _PR_CreateThread+0x43c (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/libnss3.dylib:arm64+0x3d9ed4)
    #2 0x0001254f6470 in nsThread::Init(nsTSubstring<char> const&)+0x1c4 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0x20f2470)
    #3 0x00012d595214 in mozilla::dom::WorkerThread::Create(mozilla::dom::WorkerThreadFriendKey const&)+0xdc (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0xa191214)
    #4 0x00012d5015b4 in mozilla::dom::workerinternals::RuntimeService::ScheduleWorker(mozilla::dom::WorkerPrivate&)+0xd4 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0xa0fd5b4)
    ...
    #37 0x0001301560c0 in XRE_RunAppShell()+0x21c (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0xcd520c0)
    #38 0x00012560e728 in MessageLoop::Run()+0x168 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0x220a728)
    #39 0x000130153538 in XRE_InitChildProcess(int, char**, XREChildData const*)+0x1120 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/XUL:arm64+0xcd4f538)
    #40 0x0001021a8abc in main+0x164 (/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/plugin-container.app/Contents/MacOS/plugin-container:arm64+0x100000abc)
    #41 0x000189807dfc in start+0x1b4c (/usr/lib/dyld:arm64+0xbdfc)

==61018==ABORTING
[Parent 60987, IPC I/O Parent] WARNING: process 61018 exited on signal 6: file firefox/ipc/chromium/src/chrome/common/process_watcher_posix_sigchld.cc:161

Basic-Skia heap reuse: unsubmitted replacement pixels are encoded

On the tested macOS configuration, an inert-document HTMLCanvasElement requested with willReadFrequently: true follows the Basic-Skia heap-raster path. Each frame submitted to VideoEncoder is a 128-by-128 solid-blue snapshot. After the encoder dequeues a frame, the page writes one green pixel to detach that snapshot, resizes the source canvas to release the old raster, and allocates same-sized solid-red canvases. The red canvases are retained as replacement objects but are never passed to VideoEncoder.

Locally built ASan Firefox

Source revision: 0e9cfbb4fca901314b1b18f871ae23d5adb16c0f

Serve the PoC from one terminal:

Shell
repro_dir=/Users/deayzl/firefox-bug-bounty/audit-work/applevt-page-only-heap-oracle
cd "$repro_dir"
python3 -m http.server 8000 --bind 127.0.0.1

user.js:

JavaScript
user_pref("browser.shell.checkDefaultBrowser", false);
user_pref("browser.startup.firstrunSkipsHomepage", true);
user_pref("browser.startup.homepage_override.mstone", "ignore");
user_pref("datareporting.policy.dataSubmissionEnabled", false);
user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);

// The available ASan build is Nightly. Match the unmodified Release/Beta
// default so AppleVTEncoder receives the canvas surface in the content
// process rather than an IPC copy.
user_pref("media.use-remote-encoder.video", false);

Then launch the locally built Firefox from another terminal:

Shell
repro_dir=/Users/deayzl/firefox-bug-bounty/audit-work/applevt-page-only-heap-oracle
built_firefox=/Users/deayzl/firefox-bug-bounty/obj-aarch64-apple-darwin-asan-browser/dist/Nightly.app/Contents/MacOS/firefox
profile_dir=$(mktemp -d /tmp/firefox-applevt-built.XXXXXX)
cp "$repro_dir/user.js" "$profile_dir/user.js"

ASAN_OPTIONS='detect_leaks=0:abort_on_error=1:halt_on_error=1:quarantine_size_mb=0:thread_local_quarantine_size_kb=0' \
"$built_firefox" \
  --no-remote \
  --profile "$profile_dir" \
  'http://127.0.0.1:8000/fresh-basic-skia-repro.html?frames=2200&workers=10&replacements=2&phases=400&stepUs=5&retire=1'

Result:

LOG
Fresh Basic-Skia stale-read reproduction
FRESH-CROSS-ALLOCATION-READ

670.000 SETTINGS {"frames":2200,"workers":10,"replacements":2,"phases":400,"stepUs":5,"retire":true}
1278.000 WARMUP-COMPLETE
1459.000 PROGRESS 250 retired 48 decoded 23 bestScore 0.0
1603.000 PROGRESS 500 retired 84 decoded 47 bestScore 0.0
1669.000 PROGRESS 750 retired 87 decoded 48 bestScore 0.0
1760.000 PROGRESS 1000 retired 101 decoded 51 bestScore 0.0
1795.000 PROGRESS 1250 retired 107 decoded 52 bestScore 0.0
1812.000 PROGRESS 1500 retired 109 decoded 52 bestScore 0.0
1980.000 PROGRESS 1750 retired 147 decoded 72 bestScore 0.0
2177.000 PROGRESS 2000 retired 205 decoded 114 bestScore 0.0
7561.000 RESULT {"crossAllocationRead":true,"settings":{"frames":2200,"workers":10,"replacements":2,"phases":400,"stepUs":5,"retire":true},"submitted":2200,"retired":1220,"outputs":1219,"decoded":633,"blueFrames":630,"redFrames":1,"anomalies":3,"dequeueEvents":1220,"best":{"timestamp":21033123,"average":[255,1,3],"samples":[[255,1,3],[255,1,3],[255,1,3],[255,1,3],[255,1,3]],"stride":512}}

All submitted frames were blue, while red existed only in separate replacement canvases that were never encoded.
The decoded red frame therefore shows that VideoToolbox read a replacement allocation through the stale CVPixelBuffer pointer.
Disabling ASan quarantine only makes same-size address reuse easier; the reallocated range is unpoisoned, so no ASan report is expected.
With default quarantine, uniform 0xe5 pixels matching Firefox's free-fill provide corroborating evidence of a read from retired storage.

The original report as published on Mozilla's Bugzilla, by Hyeonjun Ahn. 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

Likely the release callback retains the DataSourceSurface object but not the ScopedMap, so the mapped address given to CVPixelBufferCreateWithBytes can outlive the mapping once canvas mutation detaches the snapshot and resizing drops the backing provider.

Impact

A page could cause a use-after-unmap read inside VideoToolbox, crashing the content process; the report does not claim code execution, and the crash is a read fault rather than a confirmed heap-use-after-free.

What the attacker needed

MacOS with VideoToolbox; page runs JavaScript in Firefox; canvas-backed VideoFrame encoding

How it was found

  1. A page submits a canvas-backed VideoFrame to VideoEncoder.
  2. AppleVTEncoder wraps the mapped pixel address in a no-copy CVPixelBuffer.
  3. CreateCVPixelBuffer() returns and destroys the only ScopedMap.
  4. Page-controlled canvas mutation detaches the snapshot, and resizing drops the old backing provider.
  5. VideoToolbox asynchronously reads the address cached before that backing was destroyed.

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 Firefox sends a canvas image to the macOS video encoder, it passes along a raw memory address instead of a copy. The temporary mapping that address came from is torn down straight away, but the encoder keeps using the address later in the background. If the page changes and resizes the canvas in between, that memory is freed or unmapped, so the encoder reads memory that no longer belongs to it, which crashes the browser.

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 Hyeonjun Ahn

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.