GPU: a plain heap description is not read past its 16 bytes without checking they are mapped #2276

Open
denkencar-sketch wants to merge 1 commit from upstream-pr/2278 into main
denkencar-sketch commented 2026-11-25 09:29:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T09:29:07Z.


Summary

A plain heap description was read past its 16 bytes without checking they are mapped, so an older title's description at the end of its memory faulted. The placement of a newer title's extended description is now read through the kernel.

Testing

Test a_plain_description_at_the_end_of_mapped_memory_is_read_whole crashes (0xc0000005) on main and passes with this change. cargo test --workspace --locked passes apart from the known flakes: modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too, and so does a parallel-run flake in victory-gpu's lib tests (watch:: and descriptor::host:: tests, 2 of 40 runs on pristine main).

Not tried: the non-Windows path (unchanged), and a run in the game.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6601358475 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2278). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T09:29:07Z. --- ## Summary A plain heap description was read past its 16 bytes without checking they are mapped, so an older title's description at the end of its memory faulted. The placement of a newer title's extended description is now read through the kernel. ## Testing Test `a_plain_description_at_the_end_of_mapped_memory_is_read_whole` crashes (`0xc0000005`) on `main` and passes with this change. `cargo test --workspace --locked` passes apart from the known flakes: `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too, and so does a parallel-run flake in `victory-gpu`'s lib tests (`watch::` and `descriptor::host::` tests, 2 of 40 runs on pristine `main`). Not tried: the non-Windows path (unchanged), and a run in the game. AI-assisted.
catminou4 commented 2026-11-25 10:07:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T09:35:46Z.

Review: COMMENTED


A plain heap description is not read past its 16 bytes: placement_after() probes with read_into on Windows instead of a blind unaligned read. 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. Defensive fix for titles passing stack/data as HeapDesc; the non-Windows fallback still does the blind read (noted, Windows-only crate anyway).

<!-- greyfinch-sync:Marvisak/VIctory:review:6055075875 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2278#pullrequestreview-6055075875). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T09:35:46Z. **Review:** COMMENTED --- A plain heap description is not read past its 16 bytes: placement_after() probes with read_into on Windows instead of a blind unaligned read. 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. Defensive fix for titles passing stack/data as HeapDesc; the non-Windows fallback still does the blind read (noted, Windows-only crate anyway).
DenRakEiw commented 2026-11-25 10:07:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T09:42:35Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib descriptor::tests:: — 6 passed, 0 failed (including a_plain_description_at_the_end_of_mapped_memory_is_read_whole)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean mapped-memory guard preventing out-of-bounds reads past 16-byte plain HeapDesc structs. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6055168200 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2278#pullrequestreview-6055168200). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T09:42:35Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib descriptor::tests::` — **6 passed, 0 failed** (including `a_plain_description_at_the_end_of_mapped_memory_is_read_whole`) - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean mapped-memory guard preventing out-of-bounds reads past 16-byte plain `HeapDesc` structs. Looks good. AI-assisted (Gemini 4 Neon).
DesertGamer commented 2026-11-25 10:07:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DesertGamer on 2026-11-25T09:37:34Z.


VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158583864 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2278#issuecomment-7158583864). Originally posted by [DesertGamer](https://github.com/DesertGamer) on 2026-11-25T09:37:34Z. --- ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Marvisak commented 2026-11-25 14:07:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:32:06Z.


Automated triage for the maintainers.

Merge candidate. Rebased onto current main, one commit, merges cleanly.

In crates/victory-gpu/src/descriptor.rs, create_heap used to read the 16 bytes after a plain heap description directly, as a possible extended placement. It now reads them through placement_after, which on Windows uses crate::host::read_into (ReadProcessMemory on the current process, already used elsewhere in the crate) and returns a zero placement when those bytes are not readable. A zero placement is not mistaken for an extended one, because recognition requires its size to match the count. a_plain_description_at_the_end_of_mapped_memory_is_read_whole puts the description at the end of a page followed by a PAGE_NOACCESS page, and checks that the heap is created instead of faulting. Nit: the non-Windows branch's SAFETY: as above no longer has a safety comment above it to refer to.

CI: passing (check). Recommending a look, not approving.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163916021 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2278#issuecomment-7163916021). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:32:06Z. --- <!-- victory-triage v1 head=0d92d58a02c0aa1dd6b57cb1f955bc2addbb6ac6 verdict=merge-candidate at=2026-11-26T01:25:15Z --> Automated triage for the maintainers. **Merge candidate.** Rebased onto current `main`, one commit, merges cleanly. In `crates/victory-gpu/src/descriptor.rs`, `create_heap` used to read the 16 bytes after a plain heap description directly, as a possible extended placement. It now reads them through `placement_after`, which on Windows uses `crate::host::read_into` (`ReadProcessMemory` on the current process, already used elsewhere in the crate) and returns a zero placement when those bytes are not readable. A zero placement is not mistaken for an extended one, because recognition requires its size to match the count. `a_plain_description_at_the_end_of_mapped_memory_is_read_whole` puts the description at the end of a page followed by a `PAGE_NOACCESS` page, and checks that the heap is created instead of faulting. Nit: the non-Windows branch's `SAFETY: as above` no longer has a safety comment above it to refer to. CI: passing (`check`). Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 16:04:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:54:38Z.

Review: APPROVED


Reviewed 0d92d58a02c0aa1dd6b57cb1f955bc2addbb6ac6 (merged cleanly onto 63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 with an NVIDIA GeForce RTX 5090, WARP, and D3D12 Debug Layer.

Audit

  • crates/victory-gpu/src/descriptor.rs:740, :744, :772: placement_after probes the 16 bytes following HeapDesc through crate::host::read_into(desc_ptr.wrapping_add(1).cast(), &mut bytes) on Windows and falls back to a zero Placement when unreadable, preventing access violations when a plain 16-byte HeapDesc ends at or near a PAGE_NOACCESS boundary while decoding valid 32-byte extended HeapDesc + Placement records identically. Non-Windows fallback compiles cleanly under #[cfg(not(windows))].

Verification

  • Clean merge onto 63bcca43c6a00a758510398fa43096ce7e4f7df0 + cargo run -p xtask -- policy (191 files ok)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default & --all-features)
  • victory-gpu with VICTORY_D3D12_DEBUG=1: descriptor::tests:: 8/8 passed on RTX 5090; full descriptor:: 23/23 passed (--features diagnostics) on WARP (including a_plain_description_at_the_end_of_mapped_memory_is_read_whole).
  • Also ran a custom probe on both RTX 5090 and WARP verifying (1) a plain HeapDesc placed at page + 4096 - 24 (with only 8 mapped bytes of non-zero data before PAGE_NOACCESS) falls back cleanly without faulting or trusting partial bytes, and (2) a mapped 32-byte extended HeapDesc + Placement is still recognized and honors placement.address.
<!-- greyfinch-sync:Marvisak/VIctory:review:6077100954 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2278#pullrequestreview-6077100954). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T15:54:38Z. **Review:** APPROVED --- Reviewed `0d92d58a02c0aa1dd6b57cb1f955bc2addbb6ac6` (merged cleanly onto `63bcca43c6a00a758510398fa43096ce7e4f7df0`) and verified on Windows 11 with an NVIDIA GeForce RTX 5090, WARP, and D3D12 Debug Layer. ### Audit - `crates/victory-gpu/src/descriptor.rs:740`, `:744`, `:772`: `placement_after` probes the 16 bytes following `HeapDesc` through `crate::host::read_into(desc_ptr.wrapping_add(1).cast(), &mut bytes)` on Windows and falls back to a zero `Placement` when unreadable, preventing access violations when a plain 16-byte `HeapDesc` ends at or near a `PAGE_NOACCESS` boundary while decoding valid 32-byte extended `HeapDesc + Placement` records identically. Non-Windows fallback compiles cleanly under `#[cfg(not(windows))]`. ### Verification - Clean merge onto `63bcca43c6a00a758510398fa43096ce7e4f7df0` + `cargo run -p xtask -- policy` (`191 files ok`) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default & `--all-features`) - `victory-gpu` with `VICTORY_D3D12_DEBUG=1`: `descriptor::tests::` **8/8 passed** on RTX 5090; full `descriptor::` **23/23 passed** (`--features diagnostics`) on WARP (including `a_plain_description_at_the_end_of_mapped_memory_is_read_whole`). - Also ran a custom probe on both RTX 5090 and WARP verifying (1) a plain `HeapDesc` placed at `page + 4096 - 24` (with only 8 mapped bytes of non-zero data before `PAGE_NOACCESS`) falls back cleanly without faulting or trusting partial bytes, and (2) a mapped 32-byte extended `HeapDesc + Placement` is still recognized and honors `placement.address`.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2278:upstream-pr/2278'
git switch 'upstream-pr/2278'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2278'
git switch 'upstream-pr/2278'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2278'
git switch 'upstream-pr/2278'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2278'
git switch 'main'
git merge --squash 'upstream-pr/2278'
git switch 'main'
git merge --ff-only 'upstream-pr/2278'
git switch 'main'
git merge 'upstream-pr/2278'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2276
No description provided.