[4] ANGLE Metal backend out-of-bounds vertex fetch for converted attributes
ANGLE's front-end approved the WebGL2 draw. Metal then read past the buffer.
Rated Medium: WebGL2 content can make the GPU fetch tens of bytes past the end of a vertex buffer, but the read is bounded and read-only. Whether it becomes a leak depends on what is allocated next to the buffer and how the GPU treats out-of-range fetches.
WebGL on Apple platforms is implemented by translating OpenGL ES into Metal, and every draw is validated once by a front-end before a backend turns it into native GPU bindings. In ANGLE, the GL-to-native translation library WebKit embeds, VertexArrayMtl (the Metal backend's vertex-array state) may store a vertex attribute in a wider actual format than the GL type the page declared, converting the data into a new buffer when Metal cannot fetch the original directly. The backend is expected to fetch only within the bytes the front-end measured when it admitted the draw.
The angle: a WebGL2 page with a packed vertex attribute in a buffer sized to the last byte can get a front-end-approved draw executed as a GPU read past the end of that buffer, with the in-bounds bytes misread as floats.
[ANGLE] Metal backend: Fix OOB vertex fetch for converted attributes in syncDirtyAttrib
VertexArrayMtl::syncDirtyAttribsizes its buffer-capacity check with the actual Metal format rather than the GL attribute's type size. The two agree for natively supported formats, but the actual format is widened whenever the attribute needs conversion:R10G10B10A2_SSCALEDis emulated asR32G32B32A32_FLOAT, 4 bytes becoming 16.GetVertexCountthen subtracts 16 from a buffer that only has to hold 4 bytes per vertex, the subtraction underflows, and a buffer holding a legal number of vertices reports zero. Zero takes thenumVertices == 0branch, which is tested beforeneedConversion, so the attribute skipsconvertVertexBufferand the raw GL buffer is bound with the widened descriptor at a stride of 16. That fallback relied onKHR_robust_buffer_access_behaviorclamping the fetch, which Metal does not expose, while the front-end admitted the draw because it measures the same attribute at 4 bytes. The GPU reads past the end of the buffer, and misreads the packed bits as floats even for the in-bounds vertex. The size basis changed in 314003@main, which hoisted this check out ofconvertVertexBufferso it would cover the non-conversion path too.Count with
gl::ComputeVertexAttributeTypeSize(attrib)instead, the call the front-end uses to computeVertexAttribute::mCachedElementLimit. Every other backend already passes this value to its equivalent check. Also stop thenumVertices == 0fallback from binding the source buffer with a fabricated stride; leave the attribute unbound sosetupDrawsupplies the default attribute value, and clear the inline data pointer so a stale client array cannot be picked up instead.
Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/VertexArrayMtl.mm
Source/ThirdParty/ANGLE/src/tests/gl_tests/VertexAttributeTest.cpp
Patch Details
rx::VertexArrayMtl::syncDirtyAttrib changes in two places. The size passed to GetVertexCount(bufferMtl, binding, srcFormatSize) is now gl::ComputeVertexAttributeTypeSize(attrib), the GL attribute's own type size, instead of format.actualAngleFormat().pixelBytes, the size of the emulated Metal format. The numVertices == 0 branch no longer binds the source buffer: it sets mCurrentArrayBuffers[attribIndex] to nullptr, clears mCurrentArrayInlineDataPointers and mCurrentArrayInlineDataSizes, points mCurrentArrayBufferFormats at the FormatID::NONE vertex format, and sets offset and stride to 0. In the test file, a Pack2101010Rev helper and GL_INT_2_10_10_10_REV stride entry are added, along with signed normalized/unnormalized INT_2_10_10_10_REV tests and the regression test PackedIntRevBufferWithNoSlack, which draws three packed vertices from a 12-byte buffer with no slack.
Validator and backend measuring one element with different size bases, so a widened format underflows the capacity check and routes the draw to an unconverted fallback.
Background
Vertex attribute fetch.
A WebGL draw reads per-vertex attributes from a bound buffer. Each attribute is described by a component type (such as GL_FLOAT or GL_INT_2_10_10_10_REV), a component count, a stride (bytes between vertices, 0 meaning tightly packed), and an offset into the buffer. GL_INT_2_10_10_10_REV packs three signed 10-bit channels and one signed 2-bit channel into one 4-byte word and is available in OpenGL ES 3.0 and WebGL2.
Front-end and backend.
ANGLE's front-end (libANGLE) validates every draw; one check compares the requested vertex range against VertexAttribute::mCachedElementLimit, a per-attribute bound derived from buffer size, offset, stride and gl::ComputeVertexAttributeTypeSize(attrib) (per the added comment). The backend (renderer/metal) then translates validated state into native bindings.
Intended vs. actual format.
Each ANGLE format has an intended format (what GL specified) and an actual format (what the native API uses). When Metal cannot fetch a format directly, the backend picks a wider actual format and converts the data into a new buffer. actualAngleFormat().pixelBytes is the per-element size of the actual format.
GetVertexCount.
A helper in VertexArrayMtl.mm that computes how many whole vertices fit in a binding, using angle::CheckedNumeric<size_t> and returning 0 if any subtraction underflows.
KHR_robust_buffer_access_behavior and default attributes.
The extension guarantees that out-of-bounds buffer reads return zero or values from inside the buffer, never outside it, so a backend on a robustness-enforcing API can treat an out-of-range fetch as safe. When an attribute array is disabled or unbound, the shader receives the current generic attribute value (set by glVertexAttrib4f and similar); per the patch's added comment, in the Metal backend setupDraw() supplies it when the attribute is left unbound.
Analysis
The front-end and the Metal backend measured the same attribute in two different units, and the mismatch routed a legal draw into a fallback that bound real memory.
Before: After:
GetVertexCount(size=16) (actual format) GetVertexCount(size=4) (GL type size)
12 - 16 underflows -> 0 12 bytes -> 3 vertices
numVertices == 0 (tested before conversion) needConversion
bind raw 12-byte buffer convertVertexBuffer -> R32G32B32A32
format R32G32B32A32_FLOAT, stride 16 fetch from converted buffer
GPU fetches 16 B/vertex -> past end numVertices == 0 (truly too small)
unbind; setupDraw default value
On the left, GetVertexCount computes bytes = size - bindingOffset - srcFormatSize with checked arithmetic and returns 0 on underflow. With srcFormatSize at 16 (the widened R32G32B32A32_FLOAT), any binding with fewer than 16 usable bytes reports zero vertices, even though the front-end, measuring at 4 bytes, has admitted up to three. Because numVertices == 0 is tested before needConversion, conversion is skipped and the raw buffer is bound with the widened descriptor at a fabricated stride of 16. That branch's comment (can return any values. See KHR_robust_buffer_access_behavior) treated the fetch as benign; the commit message states Metal does not expose that extension, and the new test's comment describes the binding as "misreading the packed bits as floats and fetching past the end of the buffer." Two failures follow: an out-of-bounds read past the source buffer, and misinterpretation of in-bounds packed bits as IEEE floats.
The commit message attributes the size-basis change to 314003@main, which hoisted the check out of convertVertexBuffer to cover the non-conversion path. convertVertexBuffer measured the intended format; the hoisted copy picked up the format local, which in syncDirtyAttrib refers to the actual format.
The regression test shows exactly the shape needed: a 12-byte buffer holding three GL_INT_2_10_10_10_REV vertices with no slack, an unnormalized attribute (which needs conversion), and glDrawArrays(GL_TRIANGLES, 0, 3). Before the fix it failed at every pixel, including the in-bounds ones.
Exploitability: reachable from web content through WebGL2 with a buffer-backed, unnormalized GL_INT_2_10_10_10_REV attribute whose usable bytes after the offset are fewer than 16, followed by a draw the front-end admits. The GPU then fetched up to about 36 bytes past the end of the binding. The confirmed effect is wrong rendering plus an out-of-bounds GPU read. The read is read-only and bounded to tens of bytes, and the values reach only the vertex shader as float inputs. Escalation to a meaningful leak hinges on the BufferMtl allocation model. If WebGL buffers are sub-allocated from a shared pool, the bytes past the end could belong to another WebGL buffer, possibly from another context or origin, and could be routed through the vertex shader into rendered pixels or transform feedback and read back with readPixels. If they are standalone page-backed allocations, the over-read would land in padding or fault on the GPU. ANGLE typically runs in the GPU process on current Apple platforms, so any leaked bytes would come from GPU-process Metal allocations.
Before the fix, this vulnerability weakened memory safety at the WebGL/GPU boundary. WebGL relies on front-end validation meaning the backend only fetches within the bound buffer, and the Metal backend broke that for converted packed attributes. Whether Apple GPU hardware clamps or zero-fills such fetches is open. If the over-read returns real contents of adjacent GPU allocations and those can be made visible through rendering and readback, the vulnerability could expose a small, bounded cross-allocation information leak in the process hosting ANGLE.
Takeaway: a backend's capacity check should be the same measurement as the front-end bound that admitted the draw; when a translation layer widens a format, any bound computed in native units downstream of validation is a mismatch waiting to happen.
Audit directions
- Front-end validation and backend enforcement measuring one element with different size bases. The bound a backend enforces must be computed from the same quantity the validator admitted. Narrow: grep
Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/foractualAngleFormat().pixelBytesin size, count, or offset arithmetic, starting with the rest ofVertexArrayMtl.mmand index-buffer handling; match tell: a capacity computation using the actual format's size where the GL validator usedComputeVertexAttributeTypeSizeor the intended format. Wider: the same mismatch through index-type expansion during index streaming, emulated texture formats (RGB8 stored as RGBA8) in upload or copy sizing, and Vulkan vertex conversion inVertexArrayVk; match tell: a function where the validated size and the native size are both in scope and the arithmetic mixes them. Widest: any portability layer with format emulation, such as Dawn, MoltenVK, DXVK/VKD3D, or Mesa's gallium format fallbacks; ask whether every bounds check downstream of validation still measures in API units when the emulated format is wider. - Degenerate-case fallbacks that "can return any value" by assuming native clamping. A robustness guarantee is a property of the target API and hardware, not of the GL spec being emulated. Narrow: grep ANGLE's Metal backend for
KHR_robust_buffer_access_behavior,can return any values, and fabricated stride or offset constants in out-of-bounds branches, and check whether each still binds real memory. Wider: WebKit's WebGPU implementation on Metal and any shader-side bounds emulation in translated MSL; check whether every fallback either clamps explicitly or binds nothing. Widest: any translation layer mapping a robust API onto a possibly non-robust one, such as MoltenVK'srobustBufferAccessemulation; match tell: an out-of-bounds path that still issues a native fetch or bind against the original resource, next to a comment saying the result is unspecified. - A check hoisted into a shared caller that reads a same-typed but semantically different local. Here, the actual format instead of the GL attribute's type size. Narrow: review the other branches of
VertexArrayMtl::syncDirtyAttriband compare every size argument against the measurement the conversion path uses for the same attribute. Wider: hardening commits in ANGLE and WebCore that "unify" a check across paths; look for diffs where a bound moves up a call level and is fed a variable with different provenance. Widest: any codebase where refactors deduplicate validation, such as kernel ioctl handlers consolidating size checks or parsers hoisting length validation; match tell: a moved check whose operands have the same type but different meaning (pre- vs. post-conversion size, element count vs. byte count). - Struct-of-arrays binding caches where one branch updates only some parallel fields. Every branch that assigns a slot must assign every parallel field for that slot. Narrow: in
VertexArrayMtl::syncDirtyAttrib, check that every branch writes all ofmCurrentArrayBuffers,mCurrentArrayInlineDataPointers,mCurrentArrayInlineDataSizes,mCurrentArrayBufferFormats,mCurrentArrayBufferOffsets, andmCurrentArrayBufferStrides, then trace howsetupDraw()chooses between buffer and inline data. Wider: equivalent per-attribute and per-binding caches in other ANGLE backends and WebKit's GPU-process remote rendering state mirrors. Widest: any renderer or driver state tracker built from parallel arrays, such as Mesa state trackers and Chromium's GPU command-buffer client state; match tell: a branch that nulls a pointer field but not its sibling length or alternate-source field, where a consumer checks the siblings in priority order.