Closed Bug 2059002 Opened 3 months ago Closed 3 months ago

WebGPU swap-chain textures bypass wgpu-core validation via create_texture_from_hal with content-controlled view_formats, enabling rgba32float views of bgra8unorm shared surfaces and GPU-process OOB read/write

Categories

(Core :: Graphics: WebGPU, defect, P1)

defect

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox-esr115 --- disabled
firefox-esr140 --- disabled
firefox-esr153 155+ fixed
firefox154 --- wontfix
firefox155 + fixed
firefox156 + fixed

People

(Reporter: tjr, Assigned: aleiserson)

References

Details

(5 keywords, Whiteboard: [adv-main155+r][adv-esr153.2+r])

Attachments

(9 files, 3 external files)

WebGPU swap-chain shared-texture: content-controlled view_formats / usage bypass wgpu-core validation via create_texture_from_hal → format-reinterpreted GPU texture view → OOB read/write in the GPU process

Classification

  • Attacker: compromised (or even unmodified) web content process (web / webIsolated=<site>).
  • Victim: GPU process (WebGPUParent / wgpu server / driver). On configurations where the
    compositor runs in the parent this executes in the parent, but per §4 of the threat-model
    reference this is a GPU-class finding (PWebGPU is managed under the compositor bridge;
    the server side runs where the compositor lives).
  • Severity: Content → GPU memory corruption + memory disclosure (moderate per the matrix;
    high practical value because it is a controlled GPU-memory OOB write and an OOB read
    primitive whose results are returned to attacker JS).
  • Platform gate: the vulnerable server logic is cross-platform, but the reachable backends
    are #ifdef/cfg-gated:
    • macOS: SharedTextureMacIOSurface + Metal (cfg(target_os = "macos"),
      create_texture_with_shared_texture_iosurface) — the primary target of this audit item;
    • Linux: SharedTextureDMABuf + Vulkan (cfg(target_os = "linux")) — same flaw;
    • Windows: SharedTextureD3D11 + DX12 (cfg(target_os = "windows")) — same flaw.
      This analysis host is Linux without any GPU/Vulkan ICD, so no WebGPU adapter exists at all
      (requestAdapter() → null; see blockers.yaml); empirical in-browser reproduction was
      impossible here. The core validation bypass was reproduced empirically against the exact
      vendored wgpu-core of this tree (see “Micro-repro” below).

The bug

Where the descriptor comes from (attacker-controlled metadata)

When a WebGPU canvas is configured, the content process sends
Message::CreateSwapChain (gfx/wgpu_bindings/src/lib.rs:301) carrying, among others:

  • texture_format: wgt::TextureFormat
  • usage: wgt::TextureUsages
  • view_formats: Vec<wgt::TextureFormat>

These are populated verbatim from the JS GPUCanvasConfiguration:

  • CanvasContext::Configure (dom/webgpu/CanvasContext.cpp:90) validates only format
    (rgba8unorm/bgra8unorm). It performs no validation of viewFormats (the WebGPU spec
    requires each view format to be texture-view-format-compatible with format, i.e. only the
    srgb variant — Firefox never checks this anywhere on this path).
  • Device::SwapChainTextureDescriptor (dom/webgpu/Device.cpp:109) copies
    aConfig.mViewFormats and aConfig.mUsage into the descriptor.
  • Device::InitSwapChain (dom/webgpu/Device.cpp:1008) forwards them to
    wgpu_client_create_swap_chain (gfx/wgpu_bindings/src/client.rs:904), which puts them into
    the IPC message unchanged.

In the GPU process, Message::CreateSwapChain handling (server.rs:3111) stores them in the
canonical SwapChainConfig (server.rs:142). SwapChainConfig::to_texture_descriptor()
(server.rs:150) pins size/mip/sample/dimension (this was the bug-2050871 hardening) but
passes through format, usage and view_formats untouched.

Where validation is skipped (the twin-path flaw)

DeviceAction::CreateTexture with a swap_chain_id (server.rs:2080) replaces the client desc
with the canonical one, then — because the swap chain uses shared textures
(default on macOS/Windows/Linux-dmabuf; dom.webgpu.allow-present-without-readback defaults to
true on those platforms) — calls the platform path, e.g. macOS
create_texture_with_shared_texture_iosurface (server.rs:3670):

  1. WebGPUParent::EnsureSharedTextureForSwapChain creates the IOSurface via
    SharedTexture::Create → SharedTextureMacIOSurface::Create
    (dom/webgpu/SharedTexture.cpp:39, dom/webgpu/SharedTextureMacIOSurface.cpp:15) —
    BGRA, width×height, 4 bytes/texel.
  2. A Metal texture wrapping the IOSurface is created with hardcoded
    MTLPixelFormat::BGRA8Unorm, Type2D, usage RenderTarget|ShaderRead|PixelFormatView
    (server.rs:3722-3737).
  3. The wgpu-core texture is registered via the unsafe, validation-free
    Global::create_texture_from_hal (server.rs:3769,
    wgpu-core/src/device/resource.rs:1407) with the attacker's usage and view_formats
    in the descriptor
    .

create_texture_from_hal(_inner) performs none of device_create_texture's checks. In
particular it skips the view-format compatibility check
(wgpu-core/src/device/resource.rs:1852-1861):

if desc.format.remove_srgb_suffix() != format.remove_srgb_suffix() {
    return Err(CreateTextureError::InvalidViewFormat(*format, desc.format));
}

Its safety contract — “hal_texture must be created respecting desc” — is violated: the hal
texture is a fixed BGRA8 (4 B/px) 2D surface, while desc.view_formats may say
[Rgba32Float] (16 B/px) and desc.usage may claim capabilities the Metal/Vulkan object was
not created with.

Where the poisoned descriptor is consumed

Global::texture_create_view (wgpu-core/src/device/resource.rs:2124-2139) trusts the
descriptor:

let format_is_good = resolved_format == texture.desc.format
    || texture.desc.view_formats.contains(&resolved_format);

So content sends TextureAction::CreateView(view_id, { format: Some(Rgba32Float) }) (plain JS:
getCurrentTexture().createView({format:'rgba32float'}) — there is no client/DOM-side
validation either, dom/webgpu/Texture.cpp:49, client.rs:1089) and wgpu-core accepts it and
calls wgpu-hal:

  • Metal (wgpu-hal/src/metal/device.rs:616):
    newTextureViewWithPixelFormat:RGBA32Float ... on the BGRA8Unorm IOSurface texture. Metal
    requires view formats to be per-texel-size compatible; violating this without the (disabled in
    release) validation layer is undefined behavior — the returned view addresses
    width×height×16 bytes over a width×height×4-byte IOSurface. (If Metal returns nil the
    .unwrap() panics = GPU-process abort, still a content-triggered DoS.)
  • Vulkan (wgpu-hal/src/vulkan/device.rs:1258): vkCreateImageView with
    VK_FORMAT_R32G32B32A32_SFLOAT on a B8G8R8A8_UNORM image created without
    VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT (dmabuf import at server.rs:1903 uses only
    ALIAS) — violates VUID-VkImageViewCreateInfo-image-01019/01762 → UB; drivers create the
    view and address per the view format's texel size → OOB.
  • DX12: SRV/RTV with a format outside the resource's cast family → UB, same shape.

Primitives

With the rgba32float view of the 4-B/px swap-chain surface:

  • OOB write: render pass (view as color attachment) or clear — GPU writes
    W*H*16 bytes into a W*H*4 allocation with attacker-chosen 128-bit fill; ~75 % of the
    writes land beyond the IOSurface/VkImage allocation, corrupting adjacent GPU-accessible
    memory of the GPU process (other surfaces, heaps).
  • OOB read + exfiltration: bind the view (sampleType:'unfilterable-float') and
    textureLoad every texel into a storage buffer, copy to a MAP_READ buffer, mapAsync,
    read in JS → discloses memory beyond the surface (other tabs' surface contents, GPU heap
    data) to web content.

Secondary variant (same root cause): the attacker-controlled usage is also installed without
validation, so wgpu-core lets content use the swap-chain texture in ways the underlying
Metal texture (RenderTarget|ShaderRead|PixelFormatView, no ShaderWrite) / VkImage
(only COLOR_ATTACHMENT) was never created for (e.g. STORAGE_BINDING writes,
COPY_DST blits) — further API-contract UB.

Note this is exactly the “same check present in one path but missing in its twin” +
“descriptor trusted over the mapping” patterns: device_create_texture validates,
create_texture_from_hal (used only for shared swap-chain textures — the very surface of
this audit item) does not.

Reachability

  • Requires: WebGPU enabled (dom.webgpu.enabled; default in release on Windows, Nightly on
    macOS/Linux), a hardware adapter, and the shared-texture swap chain
    (dom.webgpu.allow-present-without-readback — default true on Win/macOS/Linux;
    support_use_shared_texture_in_swap_chain — true on macOS Metal hardware, Windows DX12
    hardware, Linux Vulkan with dmabuf extensions).
  • No compromised renderer is strictly required: viewFormats flows from plain JS with no
    validation at any layer (checked: CanvasContext::Configure, Device::InitSwapChain,
    wgpu_client_create_swap_chain, Message::CreateSwapChain handler, to_texture_descriptor,
    create_texture_from_hal, texture_create_view). The included exploit.patch additionally
    injects the poisoned view format from a (modeled) compromised content process at the client
    FFI boundary, XRE_IsContentProcess()-guarded, to keep the PoC working even if DOM-side
    spec validation is added later.

Why not reproduced empirically here

  • Primary backend is macOS-only (#ifdef XP_MACOSX, cfg(target_os="macos"),
    dom/webgpu/SharedTextureMacIOSurface.cpp); this host is Linux.
  • The Linux sibling (SharedTextureDMABuf + Vulkan) has the same flaw, but this host has no
    GPU, no /dev/dri, no Vulkan ICD (not even lavapipe)
    and
    server.rs hardcodes Backends::PRIMARY, so requestAdapter() returns null and no
    WebGPU path can execute (verified again with browser_evaluator in this session:
    [PoC] no WebGPU adapter on this machine). Recorded in blockers.yaml.

Micro-repro (executed here, against this tree's vendored wgpu-core)

micro_repro/ builds a small Rust program (cargo build --offline, vendored deps from
/firefox/third_party/rust) that uses wgpu-core's noop hal backend in place of Metal/Vulkan
and performs exactly the calls Firefox's GPU process performs:

[1] device_create_texture (validated path) REJECTS the descriptor:
    The view format Rgba32Float is not compatible with texture format Bgra8Unorm, only changing srgb-ness is allowed.
[2] create_texture_from_hal (swap-chain path) ACCEPTS the same descriptor: validation BYPASSED
[3] texture_create_view(format=Rgba32Float) on the Bgra8Unorm swap-chain texture SUCCEEDS.
    => wgpu-hal now holds a 16-byte/texel view of a 4-byte/texel surface.
[4] Control: same view on a texture without poisoned view_formats is rejected as expected:
    Trying to create a view of format Rgba32Float of a texture with format Bgra8Unorm, but this view format is not present in the texture's viewFormat array

This proves, on this exact code revision, that the incompatible-format view object is created
and handed to wgpu-hal; on real backends that call is
newTextureViewWithPixelFormat:/vkCreateImageView on the shared swap-chain surface.

Reproduction on the target OS (macOS)

  1. Nightly/ASAN build of this tree on macOS (Metal hardware; defaults suffice:
    dom.webgpu.enabled=true on Nightly, dom.webgpu.allow-present-without-readback=true).
  2. Optionally git apply exploit.patch (not required today; see above) and rebuild.
  3. Load testcase.html.
  4. Expected observations, in order of likelihood:
    • GPU-process crash (Metal/driver fault or GPU command-buffer error → device loss) during
      the clear/dispatch on the oversized view; under ASAN/GuardMalloc, an OOB write report if
      the IOSurface mapping is CPU-shadowed;
    • or the page logs non-zero “OOB words” — memory disclosed from beyond the 256 KiB
      IOSurface into JS (check first OOB words line);
    • if Metal returns nil for the incompatible view: Rust panic
      called Option::unwrap() on a None value in
      wgpu-hal/src/metal/device.rs:678 (create_texture_view) — GPU-process abort, proving
      the incompatible view request reached the driver.
  5. Linux variant: any Vulkan-capable machine with dmabuf (GBM_FORMAT_ARGB8888 modifiers);
    same testcase; the vkCreateImageView UB typically yields RADV/ANV OOB addressing.

Suggested fix

  • Run full descriptor validation for swap-chain textures: either call the same checks as
    device_create_texture before create_texture_from_hal, or sanitize
    SwapChainConfig::view_formats (allow only the srgb variant of format) and usage
    (mask to what the hal texture was actually created with) in the
    Message::CreateSwapChain handler — server-side, since the values are content-controlled.
  • Additionally validate GPUCanvasConfiguration.viewFormats in CanvasContext::Configure
    per spec (defense in depth; returns proper TypeError to JS).

Files

  • testcase.html — plain-JS PoC (configure poisoned viewFormats → rgba32float view →
    OOB-write render pass + OOB-read compute/textureLoad exfiltration).
  • exploit.patch — compromised-content-process variant (guarded by
    XRE_IsContentProcess()), injects the poisoned view format in
    Device::InitSwapChain; verified to compile against this tree (ASAN build).
  • micro_repro/Cargo.toml, micro_repro/src/main.rs, micro_repro/cargo-config.toml —
    the executed validation-bypass proof against the vendored wgpu-core.
Attached file crash_stack.txt —
Attached patch exploit.patch — — Splinter Review
Attached patch fix.patch — — Splinter Review
Attached file Cargo.toml —
Attached file cargo-config.toml —
Attached file main.rs —
Attached file testcase.html —
Attached file blockers.yaml —
Attached file output.txt —

This bug was filed automatically by an AI-powered security testing tool. The analysis, testcase, and any suggested patches were generated by an AI model and have NOT been verified by a human.

Please review all details carefully before triaging. The issue was confirmed by an independent verifier, but for non-ASAN issues, the verifier has been made less strict. Additionally, the root cause analysis and suggested fix may contain errors.

Group: core-security → gfx-core-security
Severity: -- → S2

sec-high = P1

Priority: -- → P1
Assignee: nobody → aleiserson
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
See Also: → 2050871

Needs https://github.com/gfx-rs/wgpu/commit/d5d8ed84c88f553c5d5eed35e3033f18b9f6bc6b (2026-08-03), plus an additional Firefox change.

Depends on: webgpu-update-wgpu
Attached file (secure) —

:aleiserson, please update all release status flags to reflect the affected/unaffected/disabled state correctly. Which branches (beta, release, and/or ESR) are affected by this flaw?

Flags: needinfo?(aleiserson)
Group: gfx-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch

The patch landed in nightly and beta is affected, along with ESR.
:aleiserson, is this bug important enough to require an uplift?

For more information, please visit BugBot documentation.

Flags: needinfo?(aleiserson)

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: Adds validation to protect against a compromised content process, should not affect normal cases.
  • String changes made/needed?: n/a
  • Is Android affected?: no
Attachment #9627961 - Flags: approval-mozilla-beta?

Requested beta uplift. ESR153 uplift is needed as well, but a wgpu revendor (bug 2064236) is required first.

Attachment #9627961 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
QA Whiteboard: [sec] [uplift] [qa-triage-done-c156/b155]

This still requires an esr153 uplift of the Firefox-side change, but it's tied up with CTS expectation updates and bug 2059599. I am working on it.

Attached file (secure) —
Attachment #9629637 - Flags: approval-mozilla-esr153?

firefox-esr153 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: Adds validation to protect against a compromised content process, should not affect normal cases.
  • String changes made/needed?: n/a
  • Is Android affected?: no
Flags: needinfo?(aleiserson)
Attachment #9629637 - Flags: approval-mozilla-esr153? → approval-mozilla-esr153+
Whiteboard: [adv-main155+r][adv-esr153.2+r]
See Also: → 2071219
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: