Textures: safe texture::uma_bytes constructs &'static [u8] over uncommitted sparse UMA windows #1393

Open
opened 2026-11-26 04:52:42 +00:00 by github-bot · 0 comments
Owner

@⁠microwave805 on GitHub · 2026-11-24 15:31 UTC · original

Checked on main (930e8b4).

Problem

Safe pub fn texture::uma_bytes (crates/xcl/src/gpu/texture.rs:123-132) constructs a &'static [u8] via std::slice::from_raw_parts after checking only !u.contains(a) || !u.contains(end - 1):

pub fn uma_bytes(t: &Image, cfg: PipeConfig) -> Result<&'static [u8], String> {
    let p = placement(t, cfg)?;
    let u = super::uma::get().ok_or("no UMA")?;
    let (a, end) = checked_span(p.start, p.bytes)?;
    if !u.contains(a) || !u.contains(end - 1) {
        return Err(format!("texture {a:#x}+{:#x} outside UMA", p.bytes));
    }
    // SAFETY: inside the UMA reservation, which lives for the whole process
    Ok(unsafe { std::slice::from_raw_parts(a as *const u8, p.bytes) })
}
  1. Uma::contains(p) (crates/xcl/src/gpu/uma.rs:479-481) returns true for uncommitted WindowKind::Sparse windows reserved only with MEM_RESERVE (uma.rs:174, 216). Reading the returned slice triggers an immediate STATUS_ACCESS_VIOLATION.
  2. Checking a and end - 1 independently allows spans that start in one UMA window and end in another across uncommitted/unmapped gaps.
  3. Forging &'static [u8] over guest-mutable UMA memory violates Rust's shared-reference immutability invariant (UB).

(Note: uma_bytes currently has no internal callers in crates/xcl/src, so this is a latent soundness bug in a safe public API.)

Suggested fix

Validate that the entire [a, end) range is committed and readable within a single window (e.g., via shader::readable / VirtualQuery per page) and copy into an owned Vec<u8> instead of returning &'static [u8].


AI use: Antigravity (Gemini 4 Neon) performed the read-only source audit and drafted this issue; checked and verified on 930e8b4 before opening.

**@⁠microwave805** on GitHub · 2026-11-24 15:31 UTC · [original](https://github.com/xcl-dev/xcl/issues/1393) Checked on `main` (`930e8b4`). ### Problem Safe `pub fn texture::uma_bytes` (`crates/xcl/src/gpu/texture.rs:123-132`) constructs a `&'static [u8]` via `std::slice::from_raw_parts` after checking only `!u.contains(a) || !u.contains(end - 1)`: ```rust pub fn uma_bytes(t: &Image, cfg: PipeConfig) -> Result<&'static [u8], String> { let p = placement(t, cfg)?; let u = super::uma::get().ok_or("no UMA")?; let (a, end) = checked_span(p.start, p.bytes)?; if !u.contains(a) || !u.contains(end - 1) { return Err(format!("texture {a:#x}+{:#x} outside UMA", p.bytes)); } // SAFETY: inside the UMA reservation, which lives for the whole process Ok(unsafe { std::slice::from_raw_parts(a as *const u8, p.bytes) }) } ``` 1. `Uma::contains(p)` (`crates/xcl/src/gpu/uma.rs:479-481`) returns `true` for **uncommitted `WindowKind::Sparse` windows** reserved only with `MEM_RESERVE` (`uma.rs:174, 216`). Reading the returned slice triggers an immediate `STATUS_ACCESS_VIOLATION`. 2. Checking `a` and `end - 1` independently allows spans that start in one UMA window and end in another across uncommitted/unmapped gaps. 3. Forging `&'static [u8]` over guest-mutable UMA memory violates Rust's shared-reference immutability invariant (UB). *(Note: `uma_bytes` currently has no internal callers in `crates/xcl/src`, so this is a latent soundness bug in a safe public API.)* ### Suggested fix Validate that the entire `[a, end)` range is committed and readable within a single window (e.g., via `shader::readable` / `VirtualQuery` per page) and copy into an owned `Vec<u8>` instead of returning `&'static [u8]`. --- **AI use:** Antigravity (Gemini 4 Neon) performed the read-only source audit and drafted this issue; checked and verified on `930e8b4` before opening.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:52:42 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.