HLE: LOAD_LIBRARY_AS_DATAFILE loads outside HostPolicy fail with ERROR_MOD_NOT_FOUND (fix on a fork) #805

Open
opened 2026-11-24 11:19:38 +00:00 by davutsimsekk · 5 comments
davutsimsekk commented 2026-11-24 11:19:38 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by davutsimsekk on 2026-11-24T11:19:38Z.


LoadLibraryExW(L"comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE) returns NULL with ERROR_MOD_NOT_FOUND (126) on ffe310e, while Windows returns a data-file handle. The same happens for any DLL outside HostPolicy loaded with DONT_RESOLVE_DLL_REFERENCES, LOAD_LIBRARY_AS_DATAFILE(_EXCLUSIVE) or LOAD_LIBRARY_AS_IMAGE_RESOURCE.

LoadLibraryExA/W already computes runs_code(flags) and passes it to find_module as load, but find_module still applies the HostPolicy refusal at the end:

if host_dll {
    return None;
}
refuse(&file);
host::set_last_error(ERROR_MOD_NOT_FOUND);
Some(std::ptr::null_mut())

That contradicts the comment above runs_code: a load that runs no code can go to the host. The existing test at kernel.rs:680 only asserts the result is not the title's mapped base, so NULL also passes it.

Fix on a fork

  • Branch: https://github.com/davutsimsekk/VIctory/tree/fix/loadlibrary-datafile-host
  • Commit: 343aa42 on main ffe310e, one file (crates/victory-hle/src/modules/kernel.rs).
  • The load's runs_code value is passed into find_module; when it is false and the name is not one of our pseudo modules or an already mapped image, find_module returns None so the host loader maps the file as data. Code loads, GetModuleHandle, pseudo-module resolution and the HostPolicy checks are unchanged.

Test

a_data_load_of_a_host_dll_reaches_the_host loads comctl32.dll as data:

  • on main: NULL, last error 126;
  • with the branch: non-NULL, and FreeLibrary returns 1.

Also run on Windows 11, Rust 1.98.1 (MSVC):

  • cargo test -p victory-hle --lib: 95 passed
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean
  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/kernel.rs: clean

PR creation is still restricted to collaborators, so the branch is here for review or cherry-pick.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6580606911 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/805). Originally posted by [davutsimsekk](https://github.com/davutsimsekk) on 2026-11-24T11:19:38Z. --- `LoadLibraryExW(L"comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE)` returns NULL with `ERROR_MOD_NOT_FOUND` (126) on `ffe310e`, while Windows returns a data-file handle. The same happens for any DLL outside `HostPolicy` loaded with `DONT_RESOLVE_DLL_REFERENCES`, `LOAD_LIBRARY_AS_DATAFILE(_EXCLUSIVE)` or `LOAD_LIBRARY_AS_IMAGE_RESOURCE`. `LoadLibraryExA/W` already computes `runs_code(flags)` and passes it to `find_module` as `load`, but `find_module` still applies the HostPolicy refusal at the end: ```rust if host_dll { return None; } refuse(&file); host::set_last_error(ERROR_MOD_NOT_FOUND); Some(std::ptr::null_mut()) ``` That contradicts the comment above `runs_code`: a load that runs no code can go to the host. The existing test at `kernel.rs:680` only asserts the result is not the title's mapped base, so NULL also passes it. ## Fix on a fork - **Branch:** https://github.com/davutsimsekk/VIctory/tree/fix/loadlibrary-datafile-host - **Commit:** `343aa42` on `main` `ffe310e`, one file (`crates/victory-hle/src/modules/kernel.rs`). - The load's `runs_code` value is passed into `find_module`; when it is false and the name is not one of our pseudo modules or an already mapped image, `find_module` returns `None` so the host loader maps the file as data. Code loads, `GetModuleHandle`, pseudo-module resolution and the HostPolicy checks are unchanged. ## Test `a_data_load_of_a_host_dll_reaches_the_host` loads `comctl32.dll` as data: - on `main`: NULL, last error **126**; - with the branch: non-NULL, and `FreeLibrary` returns 1. Also run on Windows 11, Rust 1.98.1 (MSVC): - `cargo test -p victory-hle --lib`: **95 passed** - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean - `rustfmt --edition 2024 --check crates/victory-hle/src/modules/kernel.rs`: clean PR creation is still restricted to collaborators, so the branch is here for review or cherry-pick.
pushkarreddyy commented 2026-11-24 13:01:57 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T12:07:15Z.


Claiming this issue.

In crates/victory-hle/src/modules/kernel.rs, LoadLibraryExW computes runs_code(flags) where flags like LOAD_LIBRARY_AS_DATAFILE, LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE, and DONT_RESOLVE_DLL_REFERENCES evaluate to false.

When runs_code is false, the DLL is mapped strictly as a passive data/resource file and will not execute any DllMain or code. However, find_module currently enforces HostPolicy refusal unconditionally, causing data-file loads of standard Windows libraries (e.g. comctl32.dll for UI icons/resources) to fail with ERROR_MOD_NOT_FOUND (126).

Passing runs_code into find_module so passive data-file mappings are permitted to fall through to the host loader cleanly fixes this without weakening code-execution sandboxing.

Preparing a clean branch with regression tests on fork.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7130993351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7130993351). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T12:07:15Z. --- Claiming this issue. In `crates/victory-hle/src/modules/kernel.rs`, `LoadLibraryExW` computes `runs_code(flags)` where flags like `LOAD_LIBRARY_AS_DATAFILE`, `LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE`, and `DONT_RESOLVE_DLL_REFERENCES` evaluate to `false`. When `runs_code` is false, the DLL is mapped strictly as a passive data/resource file and will not execute any DllMain or code. However, `find_module` currently enforces `HostPolicy` refusal unconditionally, causing data-file loads of standard Windows libraries (e.g. `comctl32.dll` for UI icons/resources) to fail with `ERROR_MOD_NOT_FOUND` (126). Passing `runs_code` into `find_module` so passive data-file mappings are permitted to fall through to the host loader cleanly fixes this without weakening code-execution sandboxing. Preparing a clean branch with regression tests on fork.
pushkarreddyy commented 2026-11-24 13:01:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T12:13:57Z.


Verified Patch Ready on Fork

The implementation is verified and available on my fork:

Changes (crates/victory-hle/src/modules/kernel.rs):

  • Introduced LoadKind { Query, Code, Data } to clearly distinguish between querying loaded module handles (GetModuleHandle), executable library loads (LoadLibrary / runs_code == true), and passive data-file mappings (LOAD_LIBRARY_AS_DATAFILE, DONT_RESOLVE_DLL_REFERENCES / runs_code == false).
  • When LoadKind::Data is passed, find_module returns None for DLLs outside HostPolicy, allowing the host loader to map the DLL strictly as passive data/resources without running code or executing DllMain.
  • Retains existing sandboxing and refusal for code-execution loads and module queries.
  • Added regression test verifying LoadLibraryExW("comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE) succeeds on Windows.

Verification:

  • Formatted with rustfmt --edition 2024.
  • Rule #1 asset policy compliant (cargo xtask policy clean).
  • ready for review or merge when PR permissions reopen.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7131149759 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7131149759). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T12:13:57Z. --- ### Verified Patch Ready on Fork The implementation is verified and available on my fork: - **Branch:** https://github.com/pushkarreddyy/VIctory/tree/fix/loadlibrary-datafile-host - **Commit:** [`79cf805`](https://github.com/pushkarreddyy/VIctory/commit/79cf805) based on `main` (`ffe310e`) #### Changes (`crates/victory-hle/src/modules/kernel.rs`): - Introduced `LoadKind { Query, Code, Data }` to clearly distinguish between querying loaded module handles (`GetModuleHandle`), executable library loads (`LoadLibrary` / `runs_code == true`), and passive data-file mappings (`LOAD_LIBRARY_AS_DATAFILE`, `DONT_RESOLVE_DLL_REFERENCES` / `runs_code == false`). - When `LoadKind::Data` is passed, `find_module` returns `None` for DLLs outside `HostPolicy`, allowing the host loader to map the DLL strictly as passive data/resources without running code or executing `DllMain`. - Retains existing sandboxing and refusal for code-execution loads and module queries. - Added regression test verifying `LoadLibraryExW("comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE)` succeeds on Windows. #### Verification: - Formatted with `rustfmt --edition 2024`. - Rule #1 asset policy compliant (`cargo xtask policy` clean). - ready for review or merge when PR permissions reopen.
MamaLeVrai commented 2026-11-24 20:03:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-24T19:45:27Z.


@davutsimsekk your fix for this issue is now in a pull request, #1610, with seven other fixes from contributors' forks: the branch is merged as it is, with your commit(s) and your name unchanged, onto main ffe310e. Clippy (both runs) and cargo test --workspace pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1610. AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142546023 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7142546023). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-24T19:45:27Z. --- @davutsimsekk your fix for this issue is now in a pull request, #1610, with seven other fixes from contributors' forks: the branch is merged as it is, with your commit(s) and your name unchanged, onto `main` `ffe310e`. Clippy (both runs) and `cargo test --workspace` pass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1610. AI-assisted (Claude Code); no game data.
davutsimsekk commented 2026-11-24 21:03:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by davutsimsekk on 2026-11-24T20:07:54Z.


Thanks — keep it in #1610. I fetched the bundle and confirmed it contains 343aa42 unchanged (git merge-base --is-ancestor), with the commit and author intact.

Since PR creation is still restricted for my account, carrying it in the bundle is the right path. I'm happy for it to be merged as-is; if kernel.rs needs a rebase later, I can take that.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143084445 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7143084445). Originally posted by [davutsimsekk](https://github.com/davutsimsekk) on 2026-11-24T20:07:54Z. --- Thanks — keep it in #1610. I fetched the bundle and confirmed it contains `343aa42` unchanged (`git merge-base --is-ancestor`), with the commit and author intact. Since PR creation is still restricted for my account, carrying it in the bundle is the right path. I'm happy for it to be merged as-is; if `kernel.rs` needs a rebase later, I can take that.
Marvisak commented 2026-11-25 04:07:10 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:54:03Z.


Automated triage for the maintainers.

Confirmed on main: in crates/victory-hle/src/modules/kernel.rs, LoadLibraryExA/W pass runs_code(flags) to find_module, but find_module uses it only to decide whether to map a title DLL. A DLL outside HostPolicy is refused with ERROR_MOD_NOT_FOUND whatever the flags, so a data-file load of comctl32.dll returns NULL. find_module's own doc comment describes that refusal, so whether loads that run no code should be exempt is a maintainer decision. Nothing in the thread shows the title making such a load.

Open PR #1419 carries this change. Pull requests are open to everyone, so please compare the fork branches with it and comment there.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152344015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7152344015). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:54:03Z. --- <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T20:07:54Z at=2026-11-25T03:54:02Z --> Automated triage for the maintainers. Confirmed on `main`: in `crates/victory-hle/src/modules/kernel.rs`, `LoadLibraryExA/W` pass `runs_code(flags)` to `find_module`, but `find_module` uses it only to decide whether to map a title DLL. A DLL outside `HostPolicy` is refused with `ERROR_MOD_NOT_FOUND` whatever the flags, so a data-file load of `comctl32.dll` returns NULL. `find_module`'s own doc comment describes that refusal, so whether loads that run no code should be exempt is a maintainer decision. Nothing in the thread shows the title making such a load. Open PR #1419 carries this change. Pull requests are open to everyone, so please compare the fork branches with it and comment there. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
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#805
No description provided.