← All reports

[2] GPU-process `<model>` texture upload OOB read/write from unvalidated IPC layout

HighWebKit GPU process ModelOOB

A compromised renderer can write its own bytes past a GPU-process cube face

6459ed6

High, but gated on a compromised renderer. The payoff is out-of-bounds reads and writes of attacker-supplied bytes inside the more privileged GPU process. What remains unproven is placement: where a cube-face overrun lands, and whether over-read texels ever flow back.

WebKit runs <model> 3D rendering in a separate, more privileged GPU process, which must treat everything the sandboxed web-content process sends as hostile. Texture data arrives as a WKBridgeImageAsset, which bundles a shared-memory pixel buffer with width, height, texture type and pixel format. An optional per-mip layout of byte offsets and row/image strides can accompany it. makeMTLTextureFromImageAsset, the Swift routine that turns that asset into a Metal texture, is expected to keep every copy inside both the shared-memory mapping it reads from and the texture allocation it writes into.

The angle: an attacker who already owns a web-content process can steer makeMTLTextureFromImageAsset into reading past its shared-memory mapping and writing attacker bytes past a texture face in the GPU process, or simply crash that process at will.

Compromised WCP can send invalid texture data. Validate data from IPC is sufficient for the texture size.

Source/WebKit/GPUProcess/graphics/Model/USDModel.swift

+ if imageAsset.textureType == .typeCube, imageAsset.width != imageAsset.height {
+ logError("rejecting cube image asset with non-square dimensions ...")
+ return nil
+ }
...
- func uploadSlice(face: Int, mipLevel: Int, bytesOffset: Int, bytesPerRow: Int, bytesPerImage: Int) {
+ func uploadSlice(face: Int, mipLevel: Int, bytesOffset: Int, bytesPerRow: Int, bytesPerImage: Int) -> Bool {
let mipWidth = mipDimension(imageAsset.width, level: mipLevel)
let mipHeight = mipDimension(imageAsset.height, level: mipLevel)
+ let destinationWidth = mipDimension(mtlTexture.width, level: mipLevel)
+ let destinationHeight = mipDimension(mtlTexture.height, level: mipLevel)
+ guard mipLevel < mtlTexture.mipmapLevelCount,
+ mipWidth <= destinationWidth,
+ mipHeight <= destinationHeight
+ else { ... return false }
+
+ let (rowBytes, rowOverflow) = mipWidth.multipliedReportingOverflow(by: bytesPerPixel)
+ let (rowSpan, spanOverflow) = (mipHeight - 1).multipliedReportingOverflow(by: bytesPerRow)
+ let (lastRowStart, startOverflow) = bytesOffset.addingReportingOverflow(rowSpan)
+ let (windowEnd, endOverflow) = lastRowStart.addingReportingOverflow(rowBytes)
+ guard !rowOverflow, !spanOverflow, !startOverflow, !endOverflow,
+ bytesOffset >= 0,
+ bytesPerRow >= rowBytes,
+ windowEnd <= textureBytes.count
+ else { ... return false }
+
unsafe mtlTexture.replace(
region: MTLRegionMake2D(0, 0, mipWidth, mipHeight),
mipmapLevel: mipLevel,
slice: face,
withBytes: unsafe baseAddress.advanced(by: bytesOffset),
bytesPerRow: bytesPerRow,
- bytesPerImage: bytesPerImage
+ bytesPerImage: 0
)
+ return true
}
...
- uploadSlice(
- face: face,
- mipLevel: mipLevel,
- bytesOffset: info.dataOffset + face * info.byteCountPerImage,
+ let (faceOffset, faceOverflow) = face.multipliedReportingOverflow(by: info.byteCountPerImage)
+ let (bytesOffset, offsetOverflow) = info.dataOffset.addingReportingOverflow(faceOffset)
+ guard !faceOverflow, !offsetOverflow,
+ uploadSlice(face: face, mipLevel: mipLevel, bytesOffset: bytesOffset, ...)
+ else { ... mipLevelsInData = 0; return }
...
- fatalError("Could not make metal texture from environment asset data")
+ logError("could not make metal texture from environment asset data")
+ return

LayoutTests/sar3/http/tests/model/model-update-texture-invalid-layout.html

+ // dataOffset alone lands 1GB past a 4KB mapping.
+ await updateTexture(newAsset2D(), [
+ { dataOffset: 0x40000000, byteCountPerRow: 64, byteCountPerImage: asset2DBytes },
+ ]);
...
+ // Non-square cube: the source window fits the asset, but the 8x4096 region overruns the
+ // 8x8 destination face.
+ await updateTexture(newAssetNonSquareCube(), nonSquareCubeLayout());

The patch makes five changes to makeMTLTextureFromImageAsset. First, it rejects .typeCube assets whose width differs from their height before the descriptor is built. Second, the nested uploadSlice now returns Bool and gains two guard blocks ahead of mtlTexture.replace(...). The destination guard requires the mip level to exist and the mipWidth × mipHeight region to fit the destination mip extent derived from mtlTexture.width/height. The source guard computes the window [bytesOffset, bytesOffset + (mipHeight-1)*bytesPerRow + mipWidth*bytesPerPixel) with overflow-reporting arithmetic and requires a non-negative offset, bytesPerRow >= rowBytes, and windowEnd <= textureBytes.count. Third, bytesPerImage is pinned to 0, since each call uploads one 2D slice. Fourth, the per-face offset dataOffset + face * byteCountPerImage is computed with multipliedReportingOverflow/addingReportingOverflow. Any rejection logs, zeroes mipLevelsInData and returns, and the computed-layout loop now honors a false from uploadSlice. Fifth, in the WKBridgeReceiver environment-map path (the handler behind RemoteMesh::SetEnvironmentMap), a nil texture now logs and returns instead of calling fatalError.

  Before:                                  After:
  IPC layout {dataOffset, rowStride, ...}  IPC layout {dataOffset, rowStride, ...}
    └─► offset = dataOffset + face*img       └─► overflow-checked offset
          (trapping * and +)                       └─► dest guard: mip exists,
          └─► replace(region w x h,                      w,h <= dest mip extent
                withBytes: base+offset)                  └─► src guard: offset >= 0,
                 ├─ src read past mapping                      stride >= rowBytes,
                 └─ dst cube face is w x w,                    end <= bytes.count
                    region h > w overruns                      └─► replace(..., bytesPerImage: 0)

Untrusted cross-process layout descriptors forwarded to an unchecked bulk-copy API without validating them against both the source buffer's length and the destination object's extent.

Where this lives. WebKit splits the engine across four process roles. WebContent runs page code in a tight sandbox. The GPU process handles graphics, media and model rendering on WebContent's behalf with broader driver and system access. The Networking process handles loads, and the UI process hosts the app. WebKit's threat model assumes WebContent may be fully compromised, so every GPU-process IPC handler validates its inputs, usually with MESSAGE_CHECK, which terminates the misbehaving sender instead of acting on bad data.

Shared memory. Large payloads such as pixel data travel as a SharedMemory handle that the GPU process maps read-only. Reads through that mapping are safe only within its mapped length, here textureBytes.count.

<model> texture messages. RemoteGPU::CreateModelBacking registers a RemoteMesh receiver. RemoteMesh::UpdateTexture and RemoteMesh::SetEnvironmentMap deliver an UpdateTextureDescriptor carrying an image asset (handle, width, height, texture type, pixel format, mip count, array length) and an optional per-mip layout vector of dataOffset, byteCountPerRow and byteCountPerImage. Both end up in makeMTLTextureFromImageAsset.

Metal upload APIs. MTLTexture.replace(region:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:) copies region.height rows of region.width * bytesPerPixel bytes from withBytes, stepping by bytesPerRow, into one slice and mip of a texture; bytesPerImage matters only for 3D regions. textureCubeDescriptor(pixelFormat:size:mipmapped:) creates a cube texture with six square faces of edge size.

Swift arithmetic. Swift's + and * trap on signed overflow. addingReportingOverflow and multipliedReportingOverflow return the wrapped value plus an overflow flag, which lets code reject input instead of trapping.

Before the fix, the function treated two pieces of WebContent-controlled data as trusted geometry for an unchecked Metal copy: the layout triples, and the asset's width/height/textureType. Neither was ever related to the size of the shared-memory mapping or to the extent of the destination texture. The bug therefore has three faces: an OOB read on the source side, an OOB write on the destination side, and integer-overflow traps that act as a DoS.

On the source side, uploadSlice passed baseAddress.advanced(by: bytesOffset) and bytesPerRow straight from IPC. Metal reads mipHeight rows of mipWidth * bytesPerPixel bytes stepping by bytesPerRow, so an arbitrary or negative dataOffset, a huge row stride, or a stride narrower than the row moves the copy outside the mapping. The patch's own comment states that replace(region:) does not bounds-check in release builds. On the arithmetic side, face * byteCountPerImage and the subsequent add used trapping operators, so chosen values crash the GPU process deterministically, as did the fatalError in the environment-map path.

The destination side is the subtle one. For cube assets, textureCubeDescriptor(... size: imageAsset.width ...) allocates square width × width faces, but uploadSlice derived mipHeight from imageAsset.height. A cube asset taller than it is wide yields a region taller than the face, so Metal writes past the face's backing storage while every source-side bound is satisfied. No source-only check can catch this. The fix closes it twice, with the up-front square-cube rejection and the general destination-extent guard.

The regression test plays a compromised WebContent process through the IPC testing API, sending RemoteMesh::UpdateTexture and RemoteMesh::SetEnvironmentMap messages:

  1. A 2D asset whose dataOffset alone lands 1 GB past a 4 KB mapping, which is a pure source-side over-read.
  2. Oversized and undersized row strides, plus negative offsets, which exercise the remaining source-window conditions.
  3. Int64-overflowing image strides, which exercise the formerly trapping per-face offset arithmetic.
  4. A non-square cube asset whose source window fits, but whose 8×4096 region overruns an 8×8 destination face. This is the destination-only case.

Reachability requires a compromised WebContent process sending RemoteMesh IPC in builds with ENABLE(GPU_PROCESS_MODEL). The overflow traps and the old fatalError give a reliable GPU-process DoS. The source-side read is a relative OOB read of GPU-process memory, anchored at the mapping's base and bounded by dataOffset, byteCountPerRow and the region size. The bytes land in a texture rather than in a buffer WebContent can read directly, so it would act as an info leak only if texture contents could flow back through rendered model output. The destination-side write overruns a cube face by an amount sized by the height - width mismatch, with contents taken from the attacker's own asset. Contents are therefore controlled, while placement is open: for .shared storage, the exact write geometry depends on the texture's memory layout, and the overrun may first spill into adjacent faces of the same cube before leaving the allocation. That makes it a heap-overflow-class candidate whose adjacency targets are not established. None of this escapes the GPU process's own sandbox; it is a renderer-to-GPU-process step.

Before the fix, this vulnerability weakened the WebContent-to-GPU-process isolation boundary. The GPU process is supposed to treat every IPC field as hostile, and shared-memory handles are supposed to bound every read it performs on WebContent's behalf. Both assumptions failed here: IPC-supplied offsets and strides directed reads outside the mapping, and asset dimensions directed writes outside the destination allocation.

Insight. The bug has two independent sides, and the test deliberately covers both. The textbook "validate offset plus length against the handle" fix would have left the non-square-cube overflow open, because the upload region came from one field (imageAsset.height) while the destination extent came from another (the descriptor's single size). Separately, Swift's trapping arithmetic and fatalError convert memory-safety bugs into availability bugs at IPC boundaries. Overflow-reporting arithmetic plus a soft reject, as used here, is the right shape. The same function still contains fatalError calls on out-of-range width/height and on an unknown bytesPerPixel, and whether those values are pre-validated at IPC decode is worth checking.