← All reports

[1] Unaccelerated ImageBuffer transfer leaks a cross-backend CGContext into another GPU-process thread

HighWebKit GPU ProcessRace

Two GPU-process threads, one CGContext, and a cleanup hook that never cleaned up

d03b917

High. A compromised web-content process can use ordinary rendering IPC to make two GPU-process work-queue threads draw into the same IOSurface CGContext at once; the commit message reports this corrupts the tile's CoreAnimation CA::CG::Queue. What keeps it below Critical is the gap between a racy ASan crash and a controlled primitive, which runs through CoreAnimation internals outside WebKit.

Safety in WebKit's GPU process, the privileged helper that draws page content for sandboxed web-content processes, rests on thread confinement: each drawing surface, and everything it references, is touched by exactly one worker thread. Each RemoteRenderingBackend (a per-client drawing service that owns a set of surfaces and runs their IPC stream on its own work-queue thread) can hand an ImageBuffer, a drawable pixel surface, to another backend. That handover is safe only if the buffer's GraphicsContext, meaning its live drawing state including fill patterns that may point at other buffers, is dropped first.

The angle: a compromised web-content process can smuggle a reference to one backend's accelerated surface into a second backend, so two GPU-process threads draw into the same CoreGraphics context at once.

SerializedImageBuffer still leaks cross-RemoteRenderingBackend data through GraphicsContext for unaccelerated buffers

ImageBufferShareableBitmapBackend::releaseGraphicsContext() is a no-op, so the fix for rdar://175520296 never covered unaccelerated buffers. A compromised WebContent process can point an unaccelerated ImageBuffer's fill pattern at an accelerated one, then move the unaccelerated buffer to a second RemoteRenderingBackend. The pattern survives the transfer. Resolving it dereferences the accelerated buffer's CGContext from the adopting backend's work queue thread while the owning backend draws into it, which corrupts the tile's CA::CG::Queue.

Release the context for real: drop it and recreate it lazily from the ShareableBitmap, as the IOSurface backends already do.

Assuming that every backend implements releaseGraphicsContext() is what failed here, so make the guarantee checkable instead. ImageBufferBackend::hasGraphicsContext() defaults to true. Backends that can drop their context report whether one is still live, and moveToSerializedBuffer() message-checks that none is. This closes the same hole in ImageBufferCGPDFDocumentBackend and replaces a base class ASSERT_NOT_REACHED() that IPC could reach. DisplayList buffers are exempt for now; their recorded items can still reference ImageBuffers owned by the source backend, and that is left to a follow-up. NullImageBufferBackend allocates its context lazily so buffers created after an allocation failure remain transferable.

The rdar://175520296 test hardcodes renderingMode 1 for both the tile and the carriers, which is why the unaccelerated path went untested. The new test transfers unaccelerated carriers that reference an accelerated tile. Without this change it crashes the GPU process in CA::CG::ContextDelegate::submit() on 3 of 5 ASan runs.

Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp

MESSAGE_CHECK(imageBuffer->hasOneRef(), "ImageBuffer in use");
// Avoid leaking cross-RemoteRenderingBackend state through context by releasing the context.
imageBuffer->releaseGraphicsContext();
+ // A backend that cannot release its context still holds that state, which the adopting
+ // RemoteRenderingBackend would then touch from its own work queue thread.
+ // FIXME: DisplayList buffers are exempt because moving them is supported, but their recorded
+ // items and state can still reference ImageBuffers owned by this RemoteRenderingBackend.
+ MESSAGE_CHECK(!imageBuffer->hasGraphicsContext() || imageBuffer->renderingMode() == RenderingMode::DisplayList, "ImageBuffer cannot release its GraphicsContext");
bool success = m_sharedResourceCache->addSerializedImageBuffer(serializedIdentifier, WTF::move(imageBuffer));

Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.h

- void releaseGraphicsContext() final { /* Do nothing. This is only relevant for IOSurface backends */ }
+ void releaseGraphicsContext() final;
+ bool hasGraphicsContext() const final { return !!m_context; }
...
- const std::unique_ptr<WebCore::GraphicsContext> m_context;
+ std::unique_ptr<WebCore::GraphicsContext> m_context;

Source/WebKit/WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp

+GraphicsContext& ImageBufferShareableBitmapBackend::context()
+{
+ if (!m_context) {
+ auto context = m_bitmap->createGraphicsContext();
+ RELEASE_ASSERT(context);
+ adoptGraphicsContext(WTF::move(context));
+ }
+ return *m_context;
+}
+
+void ImageBufferShareableBitmapBackend::releaseGraphicsContext()
+{
+ m_context = nullptr;
+}

LayoutTests/ipc/set-fill-pattern-image-buffer-cross-backend-race-unaccelerated.html

+ const carrier = createRemoteImageBuffer(A, RENDERING_MODE_UNACCELERATED, 32, 32);
+ carrier.remoteGraphicsContext.SetFillPatternImageBuffer({
+ imageBufferIdentifier: tileToReference.imageBufferIdentifier, ... });
+ return transferImageBuffer(A, adopter, carrier.imageBufferIdentifier);
...
+ carrier.remoteGraphicsContext.FillRect({ rect: RECT32, requiresClipToRect: 0 });
+ for (let k = 0; k < 8; k++) {
+ raceTile.remoteGraphicsContext.FillRect({ rect: RECT128, requiresClipToRect: 0 });

The change makes the unaccelerated backend drop its context for real, adds a fail-closed hasGraphicsContext() query across the backend hierarchy, and enforces that query with a MESSAGE_CHECK at the IPC transfer point.

In ImageBufferShareableBitmapBackend, the "Do nothing" override of releaseGraphicsContext() is replaced with one that sets m_context to null. m_context loses its const qualifier so it can be reset. context() now recreates the context lazily from m_bitmap->createGraphicsContext() under a RELEASE_ASSERT. The old constructor logic moves into a new adoptGraphicsContext() helper, which reapplies the device scale factor.

ImageBufferBackend gains virtual bool hasGraphicsContext() const { return true; }. The default deliberately reports a live context, so a backend that cannot drop one is treated as holding one. Overrides returning !!m_context are added to ImageBufferIOSurfaceBackend, ImageBufferShareableBitmapBackend, ImageBufferShareableMappedIOSurfaceBitmapBackend, DynamicContentScalingImageBufferBackend and NullImageBufferBackend. DynamicContentScalingBifurcatedImageBuffer ORs its own m_context with both of its backends. ImageBuffer gets a virtual hasGraphicsContext() that forwards to the backend. NullImageBufferBackend changes its inline NullGraphicsContext member into a lazily allocated std::unique_ptr so it can truthfully report no live context.

In RemoteRenderingBackend::moveToSerializedBuffer(), the new MESSAGE_CHECK runs after releaseGraphicsContext() and rejects any buffer that still reports a context, unless it is DisplayList-backed. A violating transfer terminates the sending web-content process. The DisplayList exemption carries an explicit FIXME. The new regression test builds accelerated tiles on backend A, points unaccelerated carriers' fill patterns at them, moves the carriers to backends B and C, and then interleaves draws on both sides.

Ownership transfer validated on the moved object's own refcount while transitively referenced thread-confined resources, guarded only by a no-op default hook, escape to another thread.

Where this lives. WebKit splits a browser tab across four kinds of process: WebContent (sandboxed, runs page script), GPU, Networking, and UI. On Cocoa platforms 2D rendering runs in the GPU process, which executes drawing commands on behalf of WebContent processes.

Threat model. GPU-process IPC bugs are evaluated assuming the WebContent process is already compromised and can send any message. Layout tests run with IPCTestingAPIEnabled simulate this by letting script send raw IPC.

RemoteRenderingBackend. Each WebContent-side rendering context talks to one RemoteRenderingBackend over a stream IPC connection. Each backend owns a set of ImageBuffers and processes its messages on its own work queue, which is a distinct thread.

ImageBuffer and its backends. An ImageBuffer is a drawable pixel surface, and its ImageBufferBackend determines the storage. ImageBufferIOSurfaceBackend is accelerated and backed by an IOSurface with a CGContext. ImageBufferShareableBitmapBackend is unaccelerated and backed by shared memory. Display-list and PDF backends record drawing instead of rasterizing it.

GraphicsContext state and RemoteGraphicsContext. A GraphicsContext holds drawing state such as fill and stroke brushes, clip and transform. A fill brush can be a pattern whose source is another ImageBuffer, so filling with it reads that buffer's contents. RemoteGraphicsContext is the GPU-process receiver for drawing commands aimed at one buffer's context. SetFillPatternImageBuffer is one such command; it names the source buffer by RenderingResourceIdentifier.

Moving buffers between backends. MoveToSerializedBuffer and MoveToImageBuffer hand an ImageBuffer from one backend to another through a shared resource cache, for example when canvases are transferred between contexts. Before the handoff, the source backend calls releaseGraphicsContext(), a virtual hook on the buffer's backend meant to drop its drawing state.

MESSAGE_CHECK. WebKit's IPC validation macro. On failure it treats the sender as compromised and terminates it, rather than crashing the privileged receiving process.

Before the fix, this was a cross-thread data race on a thread-confined graphics context: the transfer validated the carrier and trusted a release hook that did nothing for unaccelerated buffers.

  Backend A work queue                  Backend B work queue
  --------------------                  --------------------
  carrier.SetFillPatternImageBuffer(tile)
  MoveToSerializedBuffer(carrier)
    hasOneRef(carrier)        -> ok
    releaseGraphicsContext()  -> no-op
                                        MoveToImageBuffer(carrier)
  tile.FillRect  ----+                  carrier.FillRect
                     |                    resolve fill pattern --+
                     v                                           v
             tile's IOSurface CGContext  <--- two threads, no lock
             CA::CG::Queue corruption (per commit message)

Follow the left column first. hasOneRef() only examines the carrier's own refcount; it says nothing about what the carrier's drawing state references. The next line was supposed to scrub that state, but the base ImageBufferBackend::releaseGraphicsContext() is an empty virtual and ImageBufferShareableBitmapBackend overrode it with an explicit "Do nothing" body. The comment claimed the hook was "only relevant for IOSurface backends". For any unaccelerated carrier, the fill brush set by SetFillPatternImageBuffer rode across the transfer intact.

That brush holds a strong reference to the tile. The regression test documents this directly: a surviving reference makes a later transfer of the tile itself fail the "ImageBuffer in use" check. The tile therefore stays alive throughout. This is not a dangling ImageBuffer; the hazard is concurrency on its context. Once backend B adopts the carrier and issues FillRect, resolving the pattern reaches into the tile's IOSurface CGContext from B's work queue. The test comment states that "only an accelerated backend supplies the IOSurface CGContext that resolving the pattern would race against". Meanwhile A's work queue is drawing into that same context (the right-hand arrow meets the left-hand arrow in the diagram), and CoreGraphics gets no synchronization between them. The commit message states the result is corruption of the tile's CA::CG::Queue.

The discovery angle is variant analysis of an incomplete earlier fix. The commit message attributes the original hardening to rdar://175520296 and notes that its test hardcoded renderingMode 1 (accelerated) for both the tile and the carriers. That fix depended on every backend making releaseGraphicsContext() meaningful. Enumerating the backends that actually implemented it surfaces the explicit no-op in the ShareableBitmap backend. Swapping the carrier's rendering mode in the old test is then enough to build the new one. The same enumeration catches a second instance: the commit message states that ImageBufferCGPDFDocumentBackend carries equivalent state but cannot release it, and the fail-closed true default now rejects such buffers at the MESSAGE_CHECK.

The regression test walks the trigger end to end:

  1. Create accelerated tiles on backend A. Only accelerated buffers supply an IOSurface CGContext to race on.
  2. Create unaccelerated carriers on A and set each carrier's fill pattern to a tile with SetFillPatternImageBuffer.
  3. Move the carriers to backends B and C with MoveToSerializedBuffer / MoveToImageBuffer. Because the carriers' contexts were never released, their fill patterns, and with them the strong reference to A's tile, survive the move.
  4. On B and C, issue FillRect on the carriers. Each one resolves the pattern against the tile.
  5. On A, issue a burst of eight FillRects into the tile per iteration. This gives three GPU-process work-queue threads touching one context.
  6. Repeat across 96 carriers. The commit message reports an ASan crash in CA::CG::ContextDelegate::submit() on 3 of 5 runs.

The bug gives GPU-process memory corruption through a cross-thread race, reachable from a compromised WebContent process using ordinary rendering IPC. That makes it a credible sandbox-escape-stage candidate. Whether the corruption can be made structured rather than random is the open question. A structured result would be, for example, an enqueue/dequeue race that frees or reuses a CA::CG::Queue node while the other thread still holds it. That would require two things. The first is timing control over A's draws versus B's pattern resolution; the test's 96-carrier loop suggests this is achievable but probabilistic. The second is knowledge of CA::CG::Queue's internal node layout, which lies outside WebKit. If the race could be steered into a lifetime violation on a queue entry, it could act as a use-after-free candidate in the GPU process. Its ceiling is bounded by what the queue holds (pending CG command records) and by the race window between the two backend work queues. Nothing in the available source establishes attacker control over the corrupted contents. The auditor-facing question is whether any queue-node lifetime in that structure is decided by a single unsynchronized read.

On sandboxing, the bug presupposes a compromised WebContent process that can send arbitrary RemoteRenderingBackend and RemoteGraphicsContext IPC. It would therefore serve as the second, sandbox-escape stage of a chain, not as an initial renderer exploit. The GPU process is itself sandboxed, so full system impact would still depend on further steps.

This vulnerability weakens the cross-process isolation boundary between a WebContent process and the GPU process. The GPU process assumes that every ImageBuffer, together with every resource its graphics state references, is touched only from its owning backend's work-queue thread. Before the fix, a compromised WebContent process could break that thread-confinement invariant using ordinary rendering IPC and drive concurrent mutation of CoreGraphics/CoreAnimation internal structures in a more privileged process. If the CA::CG::Queue corruption were shaped into a controlled primitive, it could serve as the GPU-process stage of a renderer-to-GPU-process sandbox escape chain.

Insight. This is a variant left open by an incomplete prior fix: the security property silently failed open for every backend that did not opt in, since the base default was a no-op and one backend had written "Do nothing" explicitly. The prior test hardcoded the accelerated mode, so its coverage matched the implementation's blind spot exactly. The structural improvement here turns an assumed postcondition into a checked one. Because hasGraphicsContext() defaults to true, new or forgotten backends are rejected rather than waved through. Two limits remain. The DisplayList exemption is a known-open variant, since recorded items can still reference source-backend ImageBuffers. And hasOneRef() on the transferred object stays a weak proxy for exclusive ownership whenever that object's state references sibling resources.