HLE: pass data-only LoadLibraryEx mappings outside HostPolicy to the host #1418

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/1419 into main
fuzeofficlal commented 2026-11-24 17:54:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:54:20Z.


Fixes #805.

Summary

  • Distinguish GetModuleHandle queries (Lookup::Query), executable loads (Lookup::Code), uninitialised image loads (Lookup::NoInit for DONT_RESOLVE_DLL_REFERENCES), and passive data or resource mappings (Lookup::Data when LOAD_LIBRARY_AS_DATAFILE, LOAD_LIBRARY_AS_IMAGE_RESOURCE, or LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE is set without 0x1) in kernel::find_module.
  • Return None on Lookup::Data for modules outside HostPolicy that are neither mapped title images nor pseudo modules so the host maps data/resource handles (whose exports GetProcAddress cannot resolve), while keeping DONT_RESOLVE_DLL_REFERENCES (0x1), executable LoadLibrary* loads, and GetModuleHandle* gated by HostPolicy.

Verification

  • modules::kernel::tests::datafile_loads_outside_host_policy_reach_the_host: verifies 0x2, 0x20, 0x40, and 0x22 succeed on a DLL outside HostPolicy and return null from GetProcAddress, whereas 0x1 (DONT_RESOLVE_DLL_REFERENCES), executable LoadLibrary*, and GetModuleHandle* stay refused with ERROR_MOD_NOT_FOUND.
  • cargo test -p victory-hle --locked, cargo clippy -p victory-hle --tests --locked -- -D warnings, and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6588063952 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1419). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:54:20Z. --- Fixes #805. ### Summary - Distinguish `GetModuleHandle` queries (`Lookup::Query`), executable loads (`Lookup::Code`), uninitialised image loads (`Lookup::NoInit` for `DONT_RESOLVE_DLL_REFERENCES`), and passive data or resource mappings (`Lookup::Data` when `LOAD_LIBRARY_AS_DATAFILE`, `LOAD_LIBRARY_AS_IMAGE_RESOURCE`, or `LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE` is set without `0x1`) in `kernel::find_module`. - Return `None` on `Lookup::Data` for modules outside `HostPolicy` that are neither mapped title images nor pseudo modules so the host maps data/resource handles (whose exports `GetProcAddress` cannot resolve), while keeping `DONT_RESOLVE_DLL_REFERENCES` (`0x1`), executable `LoadLibrary*` loads, and `GetModuleHandle*` gated by `HostPolicy`. ### Verification - `modules::kernel::tests::datafile_loads_outside_host_policy_reach_the_host`: verifies `0x2`, `0x20`, `0x40`, and `0x22` succeed on a DLL outside `HostPolicy` and return null from `GetProcAddress`, whereas `0x1` (`DONT_RESOLVE_DLL_REFERENCES`), executable `LoadLibrary*`, and `GetModuleHandle*` stay refused with `ERROR_MOD_NOT_FOUND`. - `cargo test -p victory-hle --locked`, `cargo clippy -p victory-hle --tests --locked -- -D warnings`, and `cargo xtask policy`: passed.
geiyiliyabumo commented 2026-11-24 18:06:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T18:03:52Z.


Independent verification of \c8b7a3d\ on Windows 11 / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-hle --lib kernel: 5 passed, 0 failed (including \datafile_loads_outside_host_policy_reach_the_host)
  • \cargo clippy -p victory-hle --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

Code audit looks clean and minimal: introducing \Lookup::{Query, Code, Data}\ keeps code loads and \GetModuleHandle*\ queries outside \HostPolicy\ refused while allowing passive data/resource mappings through to the host.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140103760 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7140103760). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T18:03:52Z. --- Independent verification of \c8b7a3d\ on **Windows 11 / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-hle --lib kernel\: **5 passed, 0 failed** (including \datafile_loads_outside_host_policy_reach_the_host\) - \cargo clippy -p victory-hle --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok Code audit looks clean and minimal: introducing \Lookup::{Query, Code, Data}\ keeps code loads and \GetModuleHandle*\ queries outside \HostPolicy\ refused while allowing passive data/resource mappings through to the host. *AI-assisted; synthetic tests only, no game files.*
Marvisak commented 2026-11-25 02:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:26:56Z.


Automated triage for the maintainers.

Needs work. 07326307 fixes the hole from the last triage. In crates/victory-hle/src/modules/kernel.rs, load_lookup sends DONT_RESOLVE_DLL_REFERENCES (0x1) to the new Lookup::NoInit, which find_module still refuses outside HostPolicy and which does not call runtime::load_title_dll. Only pure data/resource loads (0x2, 0x20, 0x40 without 0x1) become Lookup::Data and go to the host. The test asserts all of this, and GetModuleHandle* and code loads stay refused. CI: passing (check).

What remains:

  • Evidence. This PR relaxes the host-DLL guard, so it needs a case where the title actually makes such a load: a "host DLL outside the host policy: refused" log line from a run, together with the flags passed to LoadLibraryEx. #805 shows the behaviour on a synthetic call only. Without a load seen in the title, the guard should stay as it is.
  • A DLL the host process already has loaded. Please check what the host returns for a data load of a DLL outside HostPolicy that the host process has already loaded as an image. If the host hands back the existing image handle, GetProcAddress would resolve real exports through it, which is the case the guard exists for. The test passes for comctl32.dll only because that DLL is not loaded as an image in the test process.

On your reply: the 0x1 change is exactly what was asked, thanks. The verdict stays at needs work only because of the two points above.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149557206 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7149557206). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:26:56Z. --- <!-- victory-triage v1 head=07326307b2d7e1e329b908299dfb5acc3d2d0242 verdict=needs-work at=2026-11-25T11:20:08Z --> Automated triage for the maintainers. **Needs work.** `07326307` fixes the hole from the last triage. In `crates/victory-hle/src/modules/kernel.rs`, `load_lookup` sends `DONT_RESOLVE_DLL_REFERENCES` (0x1) to the new `Lookup::NoInit`, which `find_module` still refuses outside `HostPolicy` and which does not call `runtime::load_title_dll`. Only pure data/resource loads (0x2, 0x20, 0x40 without 0x1) become `Lookup::Data` and go to the host. The test asserts all of this, and `GetModuleHandle*` and code loads stay refused. CI: passing (`check`). What remains: - **Evidence.** This PR relaxes the host-DLL guard, so it needs a case where the title actually makes such a load: a "host DLL outside the host policy: refused" log line from a run, together with the flags passed to `LoadLibraryEx`. #805 shows the behaviour on a synthetic call only. Without a load seen in the title, the guard should stay as it is. - **A DLL the host process already has loaded.** Please check what the host returns for a data load of a DLL outside `HostPolicy` that the host process has already loaded as an image. If the host hands back the existing image handle, `GetProcAddress` would resolve real exports through it, which is the case the guard exists for. The test passes for `comctl32.dll` only because that DLL is not loaded as an image in the test process. On your reply: the 0x1 change is exactly what was asked, thanks. The verdict stays at needs work only because of the two points above. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync changed title from [PR #1419] HLE: pass non-code LoadLibraryEx mappings outside HostPolicy to the host to [PR #1419] HLE: pass data-only LoadLibraryEx mappings outside HostPolicy to the host 2026-11-25 10:05:57 +00:00
fuzeofficlal commented 2026-11-25 10:07:49 +00:00 (Migrated from github.com)

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


Updated in 07326307 per triage feedback:

  • Kept DONT_RESOLVE_DLL_REFERENCES (0x1) on a separate Lookup::NoInit path so unmapped title DLLs still avoid load_title_dll (DllMain) as on main, while DLLs outside HostPolicy remain refused (ERROR_MOD_NOT_FOUND).
  • Restricted Lookup::Data to pure data/resource mappings (0x2, 0x20, 0x40 without 0x1), dropped 0x1 from the allowed test list, and added explicit assertions that 0x1 outside HostPolicy is refused and GetProcAddress on mapped data handles returns null.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7158830840 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7158830840). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T09:48:37Z. --- Updated in `07326307` per triage feedback: - Kept `DONT_RESOLVE_DLL_REFERENCES` (`0x1`) on a separate `Lookup::NoInit` path so unmapped title DLLs still avoid `load_title_dll` (`DllMain`) as on `main`, while DLLs outside `HostPolicy` remain refused (`ERROR_MOD_NOT_FOUND`). - Restricted `Lookup::Data` to pure data/resource mappings (`0x2`, `0x20`, `0x40` without `0x1`), dropped `0x1` from the allowed test list, and added explicit assertions that `0x1` outside `HostPolicy` is refused and `GetProcAddress` on mapped data handles returns null.
upstream-sync closed this pull request 2026-11-25 18:01:36 +00:00
fuzeofficlal commented 2026-11-25 18:02:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T17:20:14Z.


Closing this PR: as noted in triage, loosening the HostPolicy gate requires a real title log showing the refused DLL call site, which I do not have locally.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169356470 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1419#issuecomment-7169356470). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T17:20:14Z. --- Closing this PR: as noted in triage, loosening the `HostPolicy` gate requires a real title log showing the refused DLL call site, which I do not have locally.

Pull request closed

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!1418
No description provided.