GPU: harden CopyMemoryToMemoryX against unmapped or read-only pages #2299
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2299
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@denkencar-sketch on GitHub · 2026-11-25 10:05 UTC · original
denkencar-sketch:fix/list-003→main· +63 −8 · 1 files · 1 commits · openCrash-hardening for \CopyMemoryToMemoryX\ at submission:
@Marvisak on GitHub · 2026-11-25 15:25 UTC · original · edited 2026-11-26 00:20 UTC
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
@denkencar-sketch on GitHub · 2026-11-25 23:38 UTC · original
Addressed both triage points and rebased onto current \main\ (\
842b0cb):@catminou4 on GitHub · 2026-11-25 10:19 UTC · original · reviewed
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.
@fuzeofficlal on GitHub · 2026-11-26 19:51 UTC · original · requested changes
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).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.