Skip to content

D3D12-LOADER-CRASH-MEMORY-AT-ISOLATION: remove post-MEM_RELEASE VA-reuse race in memory_at test - #2939

Open
bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-crash-memory-at-race
Open

bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-crash-memory-at-race

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-LOADER-CRASH-MEMORY-AT-ISOLATION (#2570 (comment); ref finding #2570 (comment))

What and why

crash::tests::memory_at_names_what_an_access_hit (d3d12/crates/leonida-loader/src/crash.rs:915) called VirtualFree(base, 0, MEM_RELEASE) and then immediately asserted assert_eq!(memory_at(base + 8), "nothing mapped there").

Under parallel leonida-loader test runs (including Windows CI), another test thread can reclaim the just-released VA range via VirtualAlloc(..., PAGE_READWRITE) or the heap allocator before VirtualQuery runs, causing intermittent failures (left: "read-write", right: "nothing mapped there").

Fix: remove the racy post-MEM_RELEASE query on base and exercise MEM_FREE against both 0 and 0x1008 in Windows' permanently unmapped low-64 KiB guard region (0..0x10000).

Tested

  • Windows 11, Rust 1.98.1, cargo test --locked -p leonida-loader --lib crash::tests: 19 passed, 0 failed.
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/crash.rs: clean.

GPUs tested: n/a (CPU/OS virtual-memory query test; Windows 11).

AI-assisted: yes — Gemini 4 Neon (implementation and an independent read-only reviewer pass).

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.

@merzleckeier

Copy link
Copy Markdown
Contributor

Controlled address-reuse check under Wine on 561bbc19 merged into 1e3e316c. The unmodified memory_at_names_what_an_access_hit passed 3/3 on main, this PR, and this PR combined with #2946. Then I added the same test-only synchronization on all three trees. A worker in the same process reclaims the fixture’s exact released reservation before the old post-release check. In all nine probe runs the reclaimed address reported read-write. Main failed 3/3 at the old nothing mapped there assertion. This PR and the combined tree each passed 3/3, including the low-address and module checks.

With the original Cargo binary basename the stock crash tests passed 19/19 on this PR. The combined crash/profile/stack groups passed 23/23, including #2946’s closed-stderr test. This covers the test behavior under controlled reuse on Wine 11.22.

MEASURED with synthetic inputs, OpenAI Codex and a separate read-only review.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is right, and deletion is the only sound option: after MEM_RELEASE the test has handed the range back to the process, so any post-free VirtualQuery on base is unsound — narrowing the window would not have helped. The low-64 KiB anchor is valid (Windows keeps 0..0x10000 permanently MEM_FREE; I verified memory_at(0) and memory_at(0x1008) both return "nothing mapped there" on Win11 26200), and the PR no longer touches base after the free, so re-reservation cannot bite. crash::tests is 19/19 over 40 runs, and the old assertion is provably wrong: when I reverted it and added a throwaway free-then-VirtualAlloc-same-base probe, memory_at(base + 8) reported "read-write".

Two nits, neither blocking:

  • memory_at(0x1008) is the same MEM_FREE region as the pre-existing memory_at(0), so it adds no coverage — harmless, just not a second case.
  • The test now asserts nothing about MEM_RELEASE actually freeing the range. That is inherently untestable in-process, but worth stating explicitly rather than losing it silently.

Merge is clean against current main, and the textual overlap with #2946 is file-only (hunks are disjoint); #2947 does not touch crash.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants