Heap-use-after-free in `CanvasChild::SnapshotExternalCanvas` after WebGL command-buffer allocation failure
A raw pointer to a WebGL IPC actor was kept across a synchronous snapshot call that can flush WebGL and destroy that actor when command-buffer allocation fails, so the code then read the freed object. An attacker could trigger a content-process heap use-after-free, but only a fixed eight-byte read was confirmed, with no control over the value or any code execution.
- Fixed in 42 hours
- Paid in 16 days
- Disclosed after 42 hours
Created attachment 9621264 firefox-canvas-webglchild-uaf-report-bundle-concise-20260802.tar.gz
CanvasRenderingContext2D.drawImage(WebGLCanvas) can reach an accelerated
external-snapshot path that uses a raw WebGLChild actor after
SyncSnapshot() has destroyed it. Firefox ASan reports a content-process
heap-use-after-free.
The attached shim makes the fallible allocation fail deterministically. A
second run reaches the same UAF through a real memfd_create failure, but
only with a host-imposed low descriptor limit. I did not achieve a
normal-limit page-only trigger or a controlled memory primitive.
Environment
- Firefox Nightly ASan-opt 155.0a1
- Build ID:
20260731085738 - SourceStamp:
47f3b1d601409c7cd2c5dee876eaef22b18ae9d5 - OS: Fedora Linux 40 x86-64, kernel
6.14.5-100.fc40.x86_64 - Display: X11 through Xvfb
I found the issue by reviewing a raw actor lifetime across a synchronous WebGL flush, then validated it with ASan and the attached testcase.
Vulnerable source: https://searchfox.org/firefox-main/rev/fdd583cd5a10d051053acda8b760c3bd5d800034/gfx/layers/ipc/CanvasChild.cpp#822-864
Steps to reproduce
-
Extract the attached bundle and enter
canvas-webglchild-validation/. -
Build the included helper:
Bash bash build-injector.sh -
Run the faulted testcase against a Linux Firefox ASan build:
Bash FIREFOX_DIR=/path/to/firefox-asan bash run-validation.sh -
Confirm the output contains:
Text RAPTOR_FAULT_INJECT: ftruncate ENOMEM ... size=1339392 Failed to allocate internal command buffer. WebGL context was lost. ERROR: AddressSanitizer: heap-use-after-free SUMMARY: AddressSanitizer: heap-use-after-free ... IProtocol::Id -
Run the matched control:
Bash RAPTOR_CONTROL_RUN=1 RAPTOR_RUN_LABEL=control \ FIREFOX_DIR=/path/to/firefox-asan bash run-validation.sh
The control reaches after-draw contextLost=false without the fault marker
or ASan error. The control command returns status 1 because the runner's
success predicate is the presence of the UAF; inspect the log for the control
result.
The profile sets webgl.out-of-process.shmem-size=1337137; on this host it
page-aligns to 1339392 bytes. The shim fails exactly one ftruncate of that
size, selecting the production fallible command-buffer allocation without
changing Firefox lifetime logic.
The full faulted and control logs are attached under
canvas-webglchild-validation/.
ASan result
READ of size 8
#0 mozilla::ipc::IProtocol::Id ... ProtocolUtils.h:208
#1 mozilla::layers::CanvasChild::SnapshotExternalCanvas ... CanvasChild.cpp:861
freed by:
WebGLChild::Release
NotLostData::~NotLostData
ClientWebGLContext::Flush
CanvasChild::SnapshotExternalCanvas ... CanvasChild.cpp:851
Root cause
GetOptimizedSnapshot() obtains
ClientWebGLContext::SupportsSnapshotExternalCanvas() as a raw
IProtocol*. CanvasChild::SnapshotExternalCanvas() then calls
SyncSnapshot() before using that pointer.
For WebGL, SyncSnapshot() calls ClientWebGLContext::Flush().
Flush() requests command-buffer storage through
WebGLChild::AllocPendingCmdBytes(). If allocation fails,
OnContextLoss() synchronously clears mNotLost; when the local
NotLostData reference drops, it releases and destroys WebGLChild.
Vulnerable line 861 then calls aActor->Id() on the freed object.
Production allocation-failure confirmation
From the extracted bundle root, the following runner confirms the production allocation path without allocator interposition:
FIREFOX_DIR=/path/to/firefox-asan \
OOM_ESCALATION_NOFILE_LIMIT=256 \
bash oom-escalation/run-fd-reordered-nofile256.sh
The runner unsets LD_PRELOAD. With the host-imposed descriptor limit, 299
WebGL holder contexts make the target's normal memfd_create fail with
EMFILE; ASan then reports the same IProtocol::Id use-after-free.
The full trace and offline symbolization are attached under
oom-escalation/.
The corresponding run at the observed normal soft limit of 1024 is clean. The limit of 256 is a host condition, not a webpage-controlled primitive.
Test and proposed fix
native-test/canvas-webglchild-regression.patch is a six-file,
test-suite-ready patch. It:
- adds a default-off command-buffer allocation-failure test pref;
- adds a focused GPU mochitest for the exact
drawImage(WebGLCanvas)path; - captures actor identity before
SyncSnapshot(); - reacquires the actor afterward and falls back if it disappeared, changed, or cannot send; and
- performs that check before recording an external-snapshot wait.
The test verifies the expected WebGL context loss and then confirms that the
same Canvas2D context remains usable with a #112233 pixel readback.
Validation: full and incremental builds succeeded; the final focused test
passed 7/7 assertions with 0 failures and process exit 0; targeted format and
lint checks passed. Details are in native-test/VALIDATION.md.
Impact and limitations
The confirmed result is a content-process heap use-after-free: a fixed
eight-byte read from a freed WebGLChild/IProtocol, used as an IPC actor
ID. I have not demonstrated control over the read address or value, a memory
write, program-counter control, code execution, or a sandbox escape.
Normal-limit webpage attempts did not force the allocation failure. The non-interposed reproduction requires a host-imposed low descriptor limit and forced graphics routing under Xvfb.
The vulnerable path was introduced by Bug 1938053 for Firefox 140. Only the Nightly ASan build identified above was executed.
Attachment
Attach firefox-canvas-webglchild-uaf-report-bundle-concise-20260802.tar.gz.
The primary files inside are:
- deterministic testcase, runner, faulted ASan log, and clean control under
canvas-webglchild-validation/; - non-interposed fault/control logs under
oom-escalation/; and - source patch, test log, and validation receipt under
native-test/.
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 code held a raw actor pointer across SyncSnapshot(), which can synchronously flush WebGL, fail to allocate command-buffer storage, lose the context and destroy the WebGLChild before the pointer was used.
Impact
The confirmed result is a content-process heap use-after-free with a fixed eight-byte read; no memory write, code execution or sandbox escape was demonstrated, and normal-limit webpage attempts did not force the allocation failure.
What the attacker needed
Firefox Nightly ASan build; Linux host with Xvfb; Host-imposed low descriptor limit; Forced graphics routing
The fix
The proposed patch captures the actor identity before SyncSnapshot(), reacquires the actor afterwards and falls back if it disappeared, changed or cannot send, before recording an external-snapshot wait.
How it was found
- Extract the attached bundle and enter the validation directory.
- Build the included helper.
- Run the faulted testcase against a Linux Firefox ASan build.
- Confirm the output shows the injected allocation failure, context loss and ASan heap-use-after-free.
- Run the matched control and check it reaches the after-draw state without the fault marker or ASan error.
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.
Firefox splits its work into processes, and these talk to each other through small objects called actors. The code saved a reference to one actor, then called something that could delete it, and afterwards still used the saved reference, which is a use-after-free. The result was a crash-level memory error, not proven control of the program.
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.