Skip to content

Launcher: the elevated step verifies its job files - #86

Draft
phantoslayer21 wants to merge 6 commits into
mainfrom
launcher-elevated-job-check
Draft

phantoslayer21 wants to merge 6 commits into
mainfrom
launcher-elevated-job-check

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Draft: this waits on a new independent review and on a recorded real elevated (UAC) run.

The launcher's elevated step (used when a game folder is not writable by the player) checks its whole request before it runs anything, reports back over a reply pipe instead of files, and now acts on every file and folder through held handles.

  • The launcher writes a job file per game and a batch file listing each with its SHA-256, makes a reply pipe that only this account and administrators can open, and starts apply --batch=<file> --sha256=<hex> --pipe=<name>. A single game is a batch of one.
  • The worker reads every file once, checks each SHA-256, checks every job (all paths absolute, the OptiScaler package, the job's folders) and only then runs the jobs. One job that fails a check: no job runs.
  • The OptiScaler package of an install, update or repair: the job carries its digest; the worker copies the package into a new folder that only administrators can write, checks the copy and installs from it.
  • The worker writes no log or result file of its own: its log lines and results come back over the pipe, the launcher takes them only from the worker it started and only in that run.

File operations through held handles (new in this revision, src/wg_core/secure_fs.h)

  • Each job's folders (the game's folder, the player's local app data and Documents folders, the worker's private folder) are opened before any job runs, from the volume root one component at a time with the NT form of FILE_FLAG_OPEN_REPARSE_POINT (and the folder form of FILE_FLAG_BACKUP_SEMANTICS). Every component stays open without delete sharing until the job ends, so none of them can be renamed, replaced or deleted meanwhile.
  • A reparse point that leads elsewhere (junction, symbolic link, any name-surrogate tag) on any component, the leaf included, is refused with the path named. Reparse points that only store a file differently (Windows' file compression, OneDrive's files on demand, deduplication) are opened as the file itself and checked to be the same file by its id.
  • After each open, GetFinalPathNameByHandle must give the path the job named (normalised); otherwise the operation is refused, with both paths.
  • Every path below a root is opened relative to the held handle (NtCreateFile with a root directory). Files are created under a new name next to their target and renamed over it through the handle (NtSetInformationFile rename with a root directory: SetFileInformationByHandle(FileRenameInfo) refuses a root directory handle); deletes go through the file's handle (SetFileInformationByHandle, POSIX delete where the volume has it); folders are listed through their handle. Nothing outside the job's folders is written; reads outside them are opened the same way from the volume root.
  • The launcher binds each job path to the path Windows reports for it before the prompt, so a game reached through a link the player made is bound to the real folder; a link put in afterwards is refused.
  • The converter library opens files by name: in the worker it reads a copy made through the handles in the private folder and writes into the private folder; its output is then copied into place through the handles.
  • The worker's HIP runtime search no longer looks in PATH or HIP_PATH folders (folders the player may write); only System32 and Program Files.

What stays path-based, and why

  • The volume root itself is opened by its drive name (\??\C:\): the drive letter is resolved by Windows in the worker's own session. The final-path check still compares the whole path.
  • Child processes act by path: Windows' tar.exe unpacks an OptiScaler archive inside the worker's private folder (administrators only; what it unpacks is then read through the handles, links refused), and the HIP probe child loads its DLL by path from System32 or Program Files only.
  • The converter library opens its private copies and its output folder by name, inside the private folder only.
  • The ignore lists' matching looks up a candidate's identity following links on purpose (name and file id only, no data, nothing changed).
  • Under Wine only, the GPU check reads Linux's device list by path (read only).
  • The launcher's own side (not elevated) stays path-based.

Status against the independent review of the earlier head ("addressed" is this PR's claim, not yet re-reviewed)

# Finding Status
1 The package the player approved was bound by name, not by content Addressed: the job carries the package digest; the worker installs from its own checked copy, and reads the package through the handles.
2 Directories held by the worker did not anchor the later path-based operations Addressed in this revision: every folder a job acts on (game folder and its subfolders, backup and state folders, temporary files, the Documents and local app data parts) is opened component by component without following links, checked against its final path and held; every operation is relative to or through those handles. The exceptions are listed above.
3 A result from an earlier run could be read as the current one Addressed: no result file is read; the reply comes over the pipe from the worker process the launcher started, in this run only.
4 A job without a log could reuse the previous job's log path Addressed: the job has no log setting any more.
5 Public wording was more detailed than the neutral standard Addressed in the PR text and commit messages; a final check of the changed public text is still due before it is published.

Tested

  • CPU tests of CI on the head after main was merged in (source-size, wording, wg-core 87 checks, launcher-core 343 checks, coexist-core 187 checks, convert-ignore 219 checks): 6 of 6 passed.
  • New launcher-core cases: a junction swapped into an ancestor of a job folder after the request was written (refused, naming the link; no job runs; nothing reaches the junction's target); the same below an already held folder (refused at the next write and read); a link at the leaf (query, write through it, removal, rename onto it: refused; removing a folder never follows a link in it; a symbolic link to a file is neither written through nor read, where the account may make one); a final path that differs from the path named (a drive letter mapped onto the folder: refused with both paths); a held folder cannot be renamed while a job runs and its writes land in the folder opened; a write outside the job's folders is refused and becomes the job's result.
  • The launcher and coexist Python suites' command-line and worker cases against a test build of the merged head (with the mock HIP runtime): 119 of 120 and 102 of 103 passed; the one failure in each (a restorer size ratio in the test build; an orphan uninstall by folder) is the same on a build of the previous head.
  • Public gates on the pushed head: the must-pass gates pass; no leak hit or flagged number is in a file this change touches.

Not tested

  • A real elevated run (UAC) on a protected game folder (prepared; it needs someone at the PC to accept the prompt).
  • An administrator account other than the player's at the prompt.
  • The Python cases that paint the launcher window (they create a graphics device): the RR, RE9, direct RR, SM2, Engine.ini fix, UI and data-root cases; and a game on a network share.

@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 21:20
@phantoslayer21
phantoslayer21 marked this pull request as draft November 13, 2026 21:25
The launcher binds the job and batch files of an elevated step to its own
request by SHA-256, and the elevated step works out its result paths
itself.

- The elevation command line carries the SHA-256 of the file it names
  (apply --job=<file> --sha256=<hex>, or apply --batch=<file>
  --sha256=<hex>); the batch lists each job file with its SHA-256
  (job= / sha256= lines).
- The elevated step reads each file once into memory, checks its SHA-256
  and parses those same bytes. A request whose job files do not match is
  not run, with a clear message that the launcher shows.
- Result paths are derived from the file given on the command line:
  result-<name>.txt for job-<name>.txt, result-<stamp>-<n>.txt for the
  n-th job of batch-<stamp>.txt. A batch with a result= line is refused.
  Results are written to a new file and moved into place.
- log= must be a plain file in the player's data folders (the job's
  localappdata folder or <data>\logs).
- Log paths and their allowed folders are compared in their long form
  (8.3 short names expanded).
- New: src/wg_core/elevated_job.cpp / .h (RunWorkerFiles); the apply verb
  and the launcher's RunElevated / RunElevatedBatch use it. The installer
  README and the Python suites follow the new form.

Tests (launcher-core, CPU, in-process without elevation): the launcher's
batch runs every job with its results at the derived paths; a batch with
a result= line is refused; a batch or single job whose SHA-256 differs
is refused; a job whose SHA-256 does not match the batch is not run; log
and folder paths the step does not accept are refused; a result is not
written through an existing name.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 force-pushed the launcher-elevated-job-check branch from 921daac to d8cc03f Compare November 13, 2026 21:35
… checked first

The elevated worker now writes no log or result file of its own, checks
every job of a batch before the first one runs, and installs the
player's OptiScaler package only from its own checked copy.

- Reply pipe: the launcher makes a pipe with a random name that only
  this account and administrators can open (one instance, local only)
  before the permission prompt and names it on the command line:
  apply --batch=<file> --sha256=<hex> --pipe=<name>. The worker sends
  its log lines and each job's result over it and runs nothing without
  it. The launcher writes the lines to its own log, takes the reply only
  from the worker process it started (process id and start time) and
  only from this run; a game without a result there is shown as not
  reported. No result file is read.
- One form: a single game is a batch of one (apply --job= is gone).
- Every job is read once, checked against the batch's SHA-256 and
  parsed before any job runs; a batch with one job that fails a check
  runs no job.
- OptiScaler package: the launcher puts the package's digest in the job
  (optisha256=: the SHA-256 of a manifest of every file and its SHA-256;
  an archive is its one file). The worker copies the package into a new
  folder that only administrators can write, checks the copy's digest
  against the job's and installs from that copy; its temporary files
  go there too, and the folder is removed afterwards. Operations that
  take no package get none.
- Every path in a job must be absolute: opti= and model= are now checked
  as well, and \\?\ and \\.\ forms are refused.
- The job file has no log= line any more; the worker ignores --log and
  --out.
- New: src/wg_core/package_snapshot.cpp / .h; tests/elevated_worker.py
  (the Python suites' side of the pipe). Test builds can put the
  worker's private folder elsewhere (WRONGGPU_TEST_PRIVATE_DIR).

Tests (launcher-core, CPU, the worker in-process with the real pipe):
the normal flow (results and log lines over the pipe, the jobs folder
empty afterwards, the install from the worker's copy, the private
folder removed); a job with a changed operation, target, package path
or package digest is refused and no job runs; a changed package
content or another folder at the package path is refused; a package
without its digest is refused; a bad or changed second job leaves the
first not run; result files on disk are ignored and an unreported job
is a failure that says so; a reply from another process is not taken;
the worker without the reply pipe runs and writes nothing; permission
not given; job path checks; the package digest and private folders.
The launcher and coexist suites use the new form, with repair through
the worker using a checked package copy and a changed package refused.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Each job's folders (the game's, the player's local app data and Documents
folders, the worker's private folder) are opened before any job runs, from
the volume root one component at a time without following a link, checked
against their final path and held without delete sharing until the job
ends. Every path below them is opened relative to the held handle the same
way; a junction, symbolic link or other redirecting reparse point on any
component is refused with the path named. Files are written under a new
name and renamed over their target through the handle, renames and deletes
go through the file's handle, and nothing outside the job's folders is
written. The converter reads private copies and writes into the private
folder; its output is copied into place through the handles. The launcher
binds each job path to the path Windows reports for it before the prompt.

Tests: a junction swapped into an ancestor after validation, a link at the
leaf, a final path that differs from the path named, a held folder that
cannot be renamed, and writes outside the job's folders, each refused with
the reason.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
… folders; a missing job folder fails when the job runs

In the elevated worker the HIP runtime is looked for only in System32 and
Program Files (never in a PATH or HIP_PATH folder the player may write),
and a candidate the guard refuses is skipped. A job folder that does not
exist is not opened as a root: the job then fails when it runs, as before.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant