Skip to content

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

Open
kotekompotek wants to merge 1 commit into
Marvisak:mainfrom
kotekompotek:loader/poke-write-protect
Open

kotekompotek wants to merge 1 commit into
Marvisak:mainfrom
kotekompotek:loader/poke-write-protect

Conversation

@kotekompotek

Copy link
Copy Markdown

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

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>
@kotekompotek
kotekompotek force-pushed the loader/poke-write-protect branch from af73105 to e8ccc39 Compare November 25, 2026 22:57
@kotekompotek

Copy link
Copy Markdown
Author

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.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
@futurepro62

Copy link
Copy Markdown

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

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.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants