WIP: fix(sandbox): Windows: a confined game writes the diagnostic folders the real environment names, as on Linux, and no wider #2847

Draft
llun wants to merge 2 commits from llun/Longshot:fix/mod-api-win-sandbox-diagnostics into mod-api
Member

Summary

For #2822 (into mod-api). On Windows a confined game cannot write the folders its diagnostic switches name: RX_VK_SHOTS (the renderer's shots, headless ones too), HOS_PROFILE_DIR, HOS_SHADER_DUMP, RX_VK_DUMP, RX_VK_HANG_DUMP. Unless such a folder is inside one the game already writes (diagnostics\logs\), the shots and dumps go nowhere: the folder is not even made. Linux's plan writes them (sandbox_linux.rs diagnostic_dirs, docs/dev/reference/sandbox.md's Linux table). env_own.rs says the Windows plan grants what such a switch names, but the Windows plan had no grant for them.

The builder's Windows plan now takes these five switches from the real environment and the command alone (Env::real in gather.rs), never from a file of switches: longshot_env.txt takes no path, and HOS_ENV_FILE's file may be one a confined run can write. Each folder is served as a written root, made first. It goes through Grants::add's checks (no drive's root, no short name, nothing at or above the player's own folders or the grants' record's folder) and two checks of its own (Grants::add_diagnostic in plan.rs):

  • nothing at or above a folder or file the plan gives: the game folder written would let the game rewrite its own exe, image or switches; the same for the user folder, the save folder, the player's .nup;
  • nothing inside one the game only reads: the game folder, its bin\, mods\ and romfs\, DLSS's runtime (DLLs the renderer loads), a file read whole.

Inside a folder the game already writes, it is that folder's: nothing new. A refused folder is said in the log (sandbox: not granted: ... (a diagnostic switch's folder at or above one of the game's or the player's)). docs/dev/reference/sandbox.md's Windows table gets the row.

Not in this PR: Linux also writes the folders of seven diagnostic files (RX_VK_FRAME_LOG, HOS_CHAIN...). On Windows those would need a folder granted for one file, a wider grant, so they are left out here.

To see it on mod-api: start the game confined (longshot-builder game) with RX_VK_SHOTS set to a folder outside the game folder's own: no shot is written.

Read first: Grants::add_diagnostic in builder/crates/build-core/src/sandbox_windows/plan.rs.

Testing

Tested: Windows 11, RTX 5080, NVIDIA 621.40, the game confined, headless, RX_VK_SHOTS set to build-windows\shots-diag-*, a folder beside the game folder (not in it, not above it), a shot every 10 frames, 20 s. The game and its runtime were the same for both runs; only the builder differs.

  • Before (the builder from mod-api): no grant for the folder, the folder not made, no shot written.
  • After (the builder with this PR): sandbox: allowed write ...\build-windows\shots-diag-after (a diagnostic switch's folder (the real environment's)), served by the builder, then 135 vk: present N written to ...\shots-diag-after\vk_...png.

Both runs are on mod-api with #2726's save-folder fix and its broker change applied locally, beneath this PR: on plain mod-api a confined Windows start with a profile stops at the save folder. The shots were deleted after.

Checks, on Windows (cargo test -p build-core --lib --target x86_64-pc-windows-gnullvm with llvm-mingw):

  • sandbox_windows::gather::tests::a_diagnostic_folder_the_environment_names_is_written_and_no_wider_one, through plan_for with a real command: each of the five set to a folder of its own is a written root; %USERPROFILE% and C:\ are neither a root nor an ACL; a folder named only by HOS_ENV_FILE's file is not granted. It fails on mod-api (no root for RX_VK_SHOTS) and passes here.
  • sandbox_windows::plan::tests::a_diagnostic_folder_is_written_alone_and_never_over_or_in_what_the_game_only_reads, on the launcher's layout the plan's tests use: C:\Dev\shots written, served, made first; the plan unchanged, and the refusal said, for the game folder, a folder above it, bin\shots, mods\shots, romfs\, the user folder, the .nup's folder, DLSS's runtime, %LOCALAPPDATA%\Longshot (the record's), %USERPROFILE% and C:\; and nothing new for logs\shots, inside a written folder.
  • Each refusal is load-bearing. Without the "at or above" check, or without the "inside one read" check, the plan test fails. With the folders taken from the file-overlaid environment instead of the real one, the gather test fails. Each change was undone after.
  • build-core's library: 98 pass here, 96 on mod-api. The two that fail here fail the same way on mod-api: driver_caches::…the_caches_are_longshots_own_unless_one_is_named (#2834 fixes it) and files_windows::…the_cache_takes_files_folders_renames_and_removes.
  • tests/test_sandbox_windows.py passes: it reads gather.rs and checks it starts nothing (no Command::new), so the gather test, which builds a command but never starts it, is in gather/tests.rs.
  • cargo fmt --check passes. cargo clippy -p build-core --all-targets --no-deps -- -D warnings (Windows target) passes with #2830 beneath (alone, mod-api's own channel.rs and control.rs lints stop it first). mise run lint passes.

Still to test:

  • Windows, with a window: RX_VK_SHOTS and F12's shots, and a HOS_PROFILE_DIR profiler run, into a folder of their own (by hand)
  • Linux: cargo test -p build-core (CI; the new tests are Windows', the Linux plan is untouched)

Measurements

Verdict: fixed. A confined game on Windows writes its diagnostic switches' folders, and none wider.

Baseline: mod-api (#2822's head), the branch this PR goes into. Nothing to time: the plan gains up to five roots.

Before: mod-api @ c5e5b676 After: this PR @ 1b3a92b2
Shots written to RX_VK_SHOTS beside the game folder, 20 s, one per 10 frames 0 135
a_diagnostic_folder_the_environment_names_is_written_and_no_wider_one FAIL (no root) pass
a_diagnostic_folder_is_written_alone_and_never_over_or_in_what_the_game_only_reads (new) pass

Risks

The sandbox: this PR widens what a confined game may write on Windows, but only to the folders a developer's real environment names for these five switches. It keeps every refusal Grants::add has, and adds two: nothing at or above anything the plan gives, and nothing inside what the game only reads. A player's longshot_env.txt cannot name them (it takes no path), and neither can HOS_ENV_FILE's file. Each folder is a root of the builder's file service, opened through its no-link walk like every other root; no ACL changes. Each refusal is pinned by a test that fails without it (above).

Beside #2747, whose latest comment adds the test mode's folder (--mod-tests, HOS_MOD_TESTS) to the same Windows plan from the command and environment: the two add separate roots, and whichever lands second may need a rebase in gather.rs.

What a developer's environment points the switches at, the game can write: a folder of the developer's choosing, as on Linux. Up to five roots more. A revert is enough.

Checklist

Ready for review

  • One topic, on current mod-api (#2822's head); the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (The checks this change reaches pass, as above. mod-api's whole suite has failures on Windows that this PR doesn't change: #2825 and #2826 fix eight of them.)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here. (It fails on mod-api, where the bug is.)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary For [#2822](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2822) (into `mod-api`). On Windows a confined game cannot write the folders its diagnostic switches name: `RX_VK_SHOTS` (the renderer's shots, headless ones too), `HOS_PROFILE_DIR`, `HOS_SHADER_DUMP`, `RX_VK_DUMP`, `RX_VK_HANG_DUMP`. Unless such a folder is inside one the game already writes (`diagnostics\logs\`), the shots and dumps go nowhere: the folder is not even made. Linux's plan writes them (`sandbox_linux.rs` `diagnostic_dirs`, docs/dev/reference/sandbox.md's Linux table). `env_own.rs` says the Windows plan grants what such a switch names, but the Windows plan had no grant for them. The builder's Windows plan now takes these five switches **from the real environment and the command alone** (`Env::real` in `gather.rs`), never from a file of switches: `longshot_env.txt` takes no path, and `HOS_ENV_FILE`'s file may be one a confined run can write. Each folder is served as a written root, made first. It goes through `Grants::add`'s checks (no drive's root, no short name, nothing at or above the player's own folders or the grants' record's folder) and two checks of its own (`Grants::add_diagnostic` in `plan.rs`): - **nothing at or above a folder or file the plan gives**: the game folder written would let the game rewrite its own exe, image or switches; the same for the user folder, the save folder, the player's `.nup`; - **nothing inside one the game only reads**: the game folder, its `bin\`, `mods\` and `romfs\`, DLSS's runtime (DLLs the renderer loads), a file read whole. Inside a folder the game already writes, it is that folder's: nothing new. A refused folder is said in the log (`sandbox: not granted: ... (a diagnostic switch's folder at or above one of the game's or the player's)`). docs/dev/reference/sandbox.md's Windows table gets the row. Not in this PR: Linux also writes the folders of seven diagnostic *files* (`RX_VK_FRAME_LOG`, `HOS_CHAIN`...). On Windows those would need a folder granted for one file, a wider grant, so they are left out here. **To see it on `mod-api`:** start the game confined (`longshot-builder game`) with `RX_VK_SHOTS` set to a folder outside the game folder's own: no shot is written. Read first: `Grants::add_diagnostic` in `builder/crates/build-core/src/sandbox_windows/plan.rs`. ## Testing **Tested:** Windows 11, RTX 5080, NVIDIA 621.40, the game confined, headless, `RX_VK_SHOTS` set to `build-windows\shots-diag-*`, a folder beside the game folder (not in it, not above it), a shot every 10 frames, 20 s. The game and its runtime were the same for both runs; only the builder differs. - Before (the builder from `mod-api`): no grant for the folder, the folder not made, no shot written. - After (the builder with this PR): `sandbox: allowed write ...\build-windows\shots-diag-after (a diagnostic switch's folder (the real environment's)), served by the builder`, then 135 `vk: present N written to ...\shots-diag-after\vk_...png`. Both runs are on `mod-api` with [#2726](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2726)'s save-folder fix and its broker change applied locally, beneath this PR: on plain `mod-api` a confined Windows start with a profile stops at the save folder. The shots were deleted after. Checks, on Windows (`cargo test -p build-core --lib --target x86_64-pc-windows-gnullvm` with llvm-mingw): - `sandbox_windows::gather::tests::a_diagnostic_folder_the_environment_names_is_written_and_no_wider_one`, through `plan_for` with a real command: each of the five set to a folder of its own is a written root; `%USERPROFILE%` and `C:\` are neither a root nor an ACL; a folder named only by `HOS_ENV_FILE`'s file is not granted. It fails on `mod-api` (no root for `RX_VK_SHOTS`) and passes here. - `sandbox_windows::plan::tests::a_diagnostic_folder_is_written_alone_and_never_over_or_in_what_the_game_only_reads`, on the launcher's layout the plan's tests use: `C:\Dev\shots` written, served, made first; the plan unchanged, and the refusal said, for the game folder, a folder above it, `bin\shots`, `mods\shots`, `romfs\`, the user folder, the `.nup`'s folder, DLSS's runtime, `%LOCALAPPDATA%\Longshot` (the record's), `%USERPROFILE%` and `C:\`; and nothing new for `logs\shots`, inside a written folder. - Each refusal is load-bearing. Without the "at or above" check, or without the "inside one read" check, the plan test fails. With the folders taken from the file-overlaid environment instead of the real one, the gather test fails. Each change was undone after. - `build-core`'s library: 98 pass here, 96 on `mod-api`. The two that fail here fail the same way on `mod-api`: `driver_caches::…the_caches_are_longshots_own_unless_one_is_named` ([#2834](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2834) fixes it) and `files_windows::…the_cache_takes_files_folders_renames_and_removes`. - `tests/test_sandbox_windows.py` passes: it reads `gather.rs` and checks it starts nothing (no `Command::new`), so the gather test, which builds a command but never starts it, is in `gather/tests.rs`. - `cargo fmt --check` passes. `cargo clippy -p build-core --all-targets --no-deps -- -D warnings` (Windows target) passes with [#2830](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2830) beneath (alone, `mod-api`'s own `channel.rs` and `control.rs` lints stop it first). `mise run lint` passes. **Still to test:** - Windows, with a window: `RX_VK_SHOTS` and F12's shots, and a `HOS_PROFILE_DIR` profiler run, into a folder of their own (by hand) - Linux: `cargo test -p build-core` (CI; the new tests are Windows', the Linux plan is untouched) ## Measurements **Verdict:** fixed. A confined game on Windows writes its diagnostic switches' folders, and none wider. Baseline: `mod-api` (#2822's head), the branch this PR goes into. Nothing to time: the plan gains up to five roots. | | Before: mod-api @ c5e5b676 | After: this PR @ 1b3a92b2 | |---|---|---| | Shots written to `RX_VK_SHOTS` beside the game folder, 20 s, one per 10 frames | 0 | 135 | | `a_diagnostic_folder_the_environment_names_is_written_and_no_wider_one` | FAIL (no root) | pass | | `a_diagnostic_folder_is_written_alone_and_never_over_or_in_what_the_game_only_reads` | (new) | pass | ## Risks **The sandbox:** this PR widens what a confined game may write on Windows, but only to the folders a developer's real environment names for these five switches. It keeps every refusal `Grants::add` has, and adds two: nothing at or above anything the plan gives, and nothing inside what the game only reads. A player's `longshot_env.txt` cannot name them (it takes no path), and neither can `HOS_ENV_FILE`'s file. Each folder is a root of the builder's file service, opened through its no-link walk like every other root; no ACL changes. Each refusal is pinned by a test that fails without it (above). Beside [#2747](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2747), whose latest comment adds the test mode's folder (`--mod-tests`, `HOS_MOD_TESTS`) to the same Windows plan from the command and environment: the two add separate roots, and whichever lands second may need a rebase in `gather.rs`. What a developer's environment points the switches at, the game can write: a folder of the developer's choosing, as on Linux. Up to five roots more. A revert is enough. ## Checklist ### Ready for review - [x] One topic, on current `mod-api` (#2822's head); the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (The checks this change reaches pass, as above. `mod-api`'s whole suite has failures on Windows that this PR doesn't change: [#2825](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2825) and [#2826](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2826) fix eight of them.) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. (It fails on `mod-api`, where the bug is.) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
On Linux the builder's plan writes the folders of the diagnostic switches the real environment sets (RX_VK_SHOTS,
HOS_PROFILE_DIR, HOS_SHADER_DUMP, RX_VK_DUMP, RX_VK_HANG_DUMP: sandbox_linux.rs diagnostic_dirs), never the home,
the root or a system folder. On Windows the plan gives none, so a confined game's headless shots, profiler runs and
dumps fail to open ("PNG open failed (error 13)"). Through plan_for with a real command: each of the five set to a
folder of its own is a written root; the player's own folder and a drive's root are neither a root nor an ACL; and a
file of switches (HOS_ENV_FILE's, which a confined run may be able to write) names none. The first part fails on
mod-api: no root for RX_VK_SHOTS.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(sandbox): Windows: a confined game writes the diagnostic folders the real environment names, as on Linux, and no wider
All checks were successful
PR description / Title and description (pull_request_target) Successful in 8s
1b3a92b238
A confined game's RX_VK_SHOTS, HOS_PROFILE_DIR, HOS_SHADER_DUMP, RX_VK_DUMP and RX_VK_HANG_DUMP folders had no grant on
Windows, so its headless shots, profiler runs and dumps failed to open (Linux's plan writes them: sandbox_linux.rs
diagnostic_dirs). The builder's Windows plan takes them from the real environment and the command alone, never a file
of switches (Env::real), and serves each as a written root, made first, through Grants::add's checks (no drive's root,
no short name, nothing at or above the player's own folders or the record's) and two of its own (add_diagnostic):
nothing at or above a folder or file the plan gives (the game folder written would let the game rewrite its exe, image
or switches), nothing inside one the game only reads (its bin\, mods\, romfs\, DLSS's runtime, a file read whole).
Inside a written folder it is that one's. docs/dev/reference/sandbox.md's Windows table says so.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in the game: Windows 11, RTX 5080, NVIDIA 621.40, confined through longshot-builder game, headless, RX_VK_SHOTS set to a folder beside the game folder (not in it, not above it), a shot every 10 frames, 20 s. The game and runtime were the same for both runs; only the builder differs. Both are on mod-api with #2726's save-folder fix and its broker change applied locally, beneath this PR.

  • Before, the builder from mod-api: no grant, the folder not made, no shot.
  • After, the builder with this PR: sandbox: allowed write ...\build-windows\shots-diag-after (a diagnostic switch's folder (the real environment's)), served by the builder, then 135 vk: present N written to ...\shots-diag-after\vk_...png.

The shots were deleted after.

Tested in the game: Windows 11, RTX 5080, NVIDIA 621.40, confined through `longshot-builder game`, headless, `RX_VK_SHOTS` set to a folder beside the game folder (not in it, not above it), a shot every 10 frames, 20 s. The game and runtime were the same for both runs; only the builder differs. Both are on `mod-api` with #2726's save-folder fix and its broker change applied locally, beneath this PR. - Before, the builder from `mod-api`: no grant, the folder not made, no shot. - After, the builder with this PR: `sandbox: allowed write ...\build-windows\shots-diag-after (a diagnostic switch's folder (the real environment's)), served by the builder`, then 135 `vk: present N written to ...\shots-diag-after\vk_...png`. The shots were deleted after.
Author
Member

On hold. The direction for the confined game is that it writes nothing itself and everything goes through the broker, and the game's writes are getting an audit. This PR gives the game five more written roots (served by the builder, but still the game's writes), so it waits on that audit rather than going in as it is. If the diagnostics should come out through the broker instead (the game hands the shot or dump over, the builder writes it), this PR's refusals and tests are a starting point for which folders the builder may write to.

On hold. The direction for the confined game is that it writes nothing itself and everything goes through the broker, and the game's writes are getting an audit. This PR gives the game five more written roots (served by the builder, but still the game's writes), so it waits on that audit rather than going in as it is. If the diagnostics should come out through the broker instead (the game hands the shot or dump over, the builder writes it), this PR's refusals and tests are a starting point for which folders the builder may write to.
All checks were successful
PR description / Title and description (pull_request_target) Successful in 8s
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/mod-api-win-sandbox-diagnostics:llun-fix/mod-api-win-sandbox-diagnostics'
git switch 'llun-fix/mod-api-win-sandbox-diagnostics'

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.

git switch 'mod-api'
git merge --no-ff 'llun-fix/mod-api-win-sandbox-diagnostics'
git switch 'llun-fix/mod-api-win-sandbox-diagnostics'
git rebase 'mod-api'
git switch 'mod-api'
git merge --ff-only 'llun-fix/mod-api-win-sandbox-diagnostics'
git switch 'llun-fix/mod-api-win-sandbox-diagnostics'
git rebase 'mod-api'
git switch 'mod-api'
git merge --no-ff 'llun-fix/mod-api-win-sandbox-diagnostics'
git switch 'mod-api'
git merge --squash 'llun-fix/mod-api-win-sandbox-diagnostics'
git switch 'mod-api'
git merge --ff-only 'llun-fix/mod-api-win-sandbox-diagnostics'
git switch 'mod-api'
git merge 'llun-fix/mod-api-win-sandbox-diagnostics'
git push origin 'mod-api'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2847
No description provided.