VFS: a MAXIMUM_ALLOWED open of a game file is treated as a read and bypasses the overlay #2672

Closed
opened 2026-11-26 06:00:52 +00:00 by Kelvin19-San · 0 comments
Kelvin19-San commented 2026-11-26 06:00:52 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by Kelvin19-San on 2026-11-26T06:00:52Z.


Title: VFS: a MAXIMUM_ALLOWED open of a game file is treated as a read and bypasses the overlay

Static read of crates/xcl/src/vfs.rs and vfs_hooks.rs as of 2026-11-26 (commit hash not recorded; I read a copy of the files, not the current main). Not built, not run, not reproduced.

What I see

  1. WRITE_ACCESS in vfs.rs lists GENERIC_WRITE, GENERIC_ALL, FILE_WRITE_DATA, FILE_APPEND_DATA, FILE_WRITE_EA, FILE_WRITE_ATTRIBUTES, DELETE, WRITE_DAC and WRITE_OWNER. MAXIMUM_ALLOWED (0x0200_0000) is not in the mask, and Vfs::is_write only tests access & WRITE_ACCESS.
  2. hk_create_file_w (vfs_hooks.rs) passes the caller's acc unchanged to the real CreateFileW, with the path chosen by open_decision. hk_create_file_a and hk_create_file_2 do the same.
  3. So CreateFileW(L"GAME:\\data\\x", MAXIMUM_ALLOWED, ..., OPEN_EXISTING) takes the read branch of open_decision_for, gets Decision::Use(<original path>), and the real open runs on the original with every right the ACL allows. A WriteFile through that handle would change the game folder, which the README says is never modified.

Likelihood: rare. I know of no title that opens files this way.

Suggested fix (not compiled)

 const WRITE_ACCESS: u32 = GENERIC_WRITE
     | 0x1000_0000 // GENERIC_ALL
+    | 0x0200_0000 // MAXIMUM_ALLOWED: every right the ACL grants, writing included
     | 0x0000_0002 // FILE_WRITE_DATA / ADD_FILE

Trade-off: a title that opens a large game file with MAXIMUM_ALLOWED only to read it would now get a copy in the overlay, like any other write-open. If that is not wanted, the alternative is to keep it a read and open the original with the access reduced to read rights, which means rewriting the mask before the real call. I did not look at that.

Suggested test (not run)

Next to reads_never_touch_and_writes_copy_on_write in vfs.rs:

#[test]
fn maximum_allowed_is_a_write_open() {
    let f = Fixture::new("maxallowed");
    let v = &f.vfs;
    const MAXIMUM_ALLOWED: u32 = 0x0200_0000;
    let Decision::Use(p) = v.open_decision("G:\\data\\hello.txt", MAXIMUM_ALLOWED, OPEN_EXISTING, 0) else { panic!() };
    assert!(p.contains("overlay"), "opened the original: {p}");
    assert_eq!(std::fs::read(f.game().join("data").join("hello.txt")).unwrap(), b"original");
}

Without the fix p is the original path and the first assert fails. With it the open goes to the overlay copy.

The plain-read fast path in #1092 is gated by is_write, so adding the bit to WRITE_ACCESS covers that path too.

Searched first

Open and closed issues and PRs in xcl-dev/xcl for "MAXIMUM_ALLOWED" and "write access": nothing found.

AI use

Found and drafted by Claude (Claude Sonnet 5.5) from a static read of the files. The person posting has not checked the lines against the current main and has not built or run anything. Please treat it as an unconfirmed report.

<!-- greyfinch-sync:ivall/xcl:issue:6620575316 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2682). Originally posted by [Kelvin19-San](https://github.com/Kelvin19-San) on 2026-11-26T06:00:52Z. --- **Title:** VFS: a MAXIMUM_ALLOWED open of a game file is treated as a read and bypasses the overlay Static read of `crates/xcl/src/vfs.rs` and `vfs_hooks.rs` as of 2026-11-26 (commit hash not recorded; I read a copy of the files, not the current main). Not built, not run, not reproduced. ## What I see 1. `WRITE_ACCESS` in vfs.rs lists GENERIC_WRITE, GENERIC_ALL, FILE_WRITE_DATA, FILE_APPEND_DATA, FILE_WRITE_EA, FILE_WRITE_ATTRIBUTES, DELETE, WRITE_DAC and WRITE_OWNER. `MAXIMUM_ALLOWED` (0x0200_0000) is not in the mask, and `Vfs::is_write` only tests `access & WRITE_ACCESS`. 2. `hk_create_file_w` (vfs_hooks.rs) passes the caller's `acc` unchanged to the real `CreateFileW`, with the path chosen by `open_decision`. `hk_create_file_a` and `hk_create_file_2` do the same. 3. So `CreateFileW(L"GAME:\\data\\x", MAXIMUM_ALLOWED, ..., OPEN_EXISTING)` takes the read branch of `open_decision_for`, gets `Decision::Use(<original path>)`, and the real open runs on the original with every right the ACL allows. A `WriteFile` through that handle would change the game folder, which the README says is never modified. **Likelihood:** rare. I know of no title that opens files this way. ## Suggested fix (not compiled) ```diff const WRITE_ACCESS: u32 = GENERIC_WRITE | 0x1000_0000 // GENERIC_ALL + | 0x0200_0000 // MAXIMUM_ALLOWED: every right the ACL grants, writing included | 0x0000_0002 // FILE_WRITE_DATA / ADD_FILE ``` Trade-off: a title that opens a large game file with `MAXIMUM_ALLOWED` only to read it would now get a copy in the overlay, like any other write-open. If that is not wanted, the alternative is to keep it a read and open the original with the access reduced to read rights, which means rewriting the mask before the real call. I did not look at that. ## Suggested test (not run) Next to `reads_never_touch_and_writes_copy_on_write` in vfs.rs: ```rust #[test] fn maximum_allowed_is_a_write_open() { let f = Fixture::new("maxallowed"); let v = &f.vfs; const MAXIMUM_ALLOWED: u32 = 0x0200_0000; let Decision::Use(p) = v.open_decision("G:\\data\\hello.txt", MAXIMUM_ALLOWED, OPEN_EXISTING, 0) else { panic!() }; assert!(p.contains("overlay"), "opened the original: {p}"); assert_eq!(std::fs::read(f.game().join("data").join("hello.txt")).unwrap(), b"original"); } ``` Without the fix `p` is the original path and the first assert fails. With it the open goes to the overlay copy. ## Related The plain-read fast path in #1092 is gated by `is_write`, so adding the bit to `WRITE_ACCESS` covers that path too. ## Searched first Open and closed issues and PRs in xcl-dev/xcl for "MAXIMUM_ALLOWED" and "write access": nothing found. ## AI use Found and drafted by Claude (Claude Sonnet 5.5) from a static read of the files. The person posting has not checked the lines against the current main and has not built or run anything. Please treat it as an unconfirmed report.
Sign in to join this conversation.
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#2672
No description provided.