VFS: validate CreateFile2 parameters before reading flags #1423
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1433"
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 hajduzsolt on 2026-11-24T15:54:24Z.
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
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.test_title_draws_with_a_root_signature_under_the_debug_layeranduploads_start_from_each_subresources_state(D3D12 debug layer unavailable).Regression run
main:
PR:
Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:52:24Z.
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 unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by Belox17 on 2026-11-24T20:03:08Z.
Test report for
f1a5aa3don NVIDIA (RTX 3060 Ti): passes on NVIDIA too, also merged into current mainTested
f1a5aa3das is (base2008399), clean tree.createfile2_flags_require_a_readable_sized_structure) withcargo test -p xcl --lib <name>: 1 passed.cargo test --workspace -- --test-threads=4on the head: 752 passed, 0 failed, 41 ignored; its base2008399on 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).mainc160d86e(clean merge): 859 passed, 0 failed, 42 ignored;mainalone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above.create_file_2_flags, which the fix adds, so it does not build without it.Not tested
AI use: Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.
upstream-sync referenced this pull request2026-11-25 19:07:20 +00:00
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T16:07:44Z.
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 base037aecd.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).
Imported from ivall/xcl. Originally posted by coolpersonnn on 2026-11-30T19:18:57Z.
merge-check claim
head:
f1a5aa3dcaImported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T19:19:10Z.
merge-check claim
head:
f1a5aa3dcaImported from ivall/xcl. Originally posted by coolpersonnn on 2026-11-30T19:25:28Z.
merge-check
base:
ff0c364b3dhead:
f1a5aa3dcamerge: 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
ff0c364balone 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 passedreview: 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 withcreate_file_2_flags(params), which checks null -> Some(0), probesdwSize >= 12and readability of the first 12 bytes viaReadProcessMemory(GetCurrentProcess(), ...), and forwards toorigon 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 thedwSize < 12check 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)
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T19:25:50Z.
merge-check
base:
ff0c364b3dhead:
f1a5aa3dcamerge: 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 ff0c364b'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
c160d86evs 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
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:44:15Z.
Triage (#1607) – head
f1a5aa3No 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.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T21:42:39Z.
merge-check
base:
5ad98adbc3head:
f1a5aa3dcamerge: clean (merge commit 918b9648952f467cd7f0d91ce541ae29617ad509;
git diff --checkclean)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
5ad98adb, 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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.