[2] Follow-up: ShareableBitmap context retains a pattern reference into another backend's ImageBuffer
Medium. The trigger needs an already-compromised web-content process. What it buys is a cross-thread race on a platform drawing context, and the route from that window to real memory corruption runs through platform graphics code that is never characterized here. This commit's own hunk only repoints a test import.
Drawing state can hold strong references to other drawing surfaces, so moving a surface between owners raises a question about everything it points at, not only the surface itself. In WebKit's GPU process a fill brush can be a Pattern, a repeating image fill, that keeps its source in a SourceImage: a variant over a decoded image, a resource identifier, or a strong reference to another drawable surface. Every RemoteRenderingBackend, the per-client drawing service that runs on its own work-queue thread, expects a surface it hands off to be self-contained, with no live reference back into resources only its own thread may touch.
The angle: a compromised web-content process can use a fill brush as a hidden strong reference, so a surface handed to another backend keeps reaching into the original backend's live drawing target from a second thread.
Follow-up: SerializedImageBuffer still leaks cross-RemoteRenderingBackend data through GraphicsContext for unaccelerated buffers
Unreviewed follow-up fix to apply RC_REMOVE_SEC_ACCEL_3 macro.
LayoutTests/ipc/set-fill-pattern-image-buffer-cross-backend-race-unaccelerated.html
The security-relevant code this test exercises is shown below in its post-fix state from the WebKit tree, unmarked.
Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp
Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp
Patch Details
The single hunk in this commit modifies the regression test in place, changing its coreipc.js import from ./coreipc.js to ../../ipc/coreipc.js.
The fix the test exercises has the following post-fix state in the tree. ImageBufferBackend declares hasGraphicsContext(), defaulting to true, with a comment saying that a backend unable to destroy its context "must not be handed to a different owner". Next to it sits releaseGraphicsContext(), which defaults to a no-op. ImageBufferShareableBitmapBackend overrides releaseGraphicsContext() as m_context = nullptr and hasGraphicsContext() as !!m_context; its context() rebuilds the context lazily through adoptGraphicsContext(). RemoteRenderingBackend::moveToSerializedBuffer() releases the context after the hasOneRef() check, then applies MESSAGE_CHECK(!hasGraphicsContext() || DisplayList) before addSerializedImageBuffer. A backend that keeps its context therefore fails closed: the sending WebContent process is terminated instead of the state being handed to another backend.
Ownership transfer of a container that does not scrub its embedded state, leaving strong references to the previous owner's thread-confined resources reachable from the new owner's thread.
Background
GPU process work queues.
WebKit's GPU process performs drawing on behalf of WebContent processes. Each RemoteRenderingBackend owns a set of RemoteImageBuffers and receives drawing commands over stream IPC on its own StreamConnectionWorkQueue, a dedicated serial thread for that connection.
ImageBuffer backends.
An ImageBuffer gets its storage and drawing context from an ImageBufferBackend. Accelerated backends use IOSurface-backed CGContexts, unaccelerated ones use a ShareableBitmap (ImageBufferShareableBitmapBackend), and DisplayList backends record commands.
GraphicsContext, Pattern and SourceImage.
A GraphicsContext carries mutable drawing state such as fill and stroke brushes. A fill brush can be a Pattern, which holds a SourceImage. A SourceImage is a variant over Ref<NativeImage>, Ref<ImageBuffer> or an unresolved RenderingResourceIdentifier, so a pattern fill may hold a strong reference to another ImageBuffer.
ThreadSafeRefCounted.
ImageBuffer is ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr: its refcount is updated atomically, so references to it may be taken and dropped from any thread. Atomic refcounting governs the object's lifetime only; it does not synchronize access to the object's internals.
Moving buffers between backends.
MoveToSerializedBuffer takes a buffer out of one backend and places it in a process-wide shared resource cache under a serialized identifier. MoveToImageBuffer lets another backend, possibly on a different thread, adopt it.
MESSAGE_CHECK and the IPC testing API.
MESSAGE_CHECK marks a message invalid and has the GPU process request termination of the offending WebContent process. IPCTestingAPIEnabled exposes raw IPC sending to layout tests to model what a compromised WebContent process could send.
Analysis
The bug is a cross-thread race created by a reference chain that survived an ownership transfer.
Backend A thread Backend B thread
---------------- ----------------
tile (accelerated ImageBuffer) <--Ref--+
IOSurface CGContext | carrier (unaccelerated, adopted)
| GraphicsContext (never dropped)
| fill brush: Pattern
+------ SourceImage = Ref<ImageBuffer>
FillRect / ClearRect on tile FillRect on carrier
+------> same platform context <------+ (no synchronization)
Read the diagram from the right. The carrier arrives on backend B with its GraphicsContext intact, because the move never verified that the context was gone. The test comment says the unaccelerated backend "used to ignore releaseGraphicsContext()", and the diff in [1] shows that as an explicit do-nothing override. Inside that surviving context, the fill brush is a Pattern whose SourceImage holds a Ref<ImageBuffer> pointing at A's tile. The Ref here is inferred from the test's expectation that a later move of the tile fails hasOneRef() with "ImageBuffer in use". That only happens if something still holds a strong reference to the tile. The same expectation shows the hidden reference breaks A's ownership invariant on its own, independent of any race.
When B issues FillRect, resolving the pattern reads A's tile. Per the test comment, only an accelerated tile "supplies the IOSurface CGContext that resolving the pattern would race against". At the same time, the left column has A's thread drawing into the tile through the tile's own context. Because ImageBuffer is thread-safe refcounted, the tile itself stays alive. This is not an ImageBuffer use-after-free; the hazard is unsynchronized access to the tile's platform drawing context and backing store. The fix restores the invariant that a serialized buffer carries no context-held references. The ShareableBitmap backend now actually drops m_context, and the move rejects any backend whose hasGraphicsContext() is still true, except DisplayList buffers.
This shape suggests the same discovery path as [1]: enumerate which ImageBufferBackend subclasses fail to honor the existing release mechanism, then exercise the gap with an IPC-testing-API harness that uses three RemoteRenderingBackends to get three work-queue threads.
The trigger is reachable from a compromised WebContent process through ordinary rendering IPC: MoveToSerializedBuffer/MoveToImageBuffer and SetFillPatternImageBuffer across multiple backends. The regression test demonstrates it with the IPC testing API. Turning the race into memory corruption would require the adopting backend's FillRect and the owning backend's drawing to interleave inside non-thread-safe platform graphics state, namely the IOSurface CGContext, in a way that leaves that state inconsistent. If the platform context's internals could be corrupted by that interleaving, the race would give a GPU-process memory-corruption primitive of unclear shape; otherwise it would stay limited to rendering inconsistency or a crash. The open audit question is whether that platform state has any window in which concurrent use corrupts memory rather than just rendering garbage. If weaponized, this would be a WebContent-to-GPU-process escalation step, not a full sandbox escape by itself.
This vulnerability weakens memory-safety isolation inside the GPU process. The rendering model assumes two things: each backend's resources are touched only from that backend's work-queue thread, and a serialized buffer is a self-contained handover. A context-held pattern reference broke both for unaccelerated buffers. An attacker with a compromised WebContent process could drive concurrent, unsynchronized drawing against the same platform context or backing store from two threads. If that race corrupts platform graphics state, it would offer a GPU-process memory-corruption foothold on the way out of the WebContent sandbox.
Takeaway. A transfer is only as exclusive as the reference graph behind the moved object: hasOneRef() on the root says nothing about what its drawing state still holds, and the FIXME's DisplayList exemption is a documented residual of exactly this class.
Audit directions
- Ownership handover that checks the container's refcount but not the references the container holds. An object moved between thread-confined owners must be transitively free of references back into the old owner.
- Narrow: audit the DisplayList exemption in
RemoteRenderingBackend::moveToSerializedBuffer. Trace whether a DisplayList-mode buffer's recorded items (patterns, images or filters referencingRenderingResourceIdentifiers orRef<ImageBuffer>) can be replayed on the adopting backend's thread. Match tell: any recorded item type that stores aRef<ImageBuffer>or a resolvedSourceImagerather than an identifier. - Wider: check the same handover shape in
RemoteImageBufferSettransfers andImageBuffer::transferToNewContextpaths. Match tell: a move or adopt function that inspectshasOneRef()but never walks or clears embedded state. - Widest: look at any actor or ownership-transfer system where a moved value can smuggle an alias to the sender's confined data, such as Rust
Sendtypes wrappingRc, Chromium sequence-bound objects, or Erlang-style message passing with shared heaps. Match tell: a transfer API whose safety argument rests only on the top-level object's uniqueness. - Inconsistent release/has-context overrides across backend subclasses. Check every
ImageBufferBackendsubclass (Cairo, Skia and remote IOSurface backends included) for consistent overrides ofreleaseGraphicsContext()andhasGraphicsContext(). - Narrow: grep for
final : public ImageBufferBackendand its CG/Cairo/Skia base aliases, and compare against implementers ofhasGraphicsContext. Match tell: a backend whosecontext()returns a long-lived member but which either inherits the basetrue(moves are rejected, so functionality may break) or overrides it tofalsewithout actually dropping state (a fail-open regression). - Wider: look for any "detach from surroundings" virtual with a no-op base default. Match tell: a security-relevant virtual whose default is permissive, so new subclasses fail open.
- Widest: apply the same fail-closed-default principle to capability or permission hooks in any plugin architecture.
- Cross-backend reachability of identifier-addressed objects. Investigate where GPU-process objects reachable by identifier from one
RemoteRenderingBackendcan be resolved by another. Per-backend resources must only be touched on the owning work queue. - Narrow: start with
RemoteSharedResourceCacheentry points and anySourceImage/Patternresolution that turns aRenderingResourceIdentifierinto a liveImageBuffer. Match tell: a lookup that consults a process-wide map instead of the calling backend'sm_remoteResourceCache. - Wider: check for the same cross-queue reachability in GPU-process WebGPU/WebGL object heaps shared across connections.
- Widest: any multi-tenant service with per-session worker threads and a process-global object table, such as Chromium's shared GPU command buffers or compositor resource providers. Match tell: a handle valid in one session that dereferences an object confined to another session's thread.