From c8e3ca06c3a43610b4870486febf72513d0758e3 Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 23 Nov 2026 18:20:29 -0500 Subject: [PATCH] DirectStorage: EnqueueRequest reads its page array and file vtable without sizing regions EnqueueRequest checked the destination page array and the file object with gpu::shader::readable, which calls VirtualQuery for each region the range touches. VirtualQuery sizes a region by walking it, and a retail title keeps those arrays inside very large reservations with scattered committed pages, so the check costs far more than the read. While the title streams its world it enqueues thousands of requests a second, on one of its threads. The two reads are now ReadProcessMemory on the current process: it copies the bytes or fails on memory that is not readable, which is what the check was for, without sizing the region around them. --- crates/xcl/src/hle/dstorage.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/xcl/src/hle/dstorage.rs b/crates/xcl/src/hle/dstorage.rs index 64f9ee1c8..2a6300541 100644 --- a/crates/xcl/src/hle/dstorage.rs +++ b/crates/xcl/src/hle/dstorage.rs @@ -706,10 +706,18 @@ unsafe fn snapshot_page_array(ptr: u64, offset: u16, byte_len: u32) -> Result()) else { return Err(E_ACCESS_VIOLATION); }; - if !crate::gpu::shader::readable(ptr as usize, bytes) { + let mut pages = vec![0usize; count]; + if !read_own(ptr as usize, pages.as_mut_ptr() as *mut u8, bytes) { return Err(E_ACCESS_VIOLATION); } - Ok(std::slice::from_raw_parts(ptr as *const usize, count).to_vec()) + Ok(pages) +} + +unsafe fn read_own(at: usize, out: *mut u8, len: usize) -> bool { + use windows_sys::Win32::System::Diagnostics::Debug::ReadProcessMemory; + use windows_sys::Win32::System::Threading::GetCurrentProcess; + let mut done = 0usize; + at != 0 && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out as *mut c_void, len, &mut done) != 0 && done == len } /// Whether `n` bytes at `p` are committed, writable memory. @@ -1208,7 +1216,8 @@ unsafe extern "system" fn queue_enqueue_request(p: *mut c_void, req: *const u8) } else { // only a file this factory opened let f = r.source as *mut c_void; - if !crate::gpu::shader::readable(f as usize, 8) || *(f as *const *const usize) != file_vtbl().as_ptr() { + let mut vt = 0usize; + if !read_own(f as usize, &mut vt as *mut usize as *mut u8, 8) || vt != file_vtbl().as_ptr() as usize { return q.enqueue(Entry::Refused { hr: E_FILE_HANDLE, req: r, file: None, fill: None }); } Some(Arc::clone(inner::(f)))