Skip to content

insbx --msys: Git Bash under network deny, as a second account granted per run (closes #38) - #92

Merged
blockmandev merged 5 commits into
mainfrom
feat/insbx-msys
Nov 13, 2026
Merged

blockmandev merged 5 commits into
mainfrom
feat/insbx-msys

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Closes #38.

What it does

insbx run --msys --net deny|proxy (or [fs] msys = true) runs Git Bash and other msys programs natively on Windows. msys only gives its pipes and sections to the token's own user, so the run's token must trust that user's SID. Trusting insbx-offline, whose grants are kept since #85, would open every folder an earlier run used (measured on #38). So msys runs use a second account, insbx-msys:

  • Its grants are per run, never kept, and revoked when the run ends.
  • One msys run at a time (Global\insbx-msys).
  • An OWNER RIGHTS entry on its roots, covering files created with the default ACL.
  • insbx setup-windows makes both accounts and their firewall filters. The setup record is now v2; the v1 read folders carry over.

Hardening from three security reviews

  • The helper's threads and process are locked before the command starts. Each write right is checked separately, threads created later start out locked, and the command's token is made before the lock.
  • A leftover write grant from a dead or crashed msys run refuses later msys runs. This includes a root moved or replaced (folder identity is recorded), an entry a revoke walk missed, and CREATOR OWNER sources. insbx revoke --msys-leftovers clears it and rescans before lifting the refusal; --forget-gone is needed for a gone root.
  • Roots that pass down CREATOR OWNER, or a broad OWNER RIGHTS entry, are refused.
  • An msys lease or hardening failure always refuses, best effort or not.
  • Records are rewritten atomically, and the sweep re-reads under the lock (a race the live escape tests found).

Tests (Windows, real insbx-offline + insbx-msys accounts)

fmt and clippy -D warnings are clean. cargo test -p incord-sandbox -- --nocapture, 4 runs in a row: 116 lib, 3 main and 33 escape tests pass, none skipped. They include:

  • Git Bash runs under --msys and not without it.
  • Plain --net deny runs work with the helper locked.
  • The command can't open its helpers' threads (each of 5 write rights, with a control).
  • An msys run can't write where another run kept a grant.
  • Crash + moved/replaced root and a CREATOR OWNER subfolder stay refused until dealt with.
  • Two msys runs serialize.
  • Concurrent deny runs stay isolated.

Note for the owner's machine: the installed insbx.exe predates the v2 setup record. Reinstall it from this build after merging.

…ed per run (#38)

Git Bash dies under the write-restricted token because msys builds its pipes
with a DACL naming only the token's user. Trusting that user's SID in the
restricting SIDs fixes it, but not as insbx-offline, whose ACEs on roots are
kept across runs (measured: a run wrote into another run's folder).

So `insbx setup-windows` also makes insbx-msys (same hiding, Users membership,
WFP filters via one two-account condition, --read grants), and `[fs] msys = true`
/ `--msys` runs the command as it, with its SID trusted by the token (checked
against the setup record by the first helper and against the token's own user
by the second). Its Modify on roots and RX on reads are granted per run and
taken back on drop or by the crash sweep; one msys run at a time
(Global\insbx-msys); each msys root keeps an inheritable OWNER RIGHTS entry of
READ_CONTROL only, after the user's READ_CONTROL|WRITE_DAC entry. With network
allow the policy is a gap in strict mode; ignored off Windows.

Setup record is version 2 (no compatibility with version 1: set up again).
1. A crashed msys run's grants the sweep cannot take back (a root moved or
   gone, a failed revoke, the ACL lock busy) now refuse the next msys run,
   naming the paths; the sweep keeps an msys record with a missing root;
   `insbx revoke` also takes the msys account's ACE, and
   `insbx revoke --msys-leftovers` clears stuck records.
2. The second helper's threads (and process) are locked: by the first helper
   before the thread first runs, and by the second helper on every thread of
   its own before it starts the command.
3. An msys root that passes down CREATOR OWNER is refused.
4. An OWNER RIGHTS entry broader than READ_CONTROL on an msys root is refused,
   not trusted as already there.
5. A failed msys lease refuses the run even with --best-effort.
6. `setup-windows` carries a version-1 record's --read folders over and gives
   them to insbx-msys too (and --remove revokes them).
7. Releasing the msys account on a setup --read folder puts the read grant
   back.
8. `wait` kills the command when the wait fails; Guard documents it must
   outlive the command.

Also: the OWNER RIGHTS claim reworded to what holds; the helper logs on with
the constant account names.
- Thread hardening no longer refuses every account run: the current thread is
  locked through the GetCurrentThread pseudo-handle, a thread the first helper
  already locked (it denies its owner WRITE_DAC) is not an error, every thread
  is tried, and only one that is neither lockable nor locked fails.
- The helper's token default DACL is set to the thread DACL before the
  snapshot, so threads made later are born locked. A hardening failure refuses
  an msys run in every mode (helper and first helper).
- A grant record holds each msys root's volume serial and file index; a root
  that is a different folder under the same name counts as missing.
- Records are replaced by temp file and rename, never truncated.
- After the revoke walk (and in the sweep) the tree is read for any allow
  entry for the msys account beyond reading; those exact objects stay as
  leftovers, and --msys-leftovers revokes them.
- Carried-over version-1 read folders get --read's canonicalize and
  refuse_broad; a missing or broad one stays in the record.
- --msys-leftovers re-reads each root's tree after the release (no cap) and
  keeps the record, with exit 1, when a write entry is still there or comes
  back; an inherited CREATOR OWNER entry is named as the cause.
- A record naming a root that is gone, moved or replaced is kept unless
  --forget-gone is given.
- Thread lock state is checked for each write right on its own
  (SET_CONTEXT, SUSPEND_RESUME, SET_INFORMATION, WRITE_DAC, WRITE_OWNER); an
  exited thread (ERROR_INVALID_PARAMETER) is gone, not a failure.
- inner() makes the command's token before locking the helper; a measured test
  shows a child started by a locked helper can still query its own token.
- The sweep reads a record again under the ACL lock, so it cannot write back a
  record --msys-leftovers has just cleared (found by the escape tests).
- Escape tests: per-right OpenThread probe, a real crash with the root moved
  aside and replaced, a subfolder with its own CREATOR OWNER entry end to end;
  the msys tests run one at a time.
… an elevated admin (#38)

The thread-hardening unit tests asked whether a hardened thread or process could be opened from the test's own token. An elevated runner holds SeDebugPrivilege, which opens any thread whatever its DACL says; the real command's token has DISABLE_MAX_PRIVILEGE. The probes (and harden_thread's lock check) now run on a thread impersonating a privilege-stripped copy of the process token, reverted after; if that token cannot be made the test prints SKIPPED with the reason. A test checks the probe token really keeps at most SeChangeNotify. The code under test is unchanged.
@blockmandev
blockmandev merged commit df997f2 into main Nov 13, 2026
12 checks passed
@blockmandev
blockmandev deleted the feat/insbx-msys branch November 15, 2026 20:29
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.

insbx on Windows: Git Bash / msys can't start natively (error 5); fix with a private object namespace per run

1 participant