GPU: harden CopyMemoryToMemoryX against unmapped or read-only pages #2297
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2299"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T10:05:34Z.
Crash-hardening for \CopyMemoryToMemoryX\ at submission:
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T10:19:16Z.
Review: COMMENTED
CopyMemoryToMemoryX copies through the kernel (memmove semantics, partial writability) instead of ptr::copy. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Safer copy path for title memory.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:25:48Z.
Automated triage for the maintainers.
Merge candidate.
copy_memoryincrates/victory-gpu/src/list.rsnow defers tocopy_title_memory, which checks the source withtexture::committed, copies disjoint ranges straight throughhost::write_mappedunderwatch::writing(no buffer, one pass), and stages through a buffer only when the ranges overlap, somemmoveorder is kept. Both points from the last triage are addressed: the description is now framed as crash hardening, and the per-copy allocation is gone for the common disjoint case. A destination page the title made read-only is now skipped rather than faulting; that is a hardening trade-off the maintainer may want to note.On your reply: confirmed in the diff, both changes are there. CI: passing.
Generated by Claude Code
[PR #2299] GPU: CopyMemoryToMemoryX copies through the kernel and tells the write watchersto [PR #2299] GPU: harden CopyMemoryToMemoryX against unmapped or read-only pagesImported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T23:38:07Z.
Addressed both triage points and rebased onto current \main\ (\
842b0cb):Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:51:55Z.
Review: CHANGES_REQUESTED
Tested
2caaace8bf066394b321ff1b88ef8fa705e435c3merged ontoorigin/main(63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP,--features diagnostics, Rust 1.98.1 MSVC).Verified the positive cases cleanly: disjoint copies, overlapping (
memmove) copies,PAGE_READONLYdestinations, huge sizes, and copying between twowatch-guarded (PAGE_READONLY) pool pages (confirmingtexture::committedacceptswatch-guardedsrcandwatch::writingopens and dirtiesdst).Blocking Regression: high-address
dstoverflowshost::for_pieces(panic in debug/diag builds, infinite wraparound loop in release builds)On
origin/main,copy_memoryguarded bothsrcanddstwithcrate::texture::committed, which rejected overflowing and top-of-address-spacedstranges (committed(usize::MAX - 4, 16) == false,committed(usize::MAX - 100, 16) == false).In this PR,
copy_title_memory(crates/victory-gpu/src/list.rs:1104-1124) removescommitted(dst, len)and callscrate::host::write_mapped(dst as *mut u8, ...)directly. Whensrcis valid committed memory anddstis nearusize::MAX, the whole-rangeReadProcessMemoryfails and falls intohost::for_pieces(crates/victory-gpu/src/host.rs:2576-2584), which has two unchecked overflows:dst + lenoverflows (dst = usize::MAX - 4,len = 16):host.rs:2577(let end = start + len;) panics in debug/diag builds:panicked at crates\victory-gpu\src\host.rs:2577:15: attempt to add with overflowdstlies inside the top 64 KiB withoutdst + lenoverflowing (dst = usize::MAX - 100,len = 16):host.rs:2580(let next = ((at / step + 1) * step).min(end);) panics in debug/diag builds:panicked at crates\victory-gpu\src\host.rs:2580:20: attempt to multiply with overflow--releasebuilds (wrapping arithmetic),(at / 65536 + 1) * 65536wraps to0, sonext = 0.min(end) = 0andatresets to0, turningwhile at < endinto a2^48-iteration loop that hangs the submission thread indefinitely while callingReadProcessMemoryacross the entire 64-bit address space.Suggested Fix
copy_title_memory(crates/victory-gpu/src/list.rs:1105):for_pieces(crates/victory-gpu/src/host.rs:2576-2584) overflow-safe at the top of the address space:Verified this fix locally in both
--features diagnostics(debug) and--releasebuilds:copy_title_memoryreturns instantaneously with zero panics or wraparound fordst = usize::MAX - 4,usize::MAX - 100, andusize::MAX - 4095, while alllist::testsandhost::title_copiestests pass (4/4in0.00s).Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T21:50:02Z.
Review: APPROVED
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).CopyMemoryToMemoryXagainst unmapped or read-only pages prevents faults cleanly.cargo test -p victory-gpu --lib list:: -- --test-threads=1: 5 passed, 0 failed (includingmemory_copies_do_not_fault_on_read_only_destinations).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.