loader: keep mapped DLLs inside the title directory #2672
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2672
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2672"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Rickeal-Boss on GitHub · 2026-11-25 17:51 UTC · original
Rickeal-Boss:fix/loader-import-dll-name→main· +138 −0 · 1 files · 2 commits · openSummary
map_dlltakes the DLL name straight from the PE import descriptor and joinsit onto the title directory. A crafted import name can leave that directory or
supply an absolute path, so the loader would read and prepare an image from
outside the folder the user supplied. This PR rejects such names at the entry
point. One file, no runtime behaviour change for valid imports.
Problem
In
crates/victory-loader/src/windows.rs:142-159(unchanged on currentmain,13f91cae):nameis only lowercased...\..\evil.dllresolves outsidedirs.0, andC:\Windows\System32\version.dllis absolute —Path::joindiscards the basefor an absolute path.
wantedis applied to the unsanitised name, so the hostpolicy cannot distinguish either case. Callers in
apps/victory/src/run.rspass
dirs.0as the title directory. The documented contract is that everymapped DLL sits beside the title executable.
Reachability. The import table comes from the title's own PE files - the
files the user supplies. A damaged or hostile dump reaches this code with no
special privilege; this is a boundary check on user-supplied input, not a
synthetic overflow case.
Change
ParentDir,RootDirorPrefixcomponent, and anyname whose
Path::file_name()is not the whole name. Keep the existingASCII-lowercase normalisation so
wanted,seenand theloadedkey seeexactly the same string as before for valid imports.
starts_with(canonicalise(title_dir))before reading it. This also coversjunctions and symlinks that a lexical check would miss.
seen,wantedand theloadedentry, so arejected name cannot poison the dedup set.
!path.is_file()path); it does not abort the load.
Tests
Synthetic import names only, no game data:
..\..\evil.dll,..\\evil.dll,sub/evil.dll,C:\Windows\System32\version.dlland a UNC/verbatim prefix are refused.
kernel32.dlland a mixed-case equivalent still resolve to the same key.canonicalise check (Windows test; skipped elsewhere).
Verification
To run on the pinned toolchain (MSVC build tools, Windows):
cargo test -p victory-loader --lockedcargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo xtask policy— all files okNot run here: no Rust toolchain / Windows-only project in this environment;
CI should cover the above.
windows.rsis untouched by any open PR in the300-PR corpus checked at 17:00 UTC (max #2616), so this should be
conflict-free. #2595 edits
victory-pe/src/image.rs, a different crate.What
Reject import DLL names that would escape the title directory, and verify the
resolved path before reading it. See
## Problemand## Changeabove for theexact entry point and the checks.
Tested
Not run here: no Rust toolchain / Windows-only project in this environment.
See
## Verificationfor the commands; synthetic names only, no title files.Claim: #1633
NEW-<id>.Synthetic names only, no game data, no binaries (per
docs/asset-policy.md).Prepared with AI assistance (Chinese Model); reviewed and conducted by Rickeal-Boss.
@kotekompotek on GitHub · 2026-11-25 17:56 UTC · original
Reviewed: two-layer check is right —
is_plain_import_nameblocks lexical escapes (separators,.., drive/UNC) which PE never legitimately uses, andresolves_insidecatches junction/symlink escapes the lexical test can't see. Fail-open on unresolvable paths is correct since the caller'sis_filecheck decides missing files, and rejection-before-seenavoids poisoning dedup. Security-relevant; CI green.@oni-swr on GitHub · 2026-11-25 18:23 UTC · original
Independent verification of #2672 (loader: keep mapped DLLs inside the title directory)
PR head
3ab03c8f5869f211f01ebffc02fb81cc13b7bed9, merges cleanly ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca.Environment: Windows 11 Pro 10.0.26200 (symlink creation is permitted for this user), rustc 1.98.1, CPU only,
-j 4 --locked.Tests/clippy vs baseline.
origin/main:cargo test -p victory-loader --lib --locked= 34 passed. With #2672 as pushed: 38 passed, 1 FAILED:windows::tests::a_symlink_outside_the_title_dir_is_refused(assertion failed: !resolves_inside(&escaped.join("a.dll"), &title)). Clippy (cargo clippy -p victory-loader --all-targets --locked): 0 warnings.Bug in the test (not in the fix). The test links
title/escaped.dlltooutside/but never createsoutside/a.dll.resolves_insidereturnstruewhen the candidate does not resolve (by design, see its doc comment), so the assertion fails wheneversymlink_dirsucceeds (Developer Mode or elevation). Without that privilege the test returns early, so a CI without it would not notice. Addingstd::fs::write(outside.join("a.dll"), b"x").unwrap();before the assertion makes it pass: 39 passed, 0 failed (scratch edit only, not pushed).Negative control (scratch, not committed). With the
is_plain_import_name/resolves_insidecheck removed frommap_dll(and the symlink test fixed as above): 38 passed, 1 failed:escaping_names_are_refused_without_poisoning_the_dedup_set. The absolute-path name in that test reaches a real system file once the check is gone. The other new tests call the helpers directly and still pass, so only that one test guards the wiring inmap_dll. With the check restored everything passes.Diff review. The lexical check (a single
Component::Normal) plus the canonicalised prefix check is sound for.., separators, drive and UNC names, and symlinked directories. Nits: (1) the path is canonicalised for the check but loaded through the original path, a small check/use window; (2) a DLL deliberately symlinked from inside the title dir to somewhere else is now refused (with a warn log), which looks intended but is a behaviour change worth a line in the PR text.Limits: no game files; junctions (
mklink /J) were not exercised, only symlinks.AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
@fuzeofficlal on GitHub · 2026-11-25 18:57 UTC · original
Independent Windows 11 verification and code review of
3ab03c8f(on13f91ca):Verification (
rustc 1.98.1MSVC)cargo clippy --locked -p victory-loader --all-targets -- -D warningsand--all-features: 0 warnings.cargo test --locked -p victory-loader: 39 passed (lib), pluscrash_log(1),load_probe(2),title_dlls(1) (note:a_symlink_outside_the_title_dir_is_refusedskipped locally because symlink creation requires privilege/Developer Mode).Review Notes & Root Cause of CI Failure
is_plain_import_namerejecting..,., drive-relativeC:foo.dll, rootedoo.dll, UNC/verbatim prefixes, and subdirectories;resolves_insideviacanonicalizecatching symlinks/junctions while failing open onNotFoundso host/HLE DLLs still pass through; rejecting beforeseen.insert) look solid.windows::tests::a_symlink_outside_the_title_dir_is_refused(crates/victory-loader/src/windows.rs:173-177), the test createssymlink_dir(&outside, &escaped)and asserts!resolves_inside(&escaped.join("a.dll"), &title), without creatingoutside/a.dll. On CI runners where symlink creation succeeds,std::fs::canonicalize(&escaped.join("a.dll"))returnsErr(NotFound), soresolves_insidereturnstrueby design and trips theassert!. Creatingoutside/a.dllfirst (or usingsymlink_filepointing to a real outside file) will make the test exercise the intended rejection path and turn CI green.@Marvisak on GitHub · 2026-11-25 23:23 UTC · original
Automated triage for the maintainers.
The guard in
map_dll(crates/victory-loader/src/windows.rs,is_plain_import_nameplusresolves_inside) reads correctly, but CI (check) fails, and the cause is in the new testa_symlink_outside_the_title_dir_is_refused: it linkstitle/escaped.dlltooutside/but never createsoutside/a.dll, socanonicalizefails with NotFound andresolves_insidereturnstrueby design, tripping theassert!wherever symlink creation is allowed (as on CI). Writingoutside/a.dllbefore the assertion (as two reviewers here also found) should make it exercise the rejection path. Two smaller points: the test helperneverreturnstrue(accept everything), so a name likeaccept_allwould read correctly; and the runtime path (find_moduleinvictory-hlekernel.rs) already reduces names to a file name, so the PR text could say this guard covers static import names. A green CI run would change the verdict.Generated by Claude Code
@Rickeal-Boss on GitHub · 2026-11-26 12:22 UTC · original
Summary
map_dlltakes the DLL name straight from the PE import descriptor and joinsit onto the title directory. A crafted import name can leave that directory or
supply an absolute path, so the loader would read and prepare an image from
outside the folder the user supplied. This PR rejects such names at the entry
point. One file, no runtime behaviour change for valid imports.
Scope. This guards static PE import names. The runtime path
(
find_moduleincrates/victory-hle/src/modules/kernel.rs) already reducesnames to a file name before lookup, so it is not covered here and needs no
change.
Problem
In
crates/victory-loader/src/windows.rs:142-159(currentmain,63bcca43):nameis only lowercased...\..\evil.dllresolves outsidedirs.0, andC:\Windows\System32\version.dllis absolute -Path::joindiscards the basefor an absolute path.
wantedis applied to the unsanitised name, so the hostpolicy cannot distinguish either case. Callers in
apps/victory/src/run.rspass
dirs.0as the title directory. The documented contract is that everymapped DLL sits beside the title executable.
Reachability. The import table comes from the title's own PE files - the
files the user supplies. A damaged or hostile dump reaches this code with no
special privilege; this is a boundary check on user-supplied input, not a
synthetic overflow case.
Change
is_plain_import_namerejects any name that is not a singleComponent::Normal: separators,..,., roots, drive-relative and UNC /verbatim prefixes. PE import names are always plain file names.
resolves_insidecanonicalises both the candidate and the title directory,so a junction or symlink that leaves the title directory is rejected too. It
deliberately fails open when either side does not resolve: a host DLL that
is not shipped beside the title is not an escape, and the caller's
is_filecheck decides that case.
seen.insert/wanted, so a rejected namecannot poison the dedup set. Rejection is a no-op like a missing file, not a
load error; the ASCII-lowercase normalisation is unchanged, so valid imports
produce exactly the same
wanted,seenand loaded keys as before.Behaviour change worth calling out: a DLL deliberately symlinked or
junctioned from inside the title directory to somewhere else is now refused,
with a
tracing::warn!line. That is intended by the "beside the title executable" contract, but it is a change from today's behaviour.Known limitation: the path is canonicalised for the check but loaded through the original path, so there is a small check/use window. Closing it would mean loading from the canonicalised path; that is deliberately left out of this focused PR. Junctions (
mklink /J) were not exercised in the tests,only directory symlinks.
Tests
Synthetic import names only, no game data, no binaries:
..\..\evil.dll,..\evil.dll,sub/evil.dll,C:\Windows\System32\version.dll, a rooted name, a drive-relative name anda UNC prefix are refused (helper-level test).
escaping_names_are_refused_without_poisoning_the_dedup_setdrivesmap_dllitself: the absolute-path name reaches a real system file if theguard is removed. This is the test that guards the wiring, not just the
helpers.
kernel32.dlland a mixed-case equivalent still resolve to the same key.a_symlink_outside_the_title_dir_is_refusedcreatesoutside/a.dllbefore asserting, so
canonicalizesucceeds and the assertion exercisesthe rejection path on runners that allow symlink creation. Without the
target file,
resolves_insidecorrectly fails open and the assertion wouldtrip for the wrong reason. The test remains best-effort on hosts without
Developer Mode / elevation.
A negative control with the guard removed fails
escaping_names_are_refused_without_poisoning_the_dedup_set; with the guardrestored all tests pass.
Verification
To run on the pinned toolchain (MSVC build tools, Windows):
cargo test -p victory-loader --lib --lockedcargo clippy -p victory-loader --all-targets --locked -- -D warningscargo clippy -p victory-loader --all-targets --all-features --locked -- -D warningscargo xtask policy- all files okIndependent Windows 11 verification (rustc 1.98.1 MSVC) is reported in the
comments by @oni-swr and @fuzeofficlal: clippy clean, 39 passed / 0 failed
once the symlink target is created, 38 passed / 1 failed before it. Their
runs used synthetic data only. CI on the pushed head is the authoritative
result.
What
Reject static PE import DLL names that would escape the title directory, and
verify the resolved path before reading it. See
## Problem,## Changeand## Scopeabove for the exact entry point, the two-layer check and thelimits.
Tested
The symlink-fixture fix is pushed to the branch; CI on the new head is the
authoritative result (please re-check the
checkrun). Independent Windowsresults are reported in the comments. Synthetic names only, no game data.
Claim: #1633
NEW-221-done: NEW-221 -> #2672posted on the coordinationissue. Synthetic names only, no game data (per
docs/asset-policy.md).Prepared with AI assistance (Chinese Model); reviewed and conducted by Rickeal-Boss.
@Rickeal-Boss on GitHub · 2026-11-26 12:26 UTC · original
Thanks for the triage, and thanks to @kotekompotek @oni-swr @Marvisak and @fuzeofficlal for the independent Windows verification. All three of you
found the same thing, so I have GPT-6 Luna conduct review once again and pushed a test-only fix:
a_symlink_outside_the_title_dir_is_refusednow writesoutside/a.dllbefore the assertion. With the target present,
canonicalizesucceeds andthe assertion exercises the intended rejection path instead of tripping on
resolves_inside's deliberate fail-open behaviour. @oni-swr's scratch runwent from 38 passed / 1 failed to 39 passed / 0 failed with exactly this
one line.
neveris renamedaccept_all(all three call sitesupdated). It accepts everything; the old name read backwards.
is_plain_import_name,resolves_insideandtheir position before
seen.insert/wantedare untouched, since thereviews confirmed the two-layer guard is right.
The description now states the scope explicitly: this guards static PE
import names;
find_moduleinvictory-hle/src/modules/kernel.rsalreadyreduces runtime names to a file name. It also documents the behaviour change
for a DLL symlinked out of the title directory, the small check/use window,
and the junction limitation. The stale "300-PR corpus / max #2616" sentence
is gone, and the claim placeholder is now
NEW-221.CI on the new head is the authoritative result - it is green, could
the
triage: needs worklabel be revisited?Prepared with AI assistance (Chinese Model); reviewed and conducted by Rickeal-Boss.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.