-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The function was named in the plural and cleared one of three\n\nPre-patch, the function lived in `src/dawn/wire/server/Server.cpp`:\n\n```cpp\nvoid Server::ClearDeviceCallbacks(WGPUDevice device) {\n // Un-set the logging callback since we cannot forward them\n // after the server has been destroyed.\n mProcs->deviceSetLoggingCallback(device, kEmptyLoggingCallbackInfo);\n}\n```\n\nIt had two callsites. The first, in the `Server` destructor:\n\n```cpp\n// Un-set the error and lost callbacks since we cannot forward them\n// after the server has been destroyed.\nClearDeviceCallbacks(device);\n```\n\nThe second, in the `DoDestroyObject` specialization for `WGPUDevice` in `ServerDoers.cpp`:\n\n```cpp\n//* Deregisters uncaptured error and device lost callbacks since\n//* they should not be forwarded if the device no longer exists on the wire.\nClearDeviceCallbacks(data.handle);\n```\n\nThe 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.\n\n## The two callbacks that were never cleared\n\nIn Dawn's wire server, every WGPU device handle on the wire has an `ObjectData` entry in the server's known-objects table. That struct holds:\n\n```cpp\ntemplate <>\nstruct ObjectData : public ObjectDataBase {\n std::unique_ptr info;\n};\n```\n\n`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.\n\nWhen 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` 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.\n\n`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.\n\n## The PoC, post-renderer-compromise\n\nThe 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](https://github.com/anansi2safe/CVE-2026-5281) ships a renderer-side patch into the wire client's `QueueWriteBuffer` stub:\n\n```cpp\n// inside the QueueWriteBuffer wire stub on the client\nif (bufferOffset == 0x414141) {\n self->GetClient()->Unregister(self, dawn::wire::ObjectType::Device);\n bufferOffset = UINT64_MAX;\n}\n```\n\nThe 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:\n\n```html\n\n```\n\nThe `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.\n\nThe ASAN signature, lifted from the PoC's `README.md`:\n\n```\n==4138==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d000095798\nREAD of size 8 at 0x60d000095798 thread T2 (CrGpuMain)\n #0 ... DoAdapterRequestDevice::$_0::__invoke ...\nfreed by thread T2 here:\n #0 operator delete ...\n #1 dawn::wire::server::Server::DoUnregisterObject(ObjectType, ObjectId) ...\npreviously allocated by thread T2 here:\n #0 operator new ...\n #1 dawn::wire::server::KnownObjectsBase::Allocate ...\n```\n\nThe freed lambda is the uncaptured-error callback the `DoAdapterRequestDevice` path registered. The free is `DoUnregisterObject`. The allocation is `KnownObjectsBase::Allocate`. The three lines describe the bug.\n\n## The window was twenty months and twenty-six days\n\n`ClearDeviceCallbacks` did the work its name implied from May 2022 until April 2024. Three commits narrowed it:\n\n| date | commit | author | reviewer | what it did |\n|---|---|---|---|---|\n| 2022-05-24 | `20a4bd8377` | Austin Eng | | original three-setter `ClearDeviceCallbacks` lands |\n| 2024-04-10 | `0a552b460b` | Loko Kung | | callback-info migration for device-lost; `ClearDeviceCallbacks` stops clearing the device-lost setter |\n| 2024-06-20 | `f2a5e573d7` | Loko Kung | Kai Ninomiya | callback-info migration for uncaptured-error; `ClearDeviceCallbacks` shrinks to the single logging line above |\n| 2026-03-16 | CL 297136 | Loko Kung | Kai Ninomiya | fix lands |\n\nNeither 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.\n\nThe 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.\n\n## The patch is the function the two comments named\n\n[CL 297136](https://dawn-review.googlesource.com/c/dawn/+/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:\n\n```diff\n-void Server::ClearDeviceCallbacks(WGPUDevice device) {\n- // Un-set the logging callback since we cannot forward them\n- // after the server has been destroyed.\n- mProcs->deviceSetLoggingCallback(device, kEmptyLoggingCallbackInfo);\n-}\n```\n\nBoth 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.\n\nThe 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.\n\n## A note on what an auditor would have seen\n\nA reviewer reading the destructor in June 2024 would have read:\n\n```cpp\n// Un-set the error and lost callbacks since we cannot forward them\n// after the server has been destroyed.\nClearDeviceCallbacks(device);\n```\n\nThe 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.\n\nThis is the same shape as [yesterday's Drupal `Database::escapeTable` case](/posts/drupal-cve-2026-9082-the-comment-said-values): 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](/patterns/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.\n\n## Repro\n\nFull PoC, ASAN log, and the renderer-side trigger patch:\n\n> [`https://github.com/anansi2safe/CVE-2026-5281`](https://github.com/anansi2safe/CVE-2026-5281)\n\n`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.","closing_line":"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.","hook_md":"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`.","post_id":439,"slug":"chromium-cve-2026-5281-cleardevicecallbacks-cleared-one","title":"CVE-2026-5281: Dawn's ClearDeviceCallbacks Cleared One Callback. Its Two Callsite Comments Named the Other Two.","type":"initial","unreadable_sentence":"Dawn shipped a function whose name was plural, whose body cleared one callback, and whose two callsite comments named the two callbacks the body no longer cleared."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCamkSyAAKCRDeZjl4jgkQ JpcCAP95/3DYyLX5Du1G72J+kvKEcau+toY6f+kTlHBV2IFdcgD/aR2qit9oIY7l qrGilBfKywk4lQDqS+8EmWD7T7MyKAY= =Dxoi -----END PGP SIGNATURE-----