WebGPU swap-chain shared texture: content-controlled depthOrArrayLayers passed unvalidated to create_texture_from_hal → out-of-range Metal destinationSlice
Categories
(Core :: Graphics: WebGPU, defect, P1)
Tracking
()
People
(Reporter: tjr, Assigned: aleiserson)
References
Details
(6 keywords, Whiteboard: [adv-main153+r])
Attachments
(4 files, 2 external files)
A compromised content process can forge the bincode-serialized DeviceAction::CreateTexture message that travels over PWebGPU (managed by PCanvasManager [ParentProc=compositor, ChildProc=anydom]) so that the swap-chain texture descriptor carries depth_or_array_layers = N (up to 32766) while still requesting the shared-texture path. In the compositor process, gfx/wgpu_bindings/src/server.rs only checks width/height against limits before calling the platform shared-texture helper; on macOS create_texture_with_shared_texture_iosurface allocates a single-layer IOSurface (SharedTextureMacIOSurface::Create ignores depth), builds an MTLTexture with textureType=Type2D and the default arrayLength=1, wraps it via texture_from_raw(array_layers=1, copy_size.depth=1), and then registers it in wgpu-core with create_texture_from_hal(&desc) using the content descriptor. create_texture_from_hal performs no size/dimension/array-layer/mip/sample validation, so wgpu-core records desc.size.depth_or_array_layers = N for a hardware texture whose backing is sized for one layer.
A subsequent queue.writeTexture with origin.z = k (0 < k < N) passes validate_texture_copy_range (which checks against the forged desc), bypasses zero-init (Texture::new is called with init=false ⇒ per-mip InitTracker::new(0) ⇒ check(k..k+1)=None), and reaches wgpu-hal Metal copy_buffer_to_texture, which forwards copy.texture_base.array_layer unchanged as the destinationSlice argument of -[MTLBlitCommandEncoder copyFromBuffer:…toTexture:destinationSlice:k …] on a 1-slice IOSurface-backed MTLTexture. Apple requires destinationSlice < arrayLength; with API Validation off (production) this is driver-undefined behaviour with attacker-controlled slice index and 256 KiB attacker-chosen payload per call.
This is a Content → Compositor (GPU-class per §4) input-validation bug. It could not be exercised on the Linux verification host (no Vulkan adapter; with lavapipe the DMABuf branch bails on missing VK_EXT_image_drm_format_modifier before reaching create_texture_from_hal), so the memory-corruption outcome on macOS is unverified — possible results range from GPU fault/restart to an out-of-bounds GPU write past the IOSurface allocation in compositor address space. The Linux and Windows shared-texture branches share the same create_texture_from_hal(&desc) pattern.
Build Info
- Branch: asan-4
- Revision: 6bf7902103ad0177a215d8cb494fcb923f5c3e57
- Timestamp: 2026-06-18T07:11:31+00:00
Affected Code
File: gfx/wgpu_bindings/src/server.rs, line 2187-2304
DeviceAction::CreateTexture(id, desc, swap_chain_id) => {
...
letmax = MAX_TEXTURE_EXTENT;
if desc.size.width > max
|| desc.size.height > max
|| desc.size.depth_or_array_layers > max { ... return; }
if [w,h,d].contains(&0) { ... return; }
let use_shared_texture = if let Some(id) = swap_chain_id {
unsafe { wgpu_server_use_shared_texture_for_swap_chain(self.owner, id) }
} else { false };
if use_shared_texture {
let limits = self.device_limits(device_id);
if desc.size.width > limits.max_texture_dimension_2d
|| desc.size.height > limits.max_texture_dimension_2d { ... }
// *** NO check that dimension==D2, depth_or_array_layers==1,
// mip_level_count==1, sample_count==1 ***
#[cfg(target_os = "macos")]
{
let is_created = self.create_texture_with_shared_texture_iosurface(
device_id, id, &desc, swap_chain_id);
if is_created { return; }
}
...
}
File: gfx/wgpu_bindings/src/server.rs, line 3632-3749
pub(super) fn create_texture_with_shared_texture_iosurface(
&self, device_id, texture_id, desc: &wgc::resource::TextureDescriptor, swap_chain_id) -> bool {
let ret = unsafe {
wgpu_server_ensure_shared_texture_for_swap_chain(
self.owner, swap_chain_id.unwrap(), device_id, texture_id,
desc.size.width, desc.size.height, // <-- depth IGNORED
desc.format, desc.usage)
};
...
let descriptor = MTLTextureDescriptor::new();
descriptor.setTextureType(MTLTextureType::Type2D);
descriptor.setWidth(desc_ref.size.width as usize);
descriptor.setHeight(desc_ref.size.height as usize);
descriptor.setMipmapLevelCount(desc_ref.mip_level_count as usize);
// *** descriptor.setArrayLength NEVER called -> arrayLength == 1 ***
...
device.newTextureWithDescriptor_iosurface_plane(&descriptor, &io_surface, 0)
...
let hal_texture = unsafe {
<wgh::api::Metal as wgh::Api>::Device::texture_from_raw(
raw_texture, wgt::TextureFormat::Bgra8Unorm, MTLTextureType::Type2D,
1, 1, // array_layers=1, mips=1
wgh::CopyExtent { width: desc.size.width, height: desc.size.height, depth: 1 },
None)
};
let (_, error) = unsafe {
self.create_texture_from_hal(
Box::new(hal_texture), device_id,
&desc, // <-- CONTENT DESC, depth_or_array_layers = N
wgt::TextureUses::UNINITIALIZED, Some(texture_id))
};
...
true
}
File: third_party/rust/wgpu-core/src/device/resource.rs, line 1243-1273
pub(crate) fn create_texture_from_hal(
self: &Arc<Self>,
hal_texture: Box<dyn hal::DynTexture>,
desc: &resource::TextureDescriptor,
initial_state: wgt::TextureUses,
) -> Result<Arc<Texture>, resource::CreateTextureError> {
let format_features = self
.describe_format_features(desc.format)
.map_err(|error| resource::CreateTextureError::MissingFeatures(desc.format, error))?;
// *** NO size / dimension / array-layer / mip / sample validation ***
unsafe { self.raw().add_raw_texture(&*hal_texture) };
let texture = Texture::new(
self,
resource::TextureInner::Native { raw: hal_texture },
conv::map_texture_usage(desc.usage, desc.format.into(), format_features.flags),
desc, // <-- forged desc recorded verbatim
format_features,
resource::TextureClearMode::None,
false, // init=false -> InitTracker::new(0)
);
...
}
File: third_party/rust/wgpu-core/src/device/queue.rs, line 855-1054
dst.check_usage(wgt::TextureUsages::COPY_DST)?; // attacker sets COPY_DST in desc.usage
let (hal_copy_size, array_layer_count) =
validate_texture_copy_range(&destination, &dst.desc, CopySide::Destination, size)?;
// ^^^^^^^^ extent.depth_or_array_layers == N (forged)
let (selector, dst_base) = extract_texture_selector(&destination, size, &dst)?;
// dst_base.array_layer = origin.z = k
...
if dst_initialization_status.mips[0].check(k..k+1).is_some() { // None: InitTracker::new(0)
... clear_texture(...) // never reached
}
...
let regions = (0..array_layer_count).map(|off| {
let mut texture_base = dst_base.clone();
texture_base.array_layer += off;
hal::BufferTextureCopy { ..., texture_base, size: hal_copy_size }
}).collect();
...
unsafe { encoder.copy_buffer_to_texture(staging_buffer.raw(), dst_raw, ®ions); }
File: third_party/rust/wgpu-hal/src/metal/command.rs, line 638-679
unsafe fn copy_buffer_to_texture<T>(&mut self, src, dst: &super::Texture, regions: T) {
let encoder = self.enter_blit();
for copy in regions {
let extent = copy.texture_base.max_copy_size(&dst.copy_size).min(©.size);
// ^ clamps extent to {w,h,1}; does NOT touch array_layer
...
unsafe {
encoder.copyFromBuffer_sourceOffset_..._toTexture_destinationSlice_destinationLevel_destinationOrigin_options(
&src.raw, ...,
conv::map_copy_extent(&extent),
&dst.raw,
copy.texture_base.array_layer as usize, // <-- destinationSlice = k on arrayLength=1 texture
copy.texture_base.mip_level as usize,
dst_origin,
...,
)
};
}
}
The compositor-side handler trusts the content-supplied descriptor over the actual 1-layer hardware backing. (1) server.rs enters the shared-texture branch without enforcing depth_or_array_layers==1; (2) the macOS helper allocates a single-layer IOSurface/MTLTexture but registers it with the unmodified content descriptor; (3) wgpu-core::create_texture_from_hal performs no validation; (4) queue.write_texture validates against the forged descriptor; (5) wgpu-hal Metal forwards array_layer verbatim to destinationSlice.
Exploit Chain
- Attacker obtains code execution in a web content process (assumed renderer compromise).
- Attacker sends Message::CreateSwapChain over PWebGPU with use_shared_texture_in_swap_chain=true; WebGPUParent::DeviceCreateSwapChain stores this verbatim in PresentationData without re-validation.
- Attacker sends DeviceAction::CreateTexture with swap_chain_id set, dimension=D2, size={256,256,8192}, mip=1, sample=1, usage including COPY_DST.
- In the compositor, server.rs checks only width/height/zero/MAX_TEXTURE_EXTENT, then (on macOS) calls create_texture_with_shared_texture_iosurface.
- wgpu_server_ensure_shared_texture_for_swap_chain → SharedTextureMacIOSurface::Create → MacIOSurface::CreateIOSurface(256,256) allocates a 256 KiB single-layer IOSurface; an MTLTexture with Type2D / arrayLength=1 is wrapped over it.
- create_texture_from_hal(&desc) registers the texture in wgpu-core with desc.size.depth_or_array_layers = 8192 without validation; Texture::new(init=false) makes the per-mip init tracker InitTracker::new(0).
- Attacker issues queue.writeTexture({texture, origin:[0,0,k]}, 256 KiB payload, …, [256,256,1]) for k=1..N. validate_texture_copy_range checks origin.z+1 ≤ 8192 → passes; init tracking returns None → no clear_texture.
- wgpu-hal Metal copy_buffer_to_texture invokes -[MTLBlitCommandEncoder copyFromBuffer:…toTexture:destinationSlice:k destinationLevel:0 …] on a Type2D texture with arrayLength=1.
- With Metal API Validation disabled (production), this violates the documented destinationSlice < arrayLength requirement; driver behaviour is undefined and may include a GPU write to slice-k offset (k × 256 KiB) past the start of the IOSurface backing in compositor address space.
IPC Path
- PWebGPU Messages
- Protocol: PWebGPU
- Parent process: GPU
- Child process: Content
- Message flow: Content -> GPU(compositor): Messages bytes (bincode Message::CreateSwapChain{use_shared_texture_in_swap_chain=true}, Message::DeviceAction(DeviceAction::CreateTexture{size.depth_or_array_layers=8192, swap_chain_id}), Message::QueueWriteAction(QueueWriteAction::WriteTexture{origin.z=k}))
Steps to Reproduce
- [CROSS-OS — UNVERIFIED ON THE LINUX AUDIT HOST] On an Apple-Silicon macOS machine with a Firefox ASAN/debug build (WebGPU enabled by default; otherwise set dom.webgpu.enabled=true).
- git apply exploit.patch (modifies dom/webgpu/Device.cpp only; XRE_IsContentProcess()-guarded forgery of depthOrArrayLayers=8192 and use_shared_texture_in_swap_chain=true).
- ./mach build
- ./mach run --setpref dom.webgpu.enabled=true --setpref dom.webgpu.allow-present-without-readback=true --setpref gfx.webgpu.ignore-blocklist=true testcase.html
- Optionally export MTL_DEBUG_LAYER=1 tohave Metal API Validation flag the out-of-range destinationSlice; without it, observe driver-undefined behaviour (GPU fault / restart or heap corruption) in the compositor process.
- Linux evidence (this host): patched build prints
EXPLOIT[content]: forcing use_shared_texture_in_swap_chain=true/EXPLOIT[content]: forging swap-chain texture depthOrArrayLayers=8192, then bails withFailed to create VkImage(lavapipe lacks VK_EXT_image_drm_format_modifier) and falls back to device_create_texture which correctly rejects depth=8192 — proving the fallback validator is exactly what create_texture_from_hal skips on the IOSurface success path.
Security Impact
- Severity: Moderate
- Attacker capability: A compromised content process can drive the compositor (GPU-class) process to issue Metal blit copies with attacker-chosen destinationSlice (1..32766) and attacker-chosen 256 KiB payload per call against a 1-slice IOSurface-backed MTLTexture. If the Metal driver computes the destination as base + slice×layerStride (no bounds check with API Validation off), this is an out-of-bounds GPU write at attacker-controlled offset past the swap-chain IOSurface allocation in compositor address space — a Content → GPU lateral primitive. Actual driver behaviour is unverified and may instead manifest as a GPU page fault / device-lost.
- Preconditions: Renderer (content-process) RCE assumed. macOS host where the IOSurface shared-texture swap-chain path succeeds (Apple Silicon default; WebGPU enabled). On Linux requires a Vulkan driver exposing VK_EXT_image_drm_format_modifier with DRM (not lavapipe). Metal API Validation must be off (production default) for the call to reach the driver unfiltered.
ASAN Report
UNVERIFIED: cross-OS target (macos); see analysis.
No sanitizer crash was captured. The vulnerable shared-texture swap-chain
path requires platform GPU sharing that the Linux/Xvfb verification host
lacks (no /dev/dri; lavapipe missing VK_EXT_image_drm_format_modifier).
Runtime trace from the patched Linux build (researcher-supplied), showing
the forged IPC reaching the victim's shared-texture branch and bailing at
DMABuf VkImage creation immediately before the unvalidated
create_texture_from_hal call that the macOS branch reaches:
EXPLOIT[content]: forcing use_shared_texture_in_swap_chain=true
EXPLOIT[content]: forging swap-chain texture depthOrArrayLayers=8192
[GFX1-]: failed to get consumer dmabuf modifiers
[GFX1-]: Failed to create VkImage
[GFX1-]: Failed to create shared texture
[GFX1-]: Disable SharedTexture for SwapChain: 1
Uncaptured WebGPU error: Dimension Z value 8192 exceeds the limit of 256
(Last line emitted by the *fallback* device_create_texture validator —
exactly the validator that create_texture_from_hal SKIPS on the
IOSurface success path on macOS.)
| Reporter | ||
Comment 1•4 months ago
|
||
| Reporter | ||
Comment 2•4 months ago
|
||
| Reporter | ||
Comment 3•4 months ago
|
||
| Reporter | ||
Comment 4•4 months ago
|
||
| Reporter | ||
Comment 5•4 months ago
|
||
| Reporter | ||
Updated•4 months ago
|
| Reporter | ||
Updated•4 months ago
|
Updated•4 months ago
|
Comment 7•4 months ago
|
||
This seems like a legit bug. WebGPU is putting this in its "Urgent/Critical" column.
| Assignee | ||
Updated•4 months ago
|
| Assignee | ||
Comment 8•4 months ago
|
||
It's not clear whether there is an actual security issue here. The test case does trip the MTL_DEBUG_LAYERS, but even after changing it to write all 8192 layers instead of only 200 layers, I don't see any ill effect of the out-of-bounds accesses.
Also, in some cases (even without MTL_DEBUG_LAYERS), the browser crashes with:
_mtlValidateArgumentsForTextureViewOnDevice:1866: failed assertion `Texture Creation
(newSliceRange.location + newSliceRange.length)(8192) must be <= (1).
'
Which suggests the system is not oblivious to the true size of the texture.
The issue still seems worth fixing, just noting those observations.
| Assignee | ||
Comment 9•4 months ago
|
||
Comment 10•4 months ago
|
||
Comment 11•4 months ago
|
||
Comment 12•4 months ago
|
||
Please add uplift requests for beta and esr140
| Assignee | ||
Comment 13•4 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D309705
Updated•4 months ago
|
Comment 14•4 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: Security fix
- Code covered by automated testing?: no
- Fix verified in Nightly?: yes
- Needs manual QE testing?: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: Re-plumbs state to avoid trusting content process; no functional effect.
- String changes made/needed?: n/a
- Is Android affected?: no
| Assignee | ||
Comment 15•4 months ago
|
||
I opened an uplift request for beta. Is the esr140 uplift request needed in some way to prepare for esr153?
Nominally, esr140 doesn't have WebGPU. Although it occurs to me that for this kind of privilege escalation bug, we may need to do something more than we are currently to ensure we're protected. I will think about that more and open a separate bug for that if needed. Leaving my NI for this question.
Comment 16•4 months ago
|
||
I've updated the ESR140 status, thanks for flagging it.
ESR153 will match the final state of Fx153 Beta, so only a Beta uplift request is needed here.
Updated•4 months ago
|
Updated•4 months ago
|
Comment 17•4 months ago
|
||
| uplift | ||
Updated•4 months ago
|
| Assignee | ||
Comment 18•4 months ago
|
||
(In reply to Andy Leiserson [:aleiserson] from comment #15)
Nominally, esr140 doesn't have WebGPU. Although it occurs to me that for this kind of privilege escalation bug, we may need to do something more than we are currently to ensure we're protected.
I confirmed that we block creation of the WebGPU actor in trusted code when WebGPU is disabled, so this is fine, no fix needed to esr140.
Updated•4 months ago
|
Updated•2 months ago
|
Description
•