PE loader: refuse IAT and TLS-index writes inside the headers (#836) #854

Open
github-bot wants to merge 1 commit from github-bot/gh-854 into main AGit
Owner

@⁠Longno242 on GitHub · 2026-11-24 06:51 UTC · original
Longno242:pe-loader-header-write-targets → main · +179 −2 · 1 files · 1 commits · open

Fixes #836.

A crafted PE whose import address table, delay-load HMODULE slot, or TLS AddressOfIndex lands below SizeOfHeaders would let the manual mapper overwrite its own headers before later steps re-read them. Reject those directory-derived write targets once in pe.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 the SizeOfHeaders boundary

Tested

  • Hardware/OS (full suite by @⁠upipibi, head 6ce1240498cd787448963da24cd8f5e892feb0da as-is, base 47efa2e): NVIDIA RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after cargo build --workspace
  • cargo 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, both no wave64 on this card. hle::xaudio2 was skipped because those tests fail or hang on this machine on main too; this PR does not touch it.
  • Retail smoke: see Regression run (@⁠Toons29, RX 9070)
  • Earlier on this machine: cargo test -p xcl --lib pe::tests: 14 passed (includes the delay-load HMODULE case). @⁠DavidM1911 also ran cargo test -p xcl --lib after merging the branch with then-current main (RTX 3060 Ti): passed, with a note about intermittent #1978 under parallel scheduling.

Regression run

  • Retail scripts/smoke.ps1 from @⁠Toons29 (RX 9070, 60 s, same title/time; blocks as printed):
xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 6ce1240498cd787448963da24cd8f5e892feb0da
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1633 (PresentX 1633)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14686 MB

Not tested

  • hle::xaudio2 on the RTX 3070 report (pre-existing on main for that machine)
  • wave64-only GPU paths
  • live title coverage of the header-write rejection itself (smoke is a regression check only)

AI use

  • @⁠upipibi: Claude Code (Claude Opus 5.5) ran the workspace suite and wrote the test report
  • Cursor Auto (Composer): found #836 uncovered by open PRs, implemented the parse-time rejection and tests, rebased onto main, added the delay-load HMODULE coverage test, opened/updated this draft PR. Exact underlying model name not disclosed to the agent.
**@⁠Longno242** on GitHub · 2026-11-24 06:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/854) `Longno242:pe-loader-header-write-targets` → `main` · +179 −2 · 1 files · 1 commits · open Fixes #836. A crafted PE whose import address table, delay-load HMODULE slot, or TLS `AddressOfIndex` lands below `SizeOfHeaders` would let the manual mapper overwrite its own headers before later steps re-read them. Reject those directory-derived write targets once in `pe.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 the `SizeOfHeaders` boundary **Tested** - Hardware/OS (full suite by @⁠upipibi, head `6ce1240498cd787448963da24cd8f5e892feb0da` as-is, base `47efa2e`): NVIDIA RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after `cargo build --workspace` - `cargo 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, both `no wave64` on this card. `hle::xaudio2` was skipped because those tests fail or hang on this machine on `main` too; this PR does not touch it. - Retail smoke: see **Regression run** (@⁠Toons29, RX 9070) - Earlier on this machine: `cargo test -p xcl --lib pe::tests`: 14 passed (includes the delay-load HMODULE case). @⁠DavidM1911 also ran `cargo test -p xcl --lib` after merging the branch with then-current `main` (RTX 3060 Ti): passed, with a note about intermittent #1978 under parallel scheduling. **Regression run** - Retail `scripts/smoke.ps1` from @⁠Toons29 (RX 9070, 60 s, same title/time; blocks as printed): ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: 6ce1240498cd787448963da24cd8f5e892feb0da gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1633 (PresentX 1633) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14686 MB ``` **Not tested** - `hle::xaudio2` on the RTX 3070 report (pre-existing on `main` for that machine) - wave64-only GPU paths - live title coverage of the header-write rejection itself (smoke is a regression check only) **AI use** - @⁠upipibi: Claude Code (Claude Opus 5.5) ran the workspace suite and wrote the test report - Cursor Auto (Composer): found #836 uncovered by open PRs, implemented the parse-time rejection and tests, rebased onto main, added the delay-load HMODULE coverage test, opened/updated this draft PR. Exact underlying model name not disclosed to the agent.
A crafted image whose FirstThunk or TLS AddressOfIndex lands below
SizeOfHeaders would overwrite the mapped headers before they are
re-read. Reject those write targets in pe.rs once
(PeError::HeaderWriteTarget), including delay-load HMODULE slots.

Fixes #836

Assisted-by: Cursor Auto (Composer)
Co-authored-by: Cursor <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:34:39 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 07:50 UTC · original

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):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
716 passed; 0 failed; 41 ignored   (exit 0)

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.

**@⁠dcastell1** on GitHub · 2026-11-24 07:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7125438914) 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): ``` patch -p1 < this PR # clean, no fuzz cargo test --workspace -- --test-threads=4 716 passed; 0 failed; 41 ignored (exit 0) ``` 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.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-24 08:09 UTC · original

Linux / AMD RDNA3 datapoint.

Merged state: head 46376c5 onto main 1ec4c98, 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 of gpu_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.

**@⁠SlopTart** on GitHub · 2026-11-24 08:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7125793967) Linux / AMD RDNA3 datapoint. **Merged state:** head `46376c5` onto main `1ec4c98`, 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 of `gpu_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.
Author
Owner

@⁠Longno242 on GitHub · 2026-11-24 12:51 UTC · original

Thanks for the independent verification runs (@⁠dcastell1, @⁠SlopTart).

This PR still needs the two retail xcl-smoke blocks 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:

# on main, then on this PR head (clean tree, no uncommitted changes)
cargo build --release -p xcl
.\scripts\smoke.ps1 -Game '<Series title folder>' -Seconds 60

and paste both xcl-smoke v1 blocks (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.

**@⁠Longno242** on GitHub · 2026-11-24 12:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7132012085) Thanks for the independent verification runs (@⁠dcastell1, @⁠SlopTart). This PR still needs the two retail `xcl-smoke` blocks 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: ```powershell # on main, then on this PR head (clean tree, no uncommitted changes) cargo build --release -p xcl .\scripts\smoke.ps1 -Game '<Series title folder>' -Seconds 60 ``` and paste both `xcl-smoke v1` blocks (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.
Author
Owner

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

Regression run of 6ce12404 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 6ce1240498cd787448963da24cd8f5e892feb0da
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1633 (PresentX 1633)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14686 MB

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.

**@⁠Toons29** on GitHub · 2026-11-25 03:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7151555283) Regression run of `6ce12404` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: 6ce1240498cd787448963da24cd8f5e892feb0da gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1633 (PresentX 1633) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14686 MB ``` 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 10:15 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-25 10:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7159452783) 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!
Author
Owner

@⁠Longno242 on GitHub · 2026-11-25 12:36 UTC · original

Thanks @⁠Toons29 — pasted both of your xcl-smoke v1 blocks under Regression run so the description check can see them.

**@⁠Longno242** on GitHub · 2026-11-25 12:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7162607568) Thanks @⁠Toons29 — pasted both of your `xcl-smoke v1` blocks under **Regression run** so the description check can see them.
Author
Owner

@⁠Longno242 on GitHub · 2026-11-25 12:43 UTC · original

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.

**@⁠Longno242** on GitHub · 2026-11-25 12:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7162771486) 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.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 19:51 UTC · original

NVIDIA test report for 6ce1240 (head as is, base 47efa2e), for #1607's "one more test report" list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after cargo 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.
  • Skipped hle::xaudio2, because its tests fail or hang on this machine on main too. The PR doesn't touch it.
  • SKIPPED lines: 2, both no wave64 on this card.

AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.

**@⁠upipibi** on GitHub · 2026-11-25 19:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7172849832) NVIDIA test report for `6ce1240` (head as is, base `47efa2e`), for #1607's "one more test report" list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, after `cargo 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. - Skipped `hle::xaudio2`, because its tests fail or hang on this machine on `main` too. The PR doesn't touch it. - SKIPPED lines: 2, both `no wave64` on this card. AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
Author
Owner

@⁠Longno242 on GitHub · 2026-11-26 12:33 UTC · original

Thanks @⁠upipibi — copied the workspace counts for 6ce1240 into Tested (736 passed, 0 failed, 41 ignored, hle::xaudio2 skipped).

**@⁠Longno242** on GitHub · 2026-11-26 12:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/854#issuecomment-7192156383) Thanks @⁠upipibi — copied the workspace counts for `6ce1240` into **Tested** (736 passed, 0 failed, 41 ignored, `hle::xaudio2` skipped).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/854/head:github-bot/gh-854'
git switch 'github-bot/gh-854'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-854'
git switch 'github-bot/gh-854'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-854'
git switch 'github-bot/gh-854'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-854'
git switch 'main'
git merge --squash 'github-bot/gh-854'
git switch 'main'
git merge --ff-only 'github-bot/gh-854'
git switch 'main'
git merge 'github-bot/gh-854'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.