Loader & HLE: harden VEH crash handler, PE prep/exports/TLS, and allow oleaut32 #216

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

@⁠wbkepler on GitHub · 2026-11-24 01:30 UTC · original
wbkepler:loader/veh-safety-and-oleaut32 → main · +794 −133 · 7 files · 1 commits · open

Summary

  • VEH crash handler hardening:
    • Enforces page-bound checks before reading faulting bytes in emulate_amd_only, clwb_len, and sse4a (fixing page-end clwb emulation in the last 14 bytes of a page).
    • Guards thrown() against C++ rethrows (null ThrowInfo), null object pointers, and out-of-range catchable-type tables.
    • Makes report_crashes() idempotent via Once, serializes crashes.log writes with a Mutex, and reserves overflow stack via SetThreadStackGuarantee on handler install, title main thread, and thread attach.
  • PE preparation, export resolution, and TLS:
    • Strips IMAGE_DLLCHARACTERISTICS_GUARD_CF alongside FORCE_INTEGRITY in prepare.rs.
    • Resolves title DLL direct and forwarded exports via victory-pe ExportInfo and ImportResolver (with recursion depth guard) instead of host GetProcAddress / LdrpResolveForwarder.
    • Wraps _tls_index zeroing in VirtualProtect and calls FlushInstructionCache after emitting TLS thunks.
  • HLE oleaut32.dll support:
    • Allows oleaut32.dll in default HostPolicy so standard OLE Automation/BSTR imports (including ordinals #4 SysAllocStringLen and #6 SysFreeString) resolve to the host.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (including new tests for page-end emulation, C++ rethrow/ThrowInfo guards, idempotent report_crashes/stack guarantee, GUARD_CF stripping, forwarded/cyclic export resolution, read-only _tls_index patching, and oleaut32 ordinals)
  • cargo xtask policy — passed (151 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/216) `wbkepler:loader/veh-safety-and-oleaut32` → `main` · +794 −133 · 7 files · 1 commits · open ## Summary - **VEH crash handler hardening**: - Enforces page-bound checks before reading faulting bytes in `emulate_amd_only`, `clwb_len`, and `sse4a` (fixing page-end `clwb` emulation in the last 14 bytes of a page). - Guards `thrown()` against C++ rethrows (null `ThrowInfo`), null object pointers, and out-of-range catchable-type tables. - Makes `report_crashes()` idempotent via `Once`, serializes `crashes.log` writes with a `Mutex`, and reserves overflow stack via `SetThreadStackGuarantee` on handler install, title main thread, and thread attach. - **PE preparation, export resolution, and TLS**: - Strips `IMAGE_DLLCHARACTERISTICS_GUARD_CF` alongside `FORCE_INTEGRITY` in `prepare.rs`. - Resolves title DLL direct and forwarded exports via `victory-pe` `ExportInfo` and `ImportResolver` (with recursion depth guard) instead of host `GetProcAddress` / `LdrpResolveForwarder`. - Wraps `_tls_index` zeroing in `VirtualProtect` and calls `FlushInstructionCache` after emitting TLS thunks. - **HLE `oleaut32.dll` support**: - Allows `oleaut32.dll` in default `HostPolicy` so standard OLE Automation/BSTR imports (including ordinals `#4` `SysAllocStringLen` and `#6` `SysFreeString`) resolve to the host. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (including new tests for page-end emulation, C++ rethrow/`ThrowInfo` guards, idempotent `report_crashes`/stack guarantee, `GUARD_CF` stripping, forwarded/cyclic export resolution, read-only `_tls_index` patching, and `oleaut32` ordinals) - `cargo xtask policy` — passed (151 files ok)
- crash.rs: enforce page-bound checks before reading faulting bytes in
  emulate_amd_only, clwb_len, and sse4a (fixing clwb emulation in the last
  14 bytes of a page); guard thrown() against C++ rethrows (null ThrowInfo),
  null object pointers, and invalid/out-of-range catchable-type tables; make
  report_crashes() idempotent via Once, serialize crashes.log writes with a
  Mutex, and reserve overflow stack via SetThreadStackGuarantee on handler
  install, title main thread, and thread attach.
- prepare.rs, windows.rs, tls.rs: strip IMAGE_DLLCHARACTERISTICS_GUARD_CF
  alongside FORCE_INTEGRITY; resolve title DLL direct and forwarded exports
  through victory-pe ExportInfo and ImportResolver (with recursion depth
  guard) instead of host GetProcAddress/LdrpResolveForwarder; wrap _tls_index
  writes in VirtualProtect and call FlushInstructionCache after writing TLS
  thunks.
- host.rs: allow oleaut32.dll in default HostPolicy so standard OLE
  Automation/BSTR imports (including ordinals #4 SysAllocStringLen and #6
  SysFreeString) resolve cleanly to the host.
- Add unit tests covering page-end emulation against PAGE_NOACCESS, C++
  rethrow/invalid ThrowInfo guards, idempotent report_crashes and stack
  guarantee, GUARD_CF stripping, forwarded/cyclic export resolution,
  read-only _tls_index patching, and oleaut32 ordinal resolution.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:55:10 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 05:08 UTC · original

Thanks @⁠wbkepler for the broad hardening across the loader’s exception handling, PE preparation, TLS, export resolution, and HLE API lookup.

I tested commit 6269b57090f44a54be9b4b861f2e83b13a20ae73 with:

cargo test --locked -p victory-loader --lib -- --test-threads=1
cargo test --locked -p victory-hle --lib -- --test-threads=1

Both library suites passed: 25 loader tests and 87 HLE tests, with 0 failures.

Representative coverage of the changed paths includes:

  • Crash handling: page-end bounds during instruction emulation, invalid/rethrown exception records, and idempotent crash-handler setup with the stack guarantee.
  • PE preparation: IAT slots when the import-size field excludes its terminator, static TLS preparation, and stripping Guard CF/force-integrity flags.
  • TLS and exports: read-only TLS-index pages have their protection restored; export resolution covers direct, forwarded, and cyclic exports.
  • HLE API lookup: oleaut32 ordinals resolve to the host.

This is unit-test coverage of the affected code paths. It does not launch a full title or validate the complete runtime integration with title binaries.

**@⁠jeremygold02** on GitHub · 2026-11-24 05:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/216#issuecomment-7122662152) Thanks @⁠wbkepler for the broad hardening across the loader’s exception handling, PE preparation, TLS, export resolution, and HLE API lookup. I tested commit `6269b57090f44a54be9b4b861f2e83b13a20ae73` with: ``` cargo test --locked -p victory-loader --lib -- --test-threads=1 cargo test --locked -p victory-hle --lib -- --test-threads=1 ``` Both library suites passed: 25 loader tests and 87 HLE tests, with 0 failures. Representative coverage of the changed paths includes: - [Crash handling](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/crash.rs#L934): page-end bounds during instruction emulation, invalid/rethrown exception records, and idempotent crash-handler setup with the stack guarantee. - [PE preparation](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/prepare.rs#L210): IAT slots when the import-size field excludes its terminator, static TLS preparation, and stripping Guard CF/force-integrity flags. - [TLS and exports](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/tls.rs#L251): read-only TLS-index pages have their protection restored; [export resolution](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-loader/src/windows.rs#L586) covers direct, forwarded, and cyclic exports. - [HLE API lookup](https://github.com/Marvisak/VIctory/blob/6269b57090f44a54be9b4b861f2e83b13a20ae73/crates/victory-hle/src/lib.rs#L112): `oleaut32` ordinals resolve to the host. This is unit-test coverage of the affected code paths. It does not launch a full title or validate the complete runtime integration with title binaries.
Author
Owner

@⁠wbkepler on GitHub · 2026-11-24 20:37 UTC · original

Rebased onto current main (ffe310e) as 58e267e; the only conflict was in the crash.rs tests (kept both the upstream page-end test and this PR's tests), no code redesign. Gate (clippy -D warnings, tests, policy) clean.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

**@⁠wbkepler** on GitHub · 2026-11-24 20:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/216#issuecomment-7143843338) Rebased onto current main (`ffe310e`) as `58e267e`; the only conflict was in the crash.rs tests (kept both the upstream page-end test and this PR's tests), no code redesign. Gate (clippy -D warnings, tests, policy) clean. _AI-assisted (Claude Code); checked on Windows 11 / RTX 5090._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:20 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-loader/src/crash.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/216#issuecomment-7148415319) <!-- victory-triage v1 head=58e267e23054c1918cc1d04ae1c9c57c190a4a2f verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-loader/src/crash.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-loader/src/crash.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-216'
git switch 'github-bot/gh-216'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-216'
git switch 'github-bot/gh-216'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-216'
git switch 'main'
git merge --squash 'github-bot/gh-216'
git switch 'main'
git merge --ff-only 'github-bot/gh-216'
git switch 'main'
git merge 'github-bot/gh-216'
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!216
No description provided.