PE loader: refuse IAT and TLS-index writes inside the headers (#836) #848
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/854"
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?
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-24T06:51:47Z.
Fixes #836.
A crafted PE whose import address table, delay-load HMODULE slot, or TLS
AddressOfIndexlands belowSizeOfHeaderswould let the manual mapper overwrite its own headers before later steps re-read them. Reject those directory-derived write targets once inpe.rs(PeError::HeaderWriteTarget). Targets must lie in[size_of_headers, size_of_image).What is in it
crates/xcl/src/pe.rs:ensure_data_write_rva, checks in import thunks / delay-load HMODULE / TLS index parsing, and unit tests for IAT, delay-load HMODULE, and TLS index inside the headers plus theSizeOfHeadersboundaryTested
6ce1240498cd787448963da24cd8f5e892feb0daas-is, base47efa2e): NVIDIA RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, aftercargo build --workspacecargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2: 736 passed, 0 failed, 41 ignored. End-to-end title tests passed.SKIPPED: 2 GPU tests, bothno wave64on this card.hle::xaudio2was skipped because those tests fail or hang on this machine onmaintoo; this PR does not touch it.6ce1240498cd787448963da24cd8f5e892feb0da, RTX 4060 8 GB (Ada, wave32), driver 32.0.16.2114, i5-11400F, 32 GB, Windows 11 build 26200, rustc 1.100.0, DXC 1.9.2609.5: the four header-write tests passed 3/3 (4 passed, 0 failed), andcargo test --release -p xcl --lib pe::passed 3/3 (14 passed, 0 failed).cargo build --release -p xclwas clean.cargo test -p xcl --lib pe::tests: 14 passed (includes the delay-load HMODULE case). @DavidM1911 also rancargo test -p xcl --libafter merging the branch with then-currentmain(RTX 3060 Ti): passed, with a note about intermittent #1978 under parallel scheduling.Regression run
scripts/smoke.ps1from @Toons29 (RX 9070, 60 s, same title/time; blocks as printed):Not tested
hle::xaudio2on the RTX 3070 report (pre-existing onmainfor that machine)AI use
pe::tests and drafted the reportImported from ivall/xcl. Originally posted by dcastell1 on 2026-11-24T07:50:57Z.
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on clean
main@beaa245(713 passed, 0 failed, 41 ignored on this box):Three more passing tests than main, so the PE-loader refusals for IAT and TLS-index writes inside the headers are exercised here; nothing else changes verdict.
Tree restored afterwards (md5 and a full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-24T08:09:30Z.
Linux / AMD RDNA3 datapoint.
Merged state: head
46376c5onto main1ec4c98, clean merge.Full suite,
cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 707 passed, 11 failed, 41 ignored. Failures = the known Wine-lane set from my #42 rows plus #718 trio members and a hit ofgpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes(new flake, see #718 addendum). PE-header write-rejection tests green - closes the #836 hardening on this rig.Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.
Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross
x86_64-pc-windows-gnu,XCL_NETWORK=0, release profile,--test-threads=4. My Linux rows: #42 / #718.AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-24T12:51:24Z.
Thanks for the independent verification runs (@dcastell1, @SlopTart).
This PR still needs the two retail
xcl-smokeblocks under Regression run (main + this head, same title/time) before the description check can pass. I do not have an Xbox Series X|S package here — only a PC Xbox Minecraft Launcher install, which is not a Scarlett title.If someone with a Series title can run:
and paste both
xcl-smoke v1blocks (or drop them here so I can add them to the description), that would unblock merge review. Happy to update the PR body and mark ready once those are in.No game data needed in the comment — only the smoke block text.
upstream-sync referenced this pull request2026-11-24 22:05:13 +00:00
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:03:58Z.
Regression run of
6ce12404on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 101 % of
main's frames, 99 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; I checked the blocks before posting.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T10:15:43Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-25T12:36:29Z.
Thanks @Toons29 — pasted both of your
xcl-smoke v1blocks under Regression run so the description check can see them.Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-25T12:43:39Z.
CI is stuck on
action_required(first-time contributor workflow approval). Smoke + PR description are green; please approve the pending CI workflow when you get a chance.Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T19:51:09Z.
NVIDIA test report for
6ce1240(head as is, base47efa2e), for #1607's "one more test report" list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, aftercargo build --workspace:cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2: 736 passed, 0 failed, 41 ignored. The end-to-end title tests pass.hle::xaudio2, because its tests fail or hang on this machine onmaintoo. The PR doesn't touch it.no wave64on this card.AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-26T12:33:28Z.
Thanks @upipibi — copied the workspace counts for
6ce1240into Tested (736 passed, 0 failed, 41 ignored,hle::xaudio2skipped).Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T16:33:53Z.
Review: COMMENTED
AI-assisted review: I inspected the diff and the loader write sites; I did not run tests.
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T16:33:54Z.
Code review location:
crates/xcl/src/pe.rs; line 416Could this validate the full write width, not only the starting RVA?
thunksaccepts an IAT slot atSizeOfImage - 4because that start is in range, but the loader writes an entireu64there (loader.rsIAT and delay-load module-handle writes); similarly, the TLS index write is au32. A malformed image can therefore pass this new guard and make the loader write past the mapped image. Please use a checked[rva, rva + width)range check for each target and add upper-bound cases where the slot starts inside the image but ends beyondSizeOfImage. AI-assisted review: I inspected the diff and the loader write sites; I did not run tests.Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-27T09:34:34Z.
Code review location:
crates/xcl/src/pe.rs; line 416The start-only check on this PR is the header case (#836). The full write is checked in #1203, which is the next commit on this branch.
ensure_data_write_rva(rva, width)requires[rva, rva + width)to sit in[SizeOfHeaders, SizeOfImage), withchecked_addso the end cannot wrap. Call sites pass the width the loader actually stores: 8 for an IAT slot and a delay-load HMODULE, 4 for the TLSAddressOfIndex.Upper-bound tests on that PR:
import_address_table_straddling_image_end_is_error— IAT atSizeOfImage - 4, rejected asBadRvatls_index_straddling_image_end_is_error— TLS index atSizeOfImage - 2, rejected asBadRvaThere is no separate delay-load HMODULE straddle test; that slot uses the same width-8 check as the IAT.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T10:45:38Z.
Independent desktop NVIDIA verification of PR #854 at head
6ce1240498cd787448963da24cd8f5e892feb0da(1commit; exact parent & merge-base:47efa2ecea0a12934719ae69b81930cf02a4b1c3, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted tests & build (
6ce12404)cargo test --release -p xcl --lib -- --nocapture import_address_table_in_headers_is_error tls_index_in_headers_is_error delay_import_module_handle_in_headers_is_error write_targets_at_size_of_headers_are_accepted(3 consecutive runs)4 passed; 0 failed; 0 ignored; 719 filtered out× 3 (0.00s,0.00s,0.00s,0skipped)cargo test --release -p xcl --lib pe:: -- --nocapture(3 consecutive runs)14 passed; 0 failed; 0 ignored; 709 filtered out× 3 (0.00s,0.00s,0.01s,0skipped)cargo build --release -p xcl55.45s, exit0,0new warnings inpe.rs)Paired quiet 60 s retail smoke (
title: 29640639)(Note:
scripts/smoke.ps1at47efa2ecpredates9683e7a6and printed the local folder basename ontitle:; replaced below with the standard9683e7a6title hash29640639, with all measured fields verbatim.)Exact parent & merge-base (
47efa2ecea0a12934719ae69b81930cf02a4b1c3):PR #854 (
6ce1240498cd787448963da24cd8f5e892feb0da):Limits of coverage
#836header-write rejection / boundary tests (import_address_table_in_headers_is_error,tls_index_in_headers_is_error,delay_import_module_handle_in_headers_is_error,write_targets_at_size_of_headers_are_accepted) plus the fullpe::suite (14/14,0skipped) passed3/3.0device removals,0crashes, steady 60 Hz); single-run frame/commit delta vs. parent reflects normal startup variance.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by Longno242 on 2026-11-27T14:15:28Z.
Thanks @Decodere. The release
pe::results for6ce12404are in Tested (four header-write tests 3/3, fullpe::14/14 3/3).The smoke blocks stay in this comment.
scripts/smoke.ps1printed a folder name ontitle:, and that line was replaced with29640639before posting. Regression run keeps the unedited pair from @Toons29 for this same head.Imported from ivall/xcl. Originally posted by relativespace2K on 2026-11-30T03:24:25Z.
merge-check
base:
53e85fb1head:
6ce1240498merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2792 passed, 6 failed, 49 ignored; failing: gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form, gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, ram_budget::tests::windows_takes_a_working_set_maximum_and_lifts_it, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (in
--test gpu_two_pass_cache_e2e, so 5 failing tests give 6 failures). The same five fail on base53e85fb1alone (2788 passed, 6 failed, 49 ignored there), so none comes from this PR; its four new tests passed. 13 SKIPPED lines, all environmental: no D3D12 debug layer / d3d12SDKLayers.dll, no heap windows, no GPU_UPLOAD, per-lane f16/f32 forms refused.review: no blocking finding; one file, every hunk read. One predicate,
rva >= SizeOfHeaders && rva < SizeOfImage, now guards the three places the loader writes into a mapped image: each IAT slot as the thunks are walked, the delay-load HMODULE slot, and the TLSAddressOfIndex(with RVA 0 still meaning "no index"). Refusing the header range is right because those writes would land on the DOS/NT headers that the loader itself has already read and that a later step still needs; the upper bound reuses the existingBadRva, so nothing that was previously accepted beyondSizeOfImagechanges. The tests build real little PE images for the three refusals and one acceptance at exactlySizeOfHeaders, which is the boundary that decides whether a legitimate image is turned away. Notes, not blocking: the TLS branch reportsBadRva(0)rather than the address it refused (cosmetic in the message only), and a title whose IAT really does live in the headers would now fail to load instead of corrupting itself, which is the intent of #836 but is the one behaviour change to keep in mind. No duplicate: #854 is the only one touching this; #291 and #1217 are other loader fixes.performance: one comparison per IAT slot and per delay-load entry, at load time.
verdict: safe to merge
hardware / tool and model: AMD Radeon RX 6800 XT 16 GB (RDNA2, wave64), driver 32.0.21045.29003; Ryzen 5 5600, 32 GB RAM; Windows 10 IoT Enterprise LTSC 2024, 10.0.26100 build 26100.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build. DeepSeek Harness coding agent, model DeepSeek V4.1 Flash.
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T03:25:58Z.
merge-check claim
head:
6ce1240498Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T03:31:56Z.
merge-check
base:
cfb9753a8chead:
6ce1240498merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2837 passed, 1 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check: diff read for safety (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
Imported from ivall/xcl. Originally posted by Elytes on 2026-11-30T10:21:47Z.
merge-check
base:
9dfbe3ea66head:
6ce1240498merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2889 passed, 1 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer, 1 driver cache needs Developer Mode); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, also failing on the base alone (base lib 2737 passed / 1 failed, merge 2741 / 1; the +4 are this PR's tests, passing).
review: no blocking finding after reading the whole diff and the comments. Real PEs:
xcl inspect --jsonon 18 PE files of a retail title (its exe, 16 DLLs and one .bin; 1,924 IAT slots, 4 with TLS, no delay imports) gives byte-identical output on base and merge, so no legitimate import or TLS index is refused there. The delay-load HMODULE check is covered by its unit test only. Note, not blocking: loader.rs fails the load on an imports() error, but only warns on a delay_imports() error (the module then loads with no delay imports) and skips TLS silently on a tls() error, so a crafted delay-load HMODULE or TLS index in the headers now gives a module loaded without them rather than a refused load. That is how those paths already treat BadRva.performance: one bounds check per IAT slot and per delay-load / TLS directory at load time (reasoned).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.100.1, debug / Claude Code (Claude Opus 5.5) ran the merge, build, suite and the inspect comparison on base and merge, and reviewed the diff, loader.rs and the comments.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:19:23Z.
Triage (#1607) – head
6ce1240#1203 (same author) is stacked on this PR: it contains this commit and adds a width check on top, so it is not a duplicate and this PR should land first. #1367 bounds IAT/HMODULE/relocation writes against SizeOfImage in loader.rs and pe.rs but does not refuse targets inside the headers, so it does not cover #836.
Minor: pe.rs tls() reports a TLS AddressOfIndex that va_to_rva cannot map as BadRva(0) rather than the VA.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.