Repository navigation
insbx --msys: Git Bash under network deny, as a second account granted per run (closes #38) - #92
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Trustinginsbx-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:Global\insbx-msys).insbx setup-windowsmakes both accounts and their firewall filters. The setup record is now v2; the v1 read folders carry over.Hardening from three security reviews
insbx revoke --msys-leftoversclears it and rescans before lifting the refusal;--forget-goneis needed for a gone root.Tests (Windows, real
insbx-offline+insbx-msysaccounts)fmt and clippy
-D warningsare 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:--msysand not without it.--net denyruns work with the helper locked.Note for the owner's machine: the installed
insbx.exepredates the v2 setup record. Reinstall it from this build after merging.