mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:05:53 +01:00
[PR #501] [MERGED] pe_loader: refuse an import address table or TLS index in the headers (RT-LOADER-HEADER-WRITES) #551
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#551
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/501
Author: @Kal0s-design
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD
Base:
main← Head:fix/loader-iat-tls-header-writes📝 Commits (1)
db8a0ccpe_loader: refuse an import address table or TLS index in the headers📊 Changes
2 files changed (+60 additions, -0 deletions)
View changed files
📝
runtime/src/pe_loader.cpp(+10 -0)📝
runtime/test/test_pe_loader_bounds.cpp(+50 -0)📄 Description
Claimed in the coordination issue as: RT-LOADER-HEADER-WRITES (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7123988950)
What and why
After
map_image, the loader writes into the mapped image twice beforeprotect_sections: the bound address of every import (bind_imports) and the image's TLS index (initialize_tls). Every later step (parse_exports,protect_sections,register_unwind,initialise,~Loader) reads the headers back from the mapping. AFirstThunkor anAddressOfIndexbelowSizeOfHeaderstherefore replacese_lfanewor the section table, and the next read goes outside the image or uses headers nobody validated. The loader already refuses a section or a base relocation there; this closes the two remaining writes.bind_importsreadsSizeOfHeadersbefore the first address is written and refuses an import address table slot below it ("an import address table lands in the headers"). Delay imports go through the samebind_thunks.initialize_tlsrefuses anAddressOfIndexbelowSizeOfHeaders("the TLS index lands in the headers"). RVA 0 is refused too:index_rvadoubles as "no index", so an index at 0 was silently never written.Found by mutation fuzzing
rt::Loader::load(in-process, neverinitialise(), so no image code runs). Without this change, 11 of 30,000 mutated images crashedprotect_sections, all with an import address table moved into the headers.Tested
Windows 11, Visual Studio 18 (MSVC), Ninja, RelWithDebInfo, on current
main(8f481cf16) plus this commit. CPU only: no GPU is involved and no game files were used.test_pe_loader_boundswith this changeruntime/src/pe_loader.cpptaken frommainexpected image rejection, but Loader::load succeeded); the two "at exactly SizeOfHeaders loads" cases pass both wayspe_loader,pe_loader_bounds,loader,loader_tls,run_tiny_game*(15 tests)ctestgameinputis disabled in CMakepython -m compileall -q make_game.py tools testsscripts/check_no_game_data.pyon the two changed filesThe one failure is
d3d12_execute_indirect_validation. Its target does not linkpe_loader.cpp, so this change cannot affect it; I did not investigate it.Not covered: Linux and macOS (the loader and this test are Windows and MSVC only), and the retail executable (no game files here), so whether any shipped module has such a table is not checked. The same change was checked independently by several people on the pull request in the original repository before it went private; those results do not carry over, so the numbers above are my own.
GPUs tested: n/a (CPU only)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (Not applicable: no translator rule.)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
latencyframes in flight while armed (mailbox replace) #712