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

Open
opened 2026-11-26 04:13:59 +00:00 by github-bot · 5 comments
Owner

@⁠davutsimsekk on GitHub · 2026-11-24 11:19 UTC · original

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.

**@⁠davutsimsekk** on GitHub · 2026-11-24 11:19 UTC · [original](https://github.com/Marvisak/VIctory/issues/805) `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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:00 +00:00
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 12:07 UTC · original

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** on GitHub · 2026-11-24 12:07 UTC · [original](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7130993351) 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.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 12:13 UTC · original · edited 2026-11-24 14:22 UTC

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.
**@⁠pushkarreddyy** on GitHub · 2026-11-24 12:13 UTC · [original](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7131149759) · edited 2026-11-24 14:22 UTC ### 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.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 19:45 UTC · original

@⁠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.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 19:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7142546023) @⁠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.
Author
Owner

@⁠davutsimsekk on GitHub · 2026-11-24 20:07 UTC · original

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.

**@⁠davutsimsekk** on GitHub · 2026-11-24 20:07 UTC · [original](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7143084445) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:54 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 03:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/805#issuecomment-7152344015) <!-- 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)_
This discussion has been locked. Commenting is limited to contributors.
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#805
No description provided.