loader: support multi-region clzero stub reach and checked RVA arithmetic #80

Manually merged
github merged 1 commit from gh-pr/80/head into gh-pr/80/base 2026-12-01 20:07:24 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 05:17 UTC · original
Androtim:feat/iter81-loader-hardening → main · +153 −15 · 2 files · 1 commits · merged 2026-11-29 06:05 UTC

Summary

Adapted from upstream \VIctory-NVIDIA\ PRs #572 and #91 (GPL-3.0), extracted cleanly off \origin/main\ with zero overlap against other open PRs:

  • Multi-region \clzero\ stub reach (\crates/victory-loader/src/console_insn.rs):
    • Replaces the single \Option<(usize, usize)>\ stub allocation with \Vec<(usize, usize)>\ so loops >2 GiB apart (e.g. across distinct loaded modules) each receive an executable stub region within \jmp rel32\ reach instead of falling back to exception-handler emulation on every iteration.
    • Checks instruction length alignment and encodable form before allocating or consuming stub space.
  • Checked RVA arithmetic (\crates/victory-loader/src/prepare.rs):
    • Replaces unchecked \u32\ additions in TLS callback relocation clearing and \dir64_relocations\ with \checked_add, safely skipping malformed PE relocation/TLS RVAs near the top of the 32-bit RVA space.

Verification

  • \cargo xtask policy: \sset policy: 303 files ok\
  • \cargo test -p victory-loader --lib --locked: 49 passed; 0 failed (including \clzero_loops_far_apart_are_each_replaced,
    elocation_targets_past_the_top_of_the_rva_space_are_skipped, and \ ls_directory_at_the_top_of_the_rva_space_is_prepared)
  • \cargo test -p victory-loader --test title_dlls --locked: passed (note: nested \hle-probe\ build in \ ests/load_probe.rs\ passes MSVC /DELAYLOAD\ flag under local GNU mingw toolchain; CI covers full MSVC suite)
  • \cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings
  • \cargo clippy --workspace --all-targets --features diagnostics --locked -- -D warnings: 0 warnings
**@⁠Androtim** on GitHub · 2026-11-29 05:17 UTC · [original](https://github.com/Androtim/MiniVI/pull/80) `Androtim:feat/iter81-loader-hardening` → `main` · +153 −15 · 2 files · 1 commits · merged 2026-11-29 06:05 UTC ## Summary Adapted from upstream \VIctory-NVIDIA\ PRs #572 and #91 (GPL-3.0), extracted cleanly off \origin/main\ with zero overlap against other open PRs: - **Multi-region \clzero\ stub reach (\crates/victory-loader/src/console_insn.rs\):** - Replaces the single \Option<(usize, usize)>\ stub allocation with \Vec<(usize, usize)>\ so loops >2 GiB apart (e.g. across distinct loaded modules) each receive an executable stub region within \jmp rel32\ reach instead of falling back to exception-handler emulation on every iteration. - Checks instruction length alignment and encodable form before allocating or consuming stub space. - **Checked RVA arithmetic (\crates/victory-loader/src/prepare.rs\):** - Replaces unchecked \u32\ additions in TLS callback relocation clearing and \dir64_relocations\ with \checked_add\, safely skipping malformed PE relocation/TLS RVAs near the top of the 32-bit RVA space. ## Verification - \cargo xtask policy\: \sset policy: 303 files ok\ - \cargo test -p victory-loader --lib --locked\: **49 passed; 0 failed** (including \clzero_loops_far_apart_are_each_replaced\, \ elocation_targets_past_the_top_of_the_rva_space_are_skipped\, and \ ls_directory_at_the_top_of_the_rva_space_is_prepared\) - \cargo test -p victory-loader --test title_dlls --locked\: passed *(note: nested \hle-probe\ build in \ ests/load_probe.rs\ passes MSVC \/DELAYLOAD\ flag under local GNU mingw toolchain; CI covers full MSVC suite)* - \cargo clippy --workspace --all-targets --locked -- -D warnings\: **0 warnings** - \cargo clippy --workspace --all-targets --features diagnostics --locked -- -D warnings\: **0 warnings**
Adapted from VIctory-NVIDIA PRs #572 and #91 (GPL-3.0):

- Allow STUBS in console_insn.rs to allocate additional 64 KiB regions when a clzero loop lies outside a 2 GiB jmp rel32 reach of prior stub regions, preventing repeated exception-handler emulation across distant modules.

- Guard TLS callback RVA addition and dir64 relocation page+offset addition with checked_add in prepare.rs so malformed PE RVAs near the top of the 32-bit RVA space cannot wrap around.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:07:22 +00:00
github manually merged commit ef5893f45c into gh-pr/80/base 2026-12-01 20:07:24 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 06:02 UTC · original

Automated triage for the maintainers (not an approval).

Verdict: merge-candidate · CI (check): passing

Review Summary

Clean, well-scoped loader changes with passing CI and targeted unit tests covering both fixes:

  • crates/victory-loader/src/console_insn.rs (STUBS, patch_clzero):
    • Replacing the single Option<(usize, usize)> stub region with Vec<(usize, usize)> properly handles clzero loops separated by more than 2 GiB (beyond jmp rel32 reach of an earlier region) by selecting the first reachable region with room or allocating a new one via near(at).
    • Pre-checking (at & 15) + 5 > 16 and clzero_stub(at, at, [x, y, z]).is_none() before locking STUBS or calling near(at) avoids unnecessary allocations for unpatchable sites.
    • clzero_loops_far_apart_are_each_replaced exercises patching and executing loops allocated >4 GiB apart (VirtualAlloc low + MEM_TOP_DOWN high).
  • crates/victory-loader/src/prepare.rs (prepare, dir64_relocations):
    • Switching unchecked u32 additions to checked_add for tls.directory_rva + TLS64_ADDRESS_OF_CALLBACKS and page + (e & 0xFFF) prevents debug overflow panics and release wrap-around on malformed RVAs near u32::MAX.
    • Both overflow cases are covered by relocation_targets_past_the_top_of_the_rva_space_are_skipped and tls_directory_at_the_top_of_the_rva_space_is_prepared.

No GPU/shader/host rendering paths are touched, and there is no overlap with other open PRs. Ready as a merge candidate (pending maintainer review).


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 06:02 UTC · [original](https://github.com/Androtim/MiniVI/pull/80#issuecomment-7251614697) <!-- minivi-triage v1 head=ef5893f45cb6c1ed288a08ec54836961311d684b verdict=merge-candidate ci=passing at=2026-11-29T06:03:29Z --> Automated triage for the maintainers (not an approval). **Verdict:** `merge-candidate` · **CI (`check`):** `passing` ### Review Summary Clean, well-scoped loader changes with passing CI and targeted unit tests covering both fixes: - **`crates/victory-loader/src/console_insn.rs`** (`STUBS`, `patch_clzero`): - Replacing the single `Option<(usize, usize)>` stub region with `Vec<(usize, usize)>` properly handles `clzero` loops separated by more than 2 GiB (beyond `jmp rel32` reach of an earlier region) by selecting the first reachable region with room or allocating a new one via `near(at)`. - Pre-checking `(at & 15) + 5 > 16` and `clzero_stub(at, at, [x, y, z]).is_none()` before locking `STUBS` or calling `near(at)` avoids unnecessary allocations for unpatchable sites. - `clzero_loops_far_apart_are_each_replaced` exercises patching and executing loops allocated >4 GiB apart (`VirtualAlloc` low + `MEM_TOP_DOWN` high). - **`crates/victory-loader/src/prepare.rs`** (`prepare`, `dir64_relocations`): - Switching unchecked `u32` additions to `checked_add` for `tls.directory_rva + TLS64_ADDRESS_OF_CALLBACKS` and `page + (e & 0xFFF)` prevents debug overflow panics and release wrap-around on malformed RVAs near `u32::MAX`. - Both overflow cases are covered by `relocation_targets_past_the_top_of_the_rva_space_are_skipped` and `tls_directory_at_the_top_of_the_rva_space_is_prepared`. No GPU/shader/host rendering paths are touched, and there is no overlap with other open PRs. Ready as a merge candidate (pending maintainer review). --- _Generated with Antigravity CLI (`agy`)._
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/Androtim--MiniVI!80
No description provided.