VFS: fix MergedFind UAF and add null pointer checks (#1388) #1652

Closed
hajduzsolt wants to merge 1 commit from upstream-pr/1662 into main
hajduzsolt commented 2026-11-24 18:53:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by hajduzsolt on 2026-11-24T18:53:55Z.


Fix a use-after-free and null-pointer dereference in the VFS MergedFind
iterator, and add null-pointer guards in find_first_vfs, hk_find_next_w,
and hk_find_next_a (#1388).

What is in it

  • Replace MERGED: Mutex<Option<HashSet<usize>>> + raw Box::into_raw/Box::from_raw pointer round-trips with MERGED: Mutex<Option<HashMap<usize, MergedFind>>> keyed by opaque odd synthetic handles; the lock is held across the lookup + increment so the iterator cannot alias or dangle.
  • Guard find_first_vfs, hk_find_next_w, and hk_find_next_a against null lpFindFileData by returning ERROR_INVALID_PARAMETER (87) early.
  • Add unit test merged_find_null_data_and_close_are_safe that fails without the fix.

Tested

  • Hardware & toolchain: AMD Radeon RX 9070 XT, AMD Ryzen 7 9800X3D, Windows 11 x64, rustc 1.98.1 (48a229cea 2026-09-01), debug (cargo test).
  • cargo test -p xcl --lib vfs_hooks::tests -- --test-threads=2: 11 passed; 0 failed; 0 ignored.
  • cargo test --workspace -- --test-threads=2: 778 passed; 0 failed; 41 ignored.

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 49 48 14
device removals: 0
crashes: 0
peak commit: 20195 MB

PR:

xcl-smoke v1
commit: d3a962fa8aa89c01a26e0644b2582c261a575ec7
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1676 (PresentX 1676)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14836 MB

Not tested

  • NVIDIA / Intel GPUs, wave32-only adapters, and gameplay beyond title menus.
  • Directory enumeration across nested VFS mount points with simultaneous FindFirstFile/FindNextFile calls from multiple threads.

AI use

  • Antigravity (Gemini 4 Hydrogen, high): HashMap-keyed handle table design, null-pointer guard placement, and unit test scaffolding; verified with workspace unit tests and local RX 9070 XT smoke run.
<!-- greyfinch-sync:ivall/xcl:issue:5478366757 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1662). Originally posted by [hajduzsolt](https://github.com/hajduzsolt) on 2026-11-24T18:53:55Z. --- Fix a use-after-free and null-pointer dereference in the VFS `MergedFind` iterator, and add null-pointer guards in `find_first_vfs`, `hk_find_next_w`, and `hk_find_next_a` (#1388). **What is in it** - Replace `MERGED: Mutex<Option<HashSet<usize>>>` + raw `Box::into_raw`/`Box::from_raw` pointer round-trips with `MERGED: Mutex<Option<HashMap<usize, MergedFind>>>` keyed by opaque odd synthetic handles; the lock is held across the lookup + increment so the iterator cannot alias or dangle. - Guard `find_first_vfs`, `hk_find_next_w`, and `hk_find_next_a` against null `lpFindFileData` by returning `ERROR_INVALID_PARAMETER` (87) early. - Add unit test `merged_find_null_data_and_close_are_safe` that fails without the fix. **Tested** - Hardware & toolchain: AMD Radeon RX 9070 XT, AMD Ryzen 7 9800X3D, Windows 11 x64, `rustc 1.98.1 (48a229cea 2026-09-01)`, debug (`cargo test`). - `cargo test -p xcl --lib vfs_hooks::tests -- --test-threads=2`: 11 passed; 0 failed; 0 ignored. - `cargo test --workspace -- --test-threads=2`: 778 passed; 0 failed; 41 ignored. **Regression run** main: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1594 (PresentX 1594) presents per 2 s (last 3): 49 48 14 device removals: 0 crashes: 0 peak commit: 20195 MB ``` PR: ``` xcl-smoke v1 commit: d3a962fa8aa89c01a26e0644b2582c261a575ec7 gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1676 (PresentX 1676) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14836 MB ``` **Not tested** - NVIDIA / Intel GPUs, wave32-only adapters, and gameplay beyond title menus. - Directory enumeration across nested VFS mount points with simultaneous `FindFirstFile`/`FindNextFile` calls from multiple threads. **AI use** - Antigravity (Gemini 4 Hydrogen, high): HashMap-keyed handle table design, null-pointer guard placement, and unit test scaffolding; verified with workspace unit tests and local RX 9070 XT smoke run.
MiharaxD commented 2026-11-24 21:08:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MiharaxD on 2026-11-24T19:27:17Z.


Test report on an NVIDIA card, head d3a962f (on main c160d86), which covers the "NVIDIA" line.

Tested

  • RTX 3070 Ti 8 GB (8017 MiB dedicated, driver 621.01), Intel i5-14400F, 32 GB RAM, Windows 11 Pro 10.0.26300, Rust 1.100.0, DXC 1.9.2602.17.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 (debug) on d3a962f: 859 passed, 0 failed, 42 ignored (lib tests 810 / 0 / 22). merged_find_null_data_and_close_are_safe passes.
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60 (release builds, start screen, no input). main is c160d86:

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 3070 Ti
title: game
seconds: 60
exit: 0x0
frames shown: 1586 (PresentX 1586)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15055 MB

this PR's head:

xcl-smoke v1
commit: d3a962fa8aa89c01a26e0644b2582c261a575ec7
gpu: NVIDIA GeForce RTX 3070 Ti
title: game
seconds: 60
exit: 0x0
frames shown: 1601 (PresentX 1601)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15398 MB

Not tested

  • Nested VFS mounts and FindFirstFile / FindNextFile from several threads at once; the smoke is a regression check only.
  • AMD / Intel, gameplay past the start screen.

AI use: Claude Code (Claude Opus 5.5) built the PR, ran the tests and both smoke runs, read the logs and wrote this report; I checked it before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7142119844 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1662#issuecomment-7142119844). Originally posted by [MiharaxD](https://github.com/MiharaxD) on 2026-11-24T19:27:17Z. --- Test report on an NVIDIA card, head `d3a962f` (on `main` `c160d86`), which covers the "NVIDIA" line. **Tested** - RTX 3070 Ti 8 GB (8017 MiB dedicated, driver 621.01), Intel i5-14400F, 32 GB RAM, Windows 11 Pro 10.0.26300, Rust 1.100.0, DXC 1.9.2602.17. - `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4` (debug) on `d3a962f`: **859 passed, 0 failed, 42 ignored** (lib tests 810 / 0 / 22). `merged_find_null_data_and_close_are_safe` passes. - SKIPPED: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). **Regression run** `scripts/smoke.ps1 -Game <game folder> -Seconds 60` (release builds, start screen, no input). `main` is `c160d86`: main: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 3070 Ti title: game seconds: 60 exit: 0x0 frames shown: 1586 (PresentX 1586) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15055 MB ``` this PR's head: ``` xcl-smoke v1 commit: d3a962fa8aa89c01a26e0644b2582c261a575ec7 gpu: NVIDIA GeForce RTX 3070 Ti title: game seconds: 60 exit: 0x0 frames shown: 1601 (PresentX 1601) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15398 MB ``` **Not tested** - Nested VFS mounts and `FindFirstFile` / `FindNextFile` from several threads at once; the smoke is a regression check only. - AMD / Intel, gameplay past the start screen. **AI use:** Claude Code (Claude Opus 5.5) built the PR, ran the tests and both smoke runs, read the logs and wrote this report; I checked it before posting.
DavidM1911 commented 2026-11-24 21:30:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T21:26:28Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7144933166 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1662#issuecomment-7144933166). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T21:26:28Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. Thanks!
upipibi commented 2026-11-25 21:05:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T20:15:51Z.


NVIDIA test report for d3a962f (head as is, base c160d86), 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: 850 passed, 0 failed, 42 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: 3: 2 no wave64 on this card, 1 no heap windows.

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

<!-- greyfinch-sync:ivall/xcl:comment:7173413261 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1662#issuecomment-7173413261). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T20:15:51Z. --- NVIDIA test report for `d3a962f` (head as is, base `c160d86`), 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`: **850 passed, 0 failed, 42 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: 3: 2 `no wave64` on this card, 1 no heap windows. AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
Decodere commented 2026-11-27 11:18:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T11:18:31Z.


Independent desktop NVIDIA verification of PR #1662 at head d3a962fa8aa89c01a26e0644b2582c261a575ec7 (1 commit; exact parent & merge-base: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted tests & build (d3a962fa)

Command Result
cargo test --release -p xcl --lib merged_find_null_data_and_close_are_safe -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 831 filtered out × 3 (0.00s, 0.00s, 0.00s, 0 skipped)
cargo test --release -p xcl --lib vfs_hooks:: -- --nocapture (3 consecutive runs) 11 passed; 0 failed; 0 ignored; 821 filtered out × 3 (0.01s, 0.01s, 0.01s, 0 skipped)
cargo build --release -p xcl Clean build (1m 20s, exit 0, 0 new warnings in vfs_hooks.rs)

Paired quiet 60 s retail smoke (title: 29640639)

(Note: scripts/smoke.ps1 at c160d86e predates 9683e7a6 and printed the local folder basename on title:; replaced below with the standard 9683e7a6 title hash 29640639, with all measured fields verbatim.)

Exact parent & merge-base (c160d86ef2efe3a07e4dfb473e4fa72eafb413c0):

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1533 (PresentX 1533)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14721 MB

PR #1662 (d3a962fa8aa89c01a26e0644b2582c261a575ec7):

xcl-smoke v1
commit: d3a962fa8aa89c01a26e0644b2582c261a575ec7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1567 (PresentX 1567)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14722 MB

Limits of coverage

  • merged_find_null_data_and_close_are_safe and all 11/11 vfs_hooks:: unit tests (0 skipped) passed 3/3 on Windows 11 NTFS, directly covering the #1388 MergedFind handle-table lifetime fix and null-pointer guards.
  • The 60 s retail smoke confirms live VFS directory enumeration and runtime stability (0 device removals, 0 crashes, 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).

<!-- greyfinch-sync:ivall/xcl:comment:7216923145 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1662#issuecomment-7216923145). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-27T11:18:31Z. --- Independent desktop NVIDIA verification of **PR #1662** at head `d3a962fa8aa89c01a26e0644b2582c261a575ec7` (`1` commit; exact parent & merge-base: `c160d86ef2efe3a07e4dfb473e4fa72eafb413c0`, pre-`#2555` ancestor of `main`). ### Environment - **GPU:** NVIDIA GeForce RTX 4060 (8 GB / `7956 MiB` reported by D3D12, Wave32-only Ada), driver `32.0.16.2114` (NVIDIA `621.14`, WDDM 3.2) - **CPU / RAM / OS:** Intel Core i5-11400F (6C / 12T), 32 GB RAM (`31.9 GiB` usable), Windows 11 Home `26200` (Developer Mode off) - **Toolchain:** `rustc 1.100.0 (0ef1bc386 2026-11-09)` MSVC, DXC `1.9.2609.5`, `--release` ### Targeted tests & build (`d3a962fa`) | Command | Result | | --- | --- | | `cargo test --release -p xcl --lib merged_find_null_data_and_close_are_safe -- --nocapture` (3 consecutive runs) | `1 passed; 0 failed; 0 ignored; 831 filtered out` × 3 (`0.00s`, `0.00s`, `0.00s`, `0` skipped) | | `cargo test --release -p xcl --lib vfs_hooks:: -- --nocapture` (3 consecutive runs) | `11 passed; 0 failed; 0 ignored; 821 filtered out` × 3 (`0.01s`, `0.01s`, `0.01s`, `0` skipped) | | `cargo build --release -p xcl` | Clean build (`1m 20s`, exit `0`, `0` new warnings in `vfs_hooks.rs`) | ### Paired quiet 60 s retail smoke (`title: 29640639`) *(Note: `scripts/smoke.ps1` at `c160d86e` predates `9683e7a6` and printed the local folder basename on `title:`; replaced below with the standard `9683e7a6` title hash `29640639`, with all measured fields verbatim.)* Exact parent & merge-base (`c160d86ef2efe3a07e4dfb473e4fa72eafb413c0`): ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1533 (PresentX 1533) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14721 MB ``` PR #1662 (`d3a962fa8aa89c01a26e0644b2582c261a575ec7`): ``` xcl-smoke v1 commit: d3a962fa8aa89c01a26e0644b2582c261a575ec7 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1567 (PresentX 1567) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14722 MB ``` ### Limits of coverage - `merged_find_null_data_and_close_are_safe` and all `11/11` `vfs_hooks::` unit tests (`0` skipped) passed `3/3` on Windows 11 NTFS, directly covering the `#1388` `MergedFind` handle-table lifetime fix and null-pointer guards. - The 60 s retail smoke confirms live VFS directory enumeration and runtime stability (`0` device removals, `0` crashes, 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).*
Foniass commented 2026-12-01 06:26:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:26:07Z.


Triage (#1607) – head d3a962f

#1415 fixes the same use-after-free in vfs_hooks.rs. In both PRs, hk_find_next_w/_a now read the MergedFind entry while holding the MERGED lock, and hk_find_close frees it under that same lock. #1415 does it with the boxed handle, this PR with a HashMap that owns the entries and synthetic handles. The observable change is the same.
#1415 was opened first, merges cleanly, and has a test that races FindNext against FindClose on 8 threads. This PR conflicts with main, and its test (merged_find_null_data_and_close_are_safe) never runs FindNext and FindClose at the same time, so it does not exercise the race.
The null data/out checks (error 87) are a separate change. If they are still wanted after #1415, they can go in a PR of their own.
Recommendation: close (duplicate of #1415).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302867664 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1662#issuecomment-7302867664). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:26:07Z. --- **Triage (#1607)** – head d3a962f #1415 fixes the same use-after-free in vfs_hooks.rs. In both PRs, hk_find_next_w/_a now read the MergedFind entry while holding the MERGED lock, and hk_find_close frees it under that same lock. #1415 does it with the boxed handle, this PR with a HashMap that owns the entries and synthetic handles. The observable change is the same. #1415 was opened first, merges cleanly, and has a test that races FindNext against FindClose on 8 threads. This PR conflicts with main, and its test (`merged_find_null_data_and_close_are_safe`) never runs FindNext and FindClose at the same time, so it does not exercise the race. The null `data`/`out` checks (error 87) are a separate change. If they are still wanted after #1415, they can go in a PR of their own. Recommendation: close (duplicate of #1415). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-02 10:18:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-02T10:18:56Z.


Closing as a duplicate of #1415: #1607 group D224, checked by Foniass and Decodere, who both read the diffs and suggest keeping #1415. If something here is not in #1415, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5) ran the closing script.

<!-- greyfinch-sync:ivall/xcl:comment:7342287578 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1662#issuecomment-7342287578). Originally posted by [throny](https://github.com/throny) on 2026-12-02T10:18:56Z. --- Closing as a duplicate of #1415: #1607 group D224, checked by Foniass and Decodere, who both read the diffs and suggest keeping #1415. If something here is not in #1415, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5) ran the closing script.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1652
No description provided.