Skip to content

VFS: validate CreateFile2 parameters before reading flags - #1433

Open
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/createfile2-parameter-size
Open

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/createfile2-parameter-size

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

  • crates/xcl/src/vfs_hooks.rs: size-aware parameter reads and synthetic tests for null, short, unreadable and valid structures.

Tested

  • Windows 11 Pro x64 build 26300, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT 16 GB, driver 32.0.32029.2010; Rust 1.98.1 MSVC, debug.
  • cargo test -p xcl --lib createfile2_flags_require_a_readable_sized_structure: 1 passed, 0 failed.
  • cargo test --workspace -- --test-threads=4 --nocapture: 752 passed, 0 failed, 41 ignored. The reported passes include tests that return early.
  • SKIPPED: test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state (D3D12 debug layer unavailable).

Regression run

main:

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

PR:

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

Not tested

AI use

  • Codex (GPT-6): wrote implementation and unit tests, ran validation, and drafted this description.

Read only fields covered by the caller size and leave invalid parameter handling to the native API.

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…README

Integrates 12 additional open upstream PRs on top of upstream/main
(b7aa9f3):
- xcl-dev#1432: GFX10 to DXGI format mappings, depth SRVs, and byte sizing
- xcl-dev#1447: Arena::take overflow/alignment and Uma::free pool validation
- xcl-dev#1441: drop SC_KEYMENU so the window is never frozen in menu mode
- xcl-dev#1431, xcl-dev#1436: TLS directory sizing/alignment and RegisterClassExA checks
- xcl-dev#1430, xcl-dev#1446: XGameSave quota/URL and XAudio2 XMA channel validation
- xcl-dev#1415, xcl-dev#1433: VFS merged-directory sync and CreateFile2 checks
- xcl-dev#1418: XGameRuntime device association synchronization
- xcl-dev#1410, xcl-dev#1413: wave64 form logging and XCL_SAFE_BARRIER cache bypass

Also removes duplicate a_huge_constant_count_has_no_layout test left
from pre-applying xcl-dev#1290 before upstream merged it, and updates README.md.

Verified under GE-Proton11-14 (RX 9060 XT / RADV):
- Release build (x86_64-pc-windows-msvc): ok (22.05s)
- Proton unit test sweep across all merged/touched modules: 209 passed,
  2 failed (known Wine/vkd3d-proton diffs: xma2_source_voice current_buffer_context
  before Start, and vkd3d-proton accepting UNORDERED_ACCESS without UAV flag),
  1 ignored, 0 skipped.
@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 16:56
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@Belox17

Belox17 commented Nov 24, 2026

Copy link
Copy Markdown

Test report for f1a5aa3d on NVIDIA (RTX 3060 Ti): passes on NVIDIA too, also merged into current main

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head f1a5aa3d as is (base 2008399), clean tree.
  • The new test (createfile2_flags_require_a_readable_sized_structure) with cargo test -p xcl --lib <name>: 1 passed.
  • cargo test --workspace -- --test-threads=4 on the head: 752 passed, 0 failed, 41 ignored; its base 2008399 on the same machine: 751 passed, 0 failed, 41 ignored. SKIPPED on both: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • Merged into current main c160d86e (clean merge): 859 passed, 0 failed, 42 ignored; main alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above.
  • Not run with the fix reverted: the test calls create_file_2_flags, which the fix adds, so it does not build without it.

Not tested

  • AMD / native wave64 hardware; any retail title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 25, 2026
…ading flags

Windows vfs_hooks.rs hunk verbatim (reference-only on Linux):
create_file_2_flags (null->Some(0), dwSize<12->None, unreadable->None
via ReadProcessMemory) + hk_create_file_2 passthrough-on-None + test.
Linux live path is kernelx_linux.rs CreateFile2 (vfs_hooks_linux.rs has
no CreateFile2): pread(/proc/self/mem) twin helper (never a raw guest
deref; same syscall-only discipline as eh copy_stack/code_at), None ->
ERROR_INVALID_PARAMETER + INVALID_HANDLE_VALUE (no orig on Linux;
ExA reject-vs-passthrough precedent), NULL -> flags 0. Failing-first:
new test E0425 x4 pre-impl, green post-impl. Gates: both checks 0 errors,
zero new warnings; lib 609/0/1; title 12 GPU-only; retail SIGSEGV
+0x2237320 frontier HOLDS, M1-RE TERMINAL.
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…upstream xcl-dev#1038)

Reference-only on Linux (vfs_hooks.rs is cfg(windows)): apply_open_decision
takes Option<OpenCommit> and commits via commit_open(rel, is_new) so only a
new overlay entry clears a whiteout; new open_file wrapper stages via
open_decision_staged_for (keeps xcl-dev#1362 fail-before-commit + xcl-dev#1433 CreateFile2
flags validation a verbatim open_decision_for port would regress) and records
the whiteout via commit_overlay_removal on successful DELETE_ON_CLOSE open of
a game-original file. README 2-line hunk verbatim.

Title/e2e delete-on-close hunks NOT ported: title is cfg(windows) using
std::os::windows APIs (link.exe absent per PROMPT.md 0.9); the prebuilt PE is
stale so the e2e whiteout assert would newly FAIL. Linux behavior for the same
shape is pinned by vfs.rs reopening-keeps-whiteout + vfs_hooks_linux +
kernelx_linux delete-on-close tests.
@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

NVIDIA test report for f1a5aa3: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. Head tested as-is on its base 037aecd.

  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4: 699 passed, 0 failed, 21 ignored; 2 SKIPPED (no wave64), not in this PR's files.
  • cargo test -p xcl --lib -- --exact vfs_hooks::tests::createfile2_flags_require_a_readable_sized_structure --test-threads=1 --nocapture, 3 runs: 3/3 passed, 0 SKIPPED.
    Lib tests only; no title run.
    AI-assisted (Claude Code, Claude Opus 5.5).

@coolpersonnn

Copy link
Copy Markdown
Contributor

merge-check claim
head: f1a5aa3

@saintwolf

Copy link
Copy Markdown
Contributor

merge-check claim
head: f1a5aa3

@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@coolpersonnn

Copy link
Copy Markdown
Contributor

merge-check
base: ff0c364
head: f1a5aa3
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2889 passed, 1 failed, 51 ignored (25 SKIPPED: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache); failing: two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (fails on base ff0c364 alone too — pre-existing flake in tests/gpu_two_pass_cache_e2e.rs, unrelated to vfs_hooks.rs); new test vfs_hooks::tests::createfile2_flags_require_a_readable_sized_structure passed
review: none (minor non-blocking note below). Read the full diff (+35/-1 in crates/xcl/src/vfs_hooks.rs). Replaces the raw *((params as *const u8).add(8) as *const u32) read in hk_create_file_2 with create_file_2_flags(params), which checks null -> Some(0), probes dwSize >= 12 and readability of the first 12 bytes via ReadProcessMemory(GetCurrentProcess(), ...), and forwards to orig on None. Unit test covers null, short dwSize (4), unreadable pointer (1), and valid 12-byte struct. Non-blocking note: a single 12-byte ReadProcessMemory followed by the dwSize < 12 check would return None for all the same invalid inputs with one fewer syscall per non-null CreateFile2 call. Clean scope; no duplicates found in open/merged PRs or #1607.
performance: negligible (two ReadProcessMemory calls on the current process per non-null CreateFile2 file-open call; not on any per-draw/frame hot path)
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.2101), AMD Ryzen 9 9950X3D, Windows 11 Pro build 26300, Rust 1.100.0 / T3 Code (Antigravity), Gemini 4 Neon (Medium)

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@saintwolf

Copy link
Copy Markdown
Contributor

merge-check
base: ff0c364
head: f1a5aa3
merge: clean (trial merge 4147d8ef4a6939b55a16eeef0bc84c915c4a8dde; git diff --check clean; +35/-1 in crates/xcl/src/vfs_hooks.rs)
build: cargo build --workspace -> ok (39 lib + 19 test warnings, all pre-existing; none from the changed lines)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 0 failed, 51 ignored (base ff0c364's 2889 + 1 new test). SKIPPED: 27, the standard set for this card. The new createfile2_flags_require_a_readable_sized_structure passes in the targeted vfs run (25/0) and inside the full suite.
review: read the whole diff (+35/-1, one file) and the surrounding hook. The old line dereferenced the guest-supplied pointer raw: if params was non-null it did *((params + 8) as *const u32), so a params value pointing at an unreadable/uncommitted region would fault the hooked process, and a struct the caller declared smaller than 12 bytes had its dwFileFlags field read past what the caller promised to provide. The new create_file_2_flags helper: (1) null params -> Some(0), identical to the old behavior; (2) reads the 4-byte dwSize first via ReadProcessMemory on the current process — a fault-tolerant read that fails instead of raising on an invalid range, holding no state; (3) dwSize < 12 -> None, because CREATEFILE2_EXTENDED_PARAMETERS is three DWORDs (dwSize@0, dwFileAttributes@4, dwFileFlags@8) followed by 8-aligned pointers, so a structure declared under 12 bytes does not cover the flags field at offset 8; (4) reads the full 12 bytes and returns dwFileFlags at offset 8; any failure -> None. On None the hook returns orig(n, acc, sh, disp, params) — delegation to the original CreateFile2, the same pattern as the function's existing from_wide_ptr early return, with the Guard dropped by RAII as on that path; for a well-formed struct the bytes read and the value are exactly what the old dereference produced, so correct callers are unchanged. Race safety: the hook runs on the guest's own thread and params is a same-process pointer; if a racing guest thread unmapped the region between the two reads, the second ReadProcessMemory fails and the hook delegates to orig — nothing from params is retained, so no use-after-free in XCL state (the code comment says exactly this). The test covers all four helper paths: null -> Some(0), a 4-byte struct (dwSize = 4 < 12) -> None, address 0x1 (uncommitted on x64 — the first 64 KB of the user address space is loader-reserved, a stable Windows invariant, empirically confirmed on the three machines in the thread) -> None, and a valid [12, 0x1234, 0x5678] -> Some(0x5678). Thread: DavidM1911 (RTX 3060 Ti) lib all-pass with the branch merged into current main, noting the pre-existing 0xc0000005 abort flake on unmodified main; Belox17 (RTX 3060 Ti) new test 1/1, workspace 752/0/41 on the head vs 751/0/41 on its base on the same machine, and 859/0/42 merged onto main c160d86 vs 858/0/42 for main alone — a delta of exactly the one new test; upipibi (RTX 3070) lib 699/0/21 and the new test 3/3 standalone. Dupe note: #1607 group B5 lists eight open PRs for this same hardening — #1433 (this one, earliest, 15:54Z, +35/-1) and seven later ones by another author (#1449, #1453, #1465, #1470, #1477, #1480, #1486, 16:14-16:50Z); #1433 is the only B5 member in the #3041 queue, and the others close out when one of the group lands. No other open PR touches this hunk (open VFS PRs #3048, #1362, #1092 are distinct changes). One file, no new dependencies (the windows-sys features Win32_System_Diagnostics_Debug and Win32_System_Threading are already enabled in Cargo.toml), no stop-criteria files.
performance: none meaningful; the hooked CreateFile2 path with non-null params does one or two ReadProcessMemory calls on the current process (no cross-process copy) where the old code did one raw 4-byte read, on a path that already converts the path and logs the open.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head f1a5aa3

No open or merged PR makes the same change; main still reads dwFileFlags at params+8 without looking at dwSize. No problems found in the diff: a too-small or unreadable CREATEFILE2_EXTENDED_PARAMETERS now goes to the original CreateFile2, which reports the error itself.
Recommendation: keep open.

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

@throny throny added needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) and removed ready-to-merge Has 2 independent safe merge-checks on current head (#3041) labels Dec 2, 2026
@tiagonleal

Copy link
Copy Markdown
Contributor

merge-check
base: 5ad98ad
head: f1a5aa3
merge: clean (merge commit 918b9648952f467cd7f0d91ce541ae29617ad509; git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3006 passed, 0 failed, 52 ignored; SKIPPED: 24 (22 no wave64, 2 no heap windows); failing: none
title run: Newer Retail Game, release build of this merge, Series S settings (XCL_DEVICE_TYPE=lockhart, XCL_COHERENT_MB=512, XCL_UMA_WINDOWS=16, XCL_SPARSE_LAZY=1), scripted A presses, 240 s planned: into the world at 80 s, 42 s there with 83 frames presented, no crash, no device removal; then our RAM guard stopped it (free RAM under 1 GB on this 32 GB PC, as in main's second run).
review: none.
performance: two small reads of the params per CreateFile2 call. World frame rate not compared: on this 32 GB PC the runs of main and of the PRs end 30 to 150 s into the world (RAM guard or time limit).
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (driver 617.42), Ryzen 7 9800X3D, 32 GB, Windows 11 Pro 26300 / Claude Code with Claude Opus 5.5

Same settings on main 5ad98ad, two runs: into the world at 94 s with 145 s there and no frame presented (ran to the 240 s limit); into the world at 80 s with 59 s there and 90 frames, then stopped by our RAM guard (free RAM under 1 GB). "In the world" here means the first 2 s window of the activity log with 5,000+ draws and dispatches.

AI use: Claude Code (Claude Opus 5.5) ran the build, tests and title runs and wrote this; a Claude Sonnet subagent read the diff and I checked its points.
~Tiago

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants