Loader (diagnostics): VICTORY_POKE writes through the page's protection #2659

Open
github-bot wants to merge 1 commit from github-bot/gh-2659 into main AGit
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:42 UTC · original
kotekompotek:loader/poke-write-protect → main · +68 −5 · 3 files · 1 commits · open

Summary

  • VICTORY_POKE wrote the byte with a raw volatile store, so poking an rva in the title's read-execute .text (e.g. :0x90 over an assert's int3) raised an access violation in victory.exe itself (0xc0000005 at victory.exe+0x524eb) before the title ran.
  • New victory_loader::write_title_byte: VirtualQuery the address, VirtualProtect the page writable for the write, restore its protection, flush the instruction cache on executable pages. Committed-writable pages take the same fast path as before.
  • run.rs::poke now goes through the helper; doc updated (code pages work too).

Test plan

  • VICTORY_POKE=0x1ce6e13:0x90 on the Series 1.0.2.1 image: previously AV'd the host inside poke; now writes through and the run continues past the site.
  • cargo check -p victory --features diagnostics, cargo clippy -p victory-loader -p victory --all-targets --all-features --locked -- -D warnings

Note: for skipping int3 asserts entirely, #2644's VICTORY_STEP_OVER is the better tool (no writes needed); this fixes poke for data bytes on read-only pages and for anyone who still wants code patching.

Generated with Devin

**@⁠kotekompotek** on GitHub · 2026-11-25 17:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2659) `kotekompotek:loader/poke-write-protect` → `main` · +68 −5 · 3 files · 1 commits · open ## Summary - `VICTORY_POKE` wrote the byte with a raw volatile store, so poking an rva in the title's read-execute `.text` (e.g. `:0x90` over an assert's `int3`) raised an access violation in **victory.exe itself** (`0xc0000005` at `victory.exe+0x524eb`) before the title ran. - New `victory_loader::write_title_byte`: `VirtualQuery` the address, `VirtualProtect` the page writable for the write, restore its protection, flush the instruction cache on executable pages. Committed-writable pages take the same fast path as before. - `run.rs::poke` now goes through the helper; doc updated (code pages work too). ## Test plan - [x] `VICTORY_POKE=0x1ce6e13:0x90` on the Series 1.0.2.1 image: previously AV'd the host inside `poke`; now writes through and the run continues past the site. - [x] `cargo check -p victory --features diagnostics`, `cargo clippy -p victory-loader -p victory --all-targets --all-features --locked -- -D warnings` Note: for skipping `int3` asserts entirely, #2644's `VICTORY_STEP_OVER` is the better tool (no writes needed); this fixes poke for data bytes on read-only pages and for anyone who still wants code patching. Generated with [Devin](https://devin.ai)
The poke wrote the byte with a raw volatile store, so listing an rva in
the title's read-execute .text (e.g. nopping an assert's int3) raised an
access violation in the host itself before the title ran. The write now
goes through a loader helper that makes the page writable for the write,
restores its protection, and flushes the instruction cache on executable
pages.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:24 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:21 UTC · original · edited 2026-11-26 00:24 UTC

Automated triage for the maintainers.

Recommended for a maintainer's look. With the two unrelated GPU commits dropped, the branch now holds only the VICTORY_POKE change. victory_loader::write_title_byte (crates/victory-loader/src/crash.rs, diagnostics-only) queries the page and, if it isn't writable, makes it writable for the one-byte write. It then restores the old protection and flushes the instruction cache on executable pages. poke in apps/victory/src/run.rs uses it, so poking a byte in read-only title pages no longer crashes the host. It merges cleanly and CI check (including the all-features clippy on Windows) is passing.

On your reply: confirmed. The diff against main is now only run.rs, crash.rs and the lib.rs re-export.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2659#issuecomment-7176259465) · edited 2026-11-26 00:24 UTC <!-- victory-triage v1 head=e8ccc396353f35505907af85c05423d37af40033 verdict=merge-candidate at=2026-11-26T00:24:47Z --> Automated triage for the maintainers. Recommended for a maintainer's look. With the two unrelated GPU commits dropped, the branch now holds only the `VICTORY_POKE` change. `victory_loader::write_title_byte` (`crates/victory-loader/src/crash.rs`, diagnostics-only) queries the page and, if it isn't writable, makes it writable for the one-byte write. It then restores the old protection and flushes the instruction cache on executable pages. `poke` in `apps/victory/src/run.rs` uses it, so poking a byte in read-only title pages no longer crashes the host. It merges cleanly and CI `check` (including the all-features clippy on Windows) is passing. On your reply: confirmed. The diff against `main` is now only `run.rs`, `crash.rs` and the `lib.rs` re-export. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 22:57 UTC · original

Done — the two GPU commits are dropped; the branch now carries only the VICTORY_POKE commit (e8ccc39) on main. The host_desc change stays in #2442 where it belongs.

**@⁠kotekompotek** on GitHub · 2026-11-25 22:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2659#issuecomment-7176977612) Done — the two GPU commits are dropped; the branch now carries only the VICTORY_POKE commit (e8ccc39) on main. The host_desc change stays in #2442 where it belongs.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:35 UTC · original

Code review and Windows 11 verification at head e8ccc396353f merged cleanly onto main (63bcca43c6a0):

  • Scope & protection handling: write_title_byte (crash.rs), its re-export (lib.rs), and poke (run.rs) stay strictly behind #[cfg(all(windows, feature = "diagnostics"))]. write_title_byte checks VirtualQuery (MEM_COMMIT), checks base writability via info.Protect & 0xFF, preserves execute bits (PAGE_EXECUTE_READWRITE vs PAGE_READWRITE) on a page-aligned VirtualProtect, restores old protection after write_volatile, and calls FlushInstructionCache on executable pages.
  • Minor non-blocking notes:
    1. Adding a unit test exercising write_title_byte against a PAGE_READONLY / PAGE_EXECUTE_READ page would lock in both the write and protection restoration.
    2. If a target page ever carried PAGE_READWRITE | PAGE_GUARD, base_protect matches writable so write_volatile would raise a guard fault directly (not an issue for .text/.rdata pokes, just worth noting).
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok
    • cargo clippy --locked -p victory-loader -p victory --tests -- -D warnings (default + --all-features): 0 warnings
    • cargo test --locked -p victory-loader: 35/35 unit + 4/4 integration (crash_log, load_probe, title_dlls) passed
    • cargo test --locked -p victory-loader --all-features: 37/37 unit + 4/4 integration passed

Looks clean and ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2659#issuecomment-7178922121) Code review and Windows 11 verification at head `e8ccc396353f` merged cleanly onto `main` (`63bcca43c6a0`): - **Scope & protection handling**: `write_title_byte` (`crash.rs`), its re-export (`lib.rs`), and `poke` (`run.rs`) stay strictly behind `#[cfg(all(windows, feature = "diagnostics"))]`. `write_title_byte` checks `VirtualQuery` (`MEM_COMMIT`), checks base writability via `info.Protect & 0xFF`, preserves execute bits (`PAGE_EXECUTE_READWRITE` vs `PAGE_READWRITE`) on a page-aligned `VirtualProtect`, restores `old` protection after `write_volatile`, and calls `FlushInstructionCache` on executable pages. - **Minor non-blocking notes**: 1. Adding a unit test exercising `write_title_byte` against a `PAGE_READONLY` / `PAGE_EXECUTE_READ` page would lock in both the write and protection restoration. 2. If a target page ever carried `PAGE_READWRITE | PAGE_GUARD`, `base_protect` matches writable so `write_volatile` would raise a guard fault directly (not an issue for `.text`/`.rdata` pokes, just worth noting). - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok` - `cargo clippy --locked -p victory-loader -p victory --tests -- -D warnings` (default + `--all-features`): 0 warnings - `cargo test --locked -p victory-loader`: 35/35 unit + 4/4 integration (`crash_log`, `load_probe`, `title_dlls`) passed - `cargo test --locked -p victory-loader --all-features`: 37/37 unit + 4/4 integration passed Looks clean and ready to merge.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 11:33 UTC · original

NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head e8ccc39 (on its base 219878a).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 864 passed, 0 failed, 10 ignored.
  • No new #[test] functions in the diff.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 11:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2659#issuecomment-7190872664) NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head `e8ccc39` (on its base `219878a`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **864 passed, 0 failed, 10 ignored**. - No new `#[test]` functions in the diff. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 12:21 UTC · original · approved these changes

Reviewed and verified at head e8ccc396 against origin/main (63bcca43) on Windows 11 (debug & release, default & --all-features):

  • Design & correctness:
    • victory_loader::write_title_byte (crates/victory-loader/src/crash.rs:54-110), its re-export (crates/victory-loader/src/lib.rs:45), and its caller poke (apps/victory/src/run.rs:286-305) stay strictly gated behind #[cfg(all(windows, feature = "diagnostics"))].
    • Single-byte writes cannot cross a page boundary; VirtualQuery safely rejects uncommitted memory (queried == 0 || info.State != MEM_COMMIT); non-writable pages preserve executability (PAGE_EXECUTE_READWRITE when info.Protect & 0xF0 != 0, else PAGE_READWRITE) on a 4 KiB-aligned VirtualProtect, handle VirtualProtect failure cleanly without writing, restore old protection afterward, and flush the instruction cache on executable pages.
    • Non-blocking observations:
      1. Because base_protect = info.Protect & 0xFF masks off PAGE_GUARD, a PAGE_READWRITE | PAGE_GUARD page enters the writable fast path and raises STATUS_GUARD_PAGE_VIOLATION (0x80000001), whereas PAGE_READONLY | PAGE_GUARD goes through VirtualProtect and restores PAGE_READONLY | PAGE_GUARD cleanly. Checking info.Protect & PAGE_GUARD == 0 in writable would cover that uniformly if ever hit outside normal PE sections.
      2. An already-writable executable page (PAGE_EXECUTE_READWRITE / PAGE_EXECUTE_WRITECOPY) takes the fast path without calling FlushInstructionCache (benign on x86-64).
      3. Adding a small unit test exercising PAGE_READONLY, PAGE_EXECUTE_READ, and MEM_RESERVE would lock in protection restoration.
  • Verification:
    • Clean git merge-tree against origin/main (63bcca43); cargo xtask policy (190 files ok); cargo clippy -p victory-loader -p victory --all-targets --locked -- -D warnings clean with default features and --all-features.
    • cargo test -p victory-loader --locked: 35 unit + 4 integration passed (default), 37 unit + 4 integration passed (--all-features, both debug and --release); cargo check -p victory clean in both dev default and --release --all-features.
    • Exercised write_title_byte directly against PAGE_READWRITE, PAGE_READONLY, PAGE_EXECUTE_READ, PAGE_NOACCESS, MEM_RESERVE, and PAGE_READONLY | PAGE_GUARD allocations on Windows 11—all wrote and restored exact original protections (and returned false on MEM_RESERVE).

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2659#pullrequestreview-6074036303) · **approved these changes** Reviewed and verified at head `e8ccc396` against `origin/main` (`63bcca43`) on Windows 11 (debug & release, default & `--all-features`): - **Design & correctness**: - `victory_loader::write_title_byte` (`crates/victory-loader/src/crash.rs:54-110`), its re-export (`crates/victory-loader/src/lib.rs:45`), and its caller `poke` (`apps/victory/src/run.rs:286-305`) stay strictly gated behind `#[cfg(all(windows, feature = "diagnostics"))]`. - Single-byte writes cannot cross a page boundary; `VirtualQuery` safely rejects uncommitted memory (`queried == 0 || info.State != MEM_COMMIT`); non-writable pages preserve executability (`PAGE_EXECUTE_READWRITE` when `info.Protect & 0xF0 != 0`, else `PAGE_READWRITE`) on a 4 KiB-aligned `VirtualProtect`, handle `VirtualProtect` failure cleanly without writing, restore `old` protection afterward, and flush the instruction cache on executable pages. - Non-blocking observations: 1. Because `base_protect = info.Protect & 0xFF` masks off `PAGE_GUARD`, a `PAGE_READWRITE | PAGE_GUARD` page enters the writable fast path and raises `STATUS_GUARD_PAGE_VIOLATION` (`0x80000001`), whereas `PAGE_READONLY | PAGE_GUARD` goes through `VirtualProtect` and restores `PAGE_READONLY | PAGE_GUARD` cleanly. Checking `info.Protect & PAGE_GUARD == 0` in `writable` would cover that uniformly if ever hit outside normal PE sections. 2. An already-writable executable page (`PAGE_EXECUTE_READWRITE` / `PAGE_EXECUTE_WRITECOPY`) takes the fast path without calling `FlushInstructionCache` (benign on x86-64). 3. Adding a small unit test exercising `PAGE_READONLY`, `PAGE_EXECUTE_READ`, and `MEM_RESERVE` would lock in protection restoration. - **Verification**: - Clean `git merge-tree` against `origin/main` (`63bcca43`); `cargo xtask policy` (`190 files ok`); `cargo clippy -p victory-loader -p victory --all-targets --locked -- -D warnings` clean with default features and `--all-features`. - `cargo test -p victory-loader --locked`: 35 unit + 4 integration passed (default), 37 unit + 4 integration passed (`--all-features`, both debug and `--release`); `cargo check -p victory` clean in both dev default and `--release --all-features`. - Exercised `write_title_byte` directly against `PAGE_READWRITE`, `PAGE_READONLY`, `PAGE_EXECUTE_READ`, `PAGE_NOACCESS`, `MEM_RESERVE`, and `PAGE_READONLY | PAGE_GUARD` allocations on Windows 11—all wrote and restored exact original protections (and returned `false` on `MEM_RESERVE`). LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2659/head:github-bot/gh-2659'
git switch 'github-bot/gh-2659'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2659'
git switch 'github-bot/gh-2659'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2659'
git switch 'github-bot/gh-2659'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2659'
git switch 'main'
git merge --squash 'github-bot/gh-2659'
git switch 'main'
git merge --ff-only 'github-bot/gh-2659'
git switch 'main'
git merge 'github-bot/gh-2659'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2659
No description provided.