Repository navigation
Loader: forwarders honour LEONIDA_COMPAT_DIR; CLZERO scan keeps VirtualSize 0 sections (RT-LOADER-FORWARDER-COMPAT-CLZERO-SCAN) - #2528
Conversation
… output (BCPACK-TOOL-HARDENING)
…alSize 0 sections resolve() asks resolve_compat() first, so a drop-in DLL in LEONIDA_COMPAT_DIR owns all of its imports. resolve_forwarder() did not, so an export forwarded into such a module still reached its shim, a bundled copy or System32: the module was served half by the drop-in and half by the shim. It now asks resolve_compat() before the shim lookup; a symbol the drop-in lacks stays unbound, as for a direct import. protect_sections() sized the CLZERO scan of an executable section as min(VirtualSize, SizeOfRawData), which is 0 for a section with no virtual size, so its loops were never patched. map_image() takes a virtual size of 0 as the raw size; both now share section_file_bytes(). Found by kevincommits (ProjectLeonida#1608). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed at head Verification
Findings (Request changes)
The AI-assisted review + local MSVC verification. |
… keep a forwarder's own extension From review (timbot103): - resolve_forwarder() returned null for a LEONIDA_COMPAT_DIR module that owns the forwarded name but lacks the export, and resolve() then went on to LoadLibraryEx of the forwarding module's name in System32, so a System32 namesake could still supply it. resolve_forwarder() now reports that miss (compat_miss) and resolve() binds a failure thunk, as it does for a direct import of the compat DLL. - The compat file of a forwarded module is looked up as the bundled module is: the name as given when it has its own extension (winspool.drv), then with .dll, instead of always appending .dll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@timbot103 thank you, both findings were right. They are fixed in e2f9c31:
New
AI-assisted (Claude Code). |
lixonik
left a comment
There was a problem hiding this comment.
Reviewed e2f9c316e and verified the loader test suites on Windows 11.
Code audit:
runtime/src/pe_loader.h,runtime/src/pe_loader.cpp:section_file_bytes()cleanly unifiesmap_image()andprotect_sections()so executable sections withVirtualSize == 0useSizeOfRawDataduring the CLZERO scan.resolve_forwarder()checksLEONIDA_COMPAT_DIRbefore shims and bundled modules (preserving an explicit extension like.drvbefore appending.dll), and propagatescompat_missso a compat drop-in missing a forwarded export binds a failure thunk instead of falling through to System32.
Verification (Windows 11, MSVC 19.44, Ninja Release):
- Built
loader_testandpe_loader_test. ctest -R '^(loader|pe_loader)$': 2/2 passed (loader,pe_loader).python -I scripts/check_no_game_data.py: passed.
AI-assisted (Antigravity, Gemini).
|
Hi @Tyrannys, thanks for this pull request. It currently conflicts with AI-assisted (Claude Code, Claude Opus 5.5). |
…-hardening bcpack_tool: single-pass profile, history overwrite guard, and atomic output (BCPACK-TOOL-HARDENING)
…untime/src/pe_loader.h) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verified by OreoFR
AI-assisted (Claude Code, Claude Opus 5.5). |
Native Windows 11 + MSVC
|
timbot103
left a comment
There was a problem hiding this comment.
Static audit of 0cceb06ee against 48bae6cad. Request changes on the CLZERO scan expansion.
- Major (
runtime/src/pe_loader.cpp:2358,runtime/src/clzero_patch.h:55) The new scan range feeds zero-VirtualSizesections to a byte-pattern matcher that can rewrite inline data or part of an instruction. Gate rewrites on verified instruction boundaries, prefixes and entry points. - Major (
runtime/src/clzero_patch.h:117) A destination fault while RCX is pushed can make Win64 unwind through saved RCX as if it were the return address. Keep affected sites on instruction emulation until stub faults can unwind correctly. - Major, baseline (
runtime/src/pe_loader.cpp:2076) The bundled fallback still accepts a path after the compat lookup rejects it. Validate the forwarder module basename before any lookup. - Minor, baseline (
runtime/src/pe_loader.cpp:775) The MSVC/GATLS scanner still skips raw executable bytes whenVirtualSizeis zero. Reusesection_file_bytes()there.
The new import cases cover compat precedence and owned misses. Please cover the expanded scan with a synthetic zero-VirtualSize PE on Windows without CLZERO, including a destination write fault. AI-assisted static review.
Claimed in the coordination issue as: RT-LOADER-FORWARDER-COMPAT-CLZERO-SCAN (#1608 (comment)). Found by @kevincommits, item 5 of #1608 (comment). Thanks!
What and why
Two loader bugs in
runtime/src/pe_loader.cpp:LEONIDA_COMPAT_DIR.resolve()asksresolve_compat()first, so a drop-in DLL the player put inLEONIDA_COMPAT_DIRowns all of its imports: a module is never served half by a shim and half by the drop-in, which would not share state.resolve_forwarder()never asked it. So an export forwarded into such a module still went to the shim, a bundled copy or System32.Fix:
resolve_forwarder()asksresolve_compat()before the shim lookup, with the same key and file name rule it already uses (".dll"added when the forwarder string leaves it out). A symbol the drop-in lacks stays unbound, as it does for a direct import. The ordinal is now parsed before the lookups, becauseresolve_compat()needs it.VirtualSize == 0.protect_sections()sized the scan of an executable section asmin(VirtualSize, SizeOfRawData), which is 0 for such a section, so its CLZERO loops were never patched on a CPU without CLZERO.map_image()takes a virtual size of 0 as the raw size and copies those bytes.Fix: both now use
section_file_bytes()(inpe_loader.h), so the scan covers exactly the bytesmap_image()copied.Item 4 of the later finding (#1608 (comment):
clzero_patch::patch()leavesVirtualProtectunchecked after patching) is not here: open #2036 already fixes it, so it is left to that PR.Tested
loader_test, intest_compat_modules(CPU only, synthetic images):testshim.F, which the test shim table has) is left unimplemented and does not reach the shim. WithoutLEONIDA_COMPAT_DIRthe same forwarder binds to the shim.mainthe second case fails ("F was not left unimplemented"); with the fix all 102 checks pass. The first case also passes onmainhere, because Windows finds the already loaded compat DLL by name through the System32 search, so the second case is the one that shows the bug.section_file_bytes():static_asserts inloader_test.cpp, including a virtual size of 0. The CLZERO path itself only runs on a CPU without CLZERO; the test machine has it (Zen 5), so that path is covered by the helper it now shares withmap_image()./W4), Release; no new warnings.GPUs tested: n/a (CPU test).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).protect_sections, not to the CLZERO scan; runtime: guard rel32 range, stub_page arithmetic, and VirtualProtect failure in clzero_patch #2036 owns theclzero_patch.hfix.🤖 Generated with Claude Code