Repository navigation
fix: refuse unsafe Linux file permission requests - #199
Conversation
## Problem Linux workloads can store set-user-ID and set-group-ID bits through permitted file-mode calls. Execution restrictions do not prevent those bits from remaining on the host file. ## Solution Reject explicit special-bit requests during permission changes and creation. Preserve ordinary writes, executable-bit changes, and approved shared-directory inheritance. Retain existing ownership and alternate-creation refusals. Add no filesystem grant, configuration field, or dependency. ## Tests The all-feature containment suite passes. direct_file_permissions_preserve_writes_and_refuse_special_modes checks 80 host controls, 20 contained successes, and 60 refusals with final metadata and host-path assertions. Seven deliberate mutations fail; an unchanged scratch baseline passes. An additional native run under an owned shared-group parent preserves inherited directory mode 02755. Containment build, clippy, formatting, and feature-disabled build pass on native ARM64 Linux. The deterministic suite reports 119 passed cases, one failure, and nine macOS-only skips. The sole home-path assertion failure also reproduces on freshly rebuilt unchanged main. The full workspace phase exceeded its 600-second cap and remains incomplete. Native macOS and other Linux targets were not rerun for this four-file candidate. Independent adversarial review found no blocking production defect.
|
Assessment: Comment (close to approve) The fix closes a real gap — a Review notes
Thorough work — the threat model, enforcement, and docs are well aligned. |
|
Assessment: Comment (re-review of 7396d35) The new commit adds only a two-line comment, which is accurate. The tested source still matches e748404. One correctness finding from the earlier source is new in this review (see inline on Checks that held
|
|
Assessment: Approve (re-review of 0ee541f)
Checks that held
I could not run the new test itself: the file is gated to aarch64 and this runner is x86_64. Its result rests on the author's ARM64 run. |
|
Assessment: Approve (re-review of dd5eea7, the merge of main) The merge resolution keeps both sides. Compared with the new main parent ( Checks that held
The aarch64-gated permission regressions still can't run on this x86_64 runner. They rest on the author's post-merge ARM64 run. |
|
Assessment: Approve (re-review of ab5ede2, after merge
Checks that held
The aarch64-gated permission regressions still can't run on this x86_64 runner. They rest on the author's ARM64 run. |
Human readable section
Problem. An untrusted Linux program can leave special permission bits on writable host files after Box exits. Where execution rules honor these bits, an executable can run with the file owner's user or group identity. Box's existing execution restrictions do not prevent the stored permission change.
Solution. Reject file-creation and permission-change requests that explicitly include either special bit. Continue to permit ordinary writes under existing file-access grants. Continue to reject file-owner and group-owner changes.
Trade-off. Directories can still inherit their parent's shared group and the bit that passes this group to new subdirectories. Tools that explicitly request these shared-group permissions fail, including
git init --shared, which can leave a partial repository.Permission updates that preserve existing special bits also fail. This includes some
chmodcommands on directories that inherited the group bit. A request that clears both bits can succeed under existing grants. This change does not remove existing bits or expand file-access grants.Description
The special bits are set-user-ID and set-group-ID. The group bit also controls directory group inheritance.
The existing Linux restriction filter now checks the requested mode for
fchmod,fchmodat,fchmodat2, andmkdirat. Foropenat, it checks the mode only whenO_CREATor the completeO_TMPFILEflag is present. An unused mode argument remains ignored. Comparisons use the low 32 bits consumed by the kernel.Tools that explicitly request shared-group modes remain incompatible:
install -d -m 2775,mkdir -m g+s, andgit init --sharedfail. This also applies under an existing shared-group parent. Git can leave a partial repository. The tested ordinary versions of these commands succeed.Permission changes, including executable-bit changes, require a requested mode without either special bit. GNU
chmod g+wandchmod 755fail on a directory that inherited its group bit because their requests preserve it. A request that clears both bits can succeed under existing grants.Ownership calls and alternate creation routes retain their existing default denial. The native regression checks refusal results, final mode and ownership, and host-side absence after refused creation. Safe uncontained controls prove that the requested operations can succeed on owned temporary files.
This change is independent of the native-policy integration. It adds no policy input, configuration field, or dependency commit. This PR does not change whether workloads can read helper programs. It also excludes performance work and unrelated platform defects.
Related Issues
Addresses the file-permission portion of #51. The issue covers other controls, so this PR does not close it.
Type of Change
Bug fix
Testing
Current revision:
ab5ede2cd599bfefb3f7d13cee11c22edf80a47b. This branch includes conflict-repair merge452da395c24b4a2412c30ef8ce8908e7f3cd246bwith mainef009143f5ed960d18c145c4fcc7063da1e9ec93. The sole conflict joined adjacent restriction-filter helpers. The resolution preserves this PR's special-permission checks and main's terminal-control restrictions unchanged. The permission regressions and main's terminal tests are unchanged. Codex reviewed the changed files, and a second agent independently reviewed the resolution. Formal maintainer approval remains separate.Final naming-only follow-up.
ab5ede2addresses the human review nit by replacing the two numeric masks withlibc::S_ISUIDandlibc::S_ISGIDthrough lossless conversions. No policy value or control flow changed. Formatting, strict all-target containment lint, all 26 syscall unit tests, and both non-root permission regressions passed again with zero omitted prerequisites. A second agent reviewed the one-line diff. The reply records the change, and that thread is resolved. The full local suite and root controls below ran on452da39; they were not repeated for this value-preserving naming change.The human approval submitted for
dd5eea7was dismissed after the conflict-repair push. Formal approval of the current revision remains required.Current hosted checks and automated review. The current-head CI run and automated-review trigger are pending. The trigger is not a completed reviewer assessment. Previous-revision hosted results below do not establish current-head approval.
Local validation of merge
452da39. Amazon Linux 2023 ARM64, kernel6.12.113-138.209.amzn2023.aarch64, Rust1.98.1; Linux experimental support enabled. An isolated target used four build jobs and four test threads. The product and containment build, whole-workspace formatting, strict permission-test lint, and the documented whole-workspace lint recipe passed. The lint recipe uses only its existing vendored allowances. All 26 syscall unit tests and seven terminal unit tests passed.Both permission regressions passed as non-root and real root. Each identity produced 87 successful outside controls, 23 permitted contained operations, and 64 expected refusals, with zero omitted prerequisites. This includes inherited-directory permissions and requests that preserve or clear existing special bits. The two helper test entries are not additional security cases.
Two initial root launches failed during namespace setup because private parent directories prevented reopening the test executable; no contained permission assertion ran. The identical binary then passed from a unique, traversable task-owned directory under
/tmp, with no source or shared-directory permission change. Its SHA-256 was4c50795699ef4563f122986da8f21ff45724bd4950e54a2f1a8a6c2d5e6fc331at both locations. The failed setup logs remain recorded alongside the successful runs.The full
cargo test --workspace --locked --all-features --no-fail-fast -- --show-outputcommand completed successfully: 4,619 top-level pass entries, zero failures, and 17 ignored entries across 142 result blocks. One nested child result is excluded from those totals. The raw output audit failed because the installed-alias unit test lacked its helper beside the test binary. After applying the existing hosted build-output installation recipe, that exact test passed separately with zero skips; its separate output audit passed. The full suite was not repeated, and its raw audit failure remains recorded. Two documented omissions remain: the real credential-daemon fixture was unavailable, and the execute-only alias read assertion is unsupported by the namespace backend; the alias write assertions ran.These local results do not qualify a release. No shared deterministic fixture suite ran locally for this repair. Historical tests and their limits follow.
Previous revision: November 1 hosted checks. The continuous integration gate passed for
dd5eea7f19caec86aa2a7c41fe693231ff734c0aon November 1, 2026. This status is separate from the local and historical test results below. The optional Verdict job skipped and provides no coverage.Previous head
dd5eea7f19caec86aa2a7c41fe693231ff734c0amerges maine4ca8b80359b2213d684de31cd6ef32e0d61478a. The sole conflict combined two independent documentation additions; both remain intact. Both permission regressions passed again as root and non-root on this combined source. Strict scoped lint and formatting passed. Independent review confirmed that the merge retains main and introduces no additional permission-policy change.Previous branch revision
dd5eea7passed the complete hosted validation run: Linux ARM64 and macOS all-feature workspace tests, both deterministic containment suites, native macOS checks, packaging, lint, and the final gate. Security analysis also passed. The optional Verdict job was skipped; it provides no coverage. These results do not establish deployment qualification or release acceptance.The automated review of this exact revision reports Approve with no new findings. At that November 1 checkpoint, both review discussions were resolved. Current human review status is recorded above.
Earlier local validation.
Original tested source:
e74840408aad18421651763e3c9d1808b8ef8160, based directly on main6418aad802e92880b6c5c431c942cef5a283aaef. The original four-file source hashes exactly match the candidate tested and independently reviewed before publication. Follow-up commit7396d35e3e3189d4f2e3b194962587c8e0fab6b0adds only a two-line code comment about directory inheritance. Formatting and whitespace checks passed. At that revision, removing those comment lines reproduced the original tested source exactly.Earlier follow-up:
0ee541f41fc4960e9d3db65c41b7b909e74a291fupdates both guides and addspermission_changes_refuse_existing_special_bits_unless_cleared. It changes no enforcement code. The new regression covers actual directory inheritance and existing special-bit files, successful host controls, refusals that preserve the bits, successful requests that clear them, and final host mode/ownership checks.The new regression passed under real-root and non-root launches through the production trampoline: 14 successful host controls, eight contained refusals, six contained successes, and zero skips. The original 80-case permission regression also passed under both identities. Formatting, whitespace checks, and
cargo clippy --locked -p strands-box-containment --all-features --test file_permissions_linux -- -D warningspassed. An initial non-root assertion incorrectly compared host IDs with sandbox IDs; the corrected assertion compares identities within each namespace, and both final runs passed.Follow-up environment: Amazon Linux 2023 ARM64, kernel
6.12.113-138.209.amzn2023.aarch64. Independent adversarial review found no remaining blocking issue in the final follow-up. The later November 1 revision passed the hosted checks and automated review recorded above.Original revision: earlier validation and its limits
The remaining table records the original revision's broader validation and its limits.
Native target: ARM64 Linux, kernel
6.12.111-136.204.amzn2023.aarch64, Rust1.98.1. Linux experimental support was enabled. Temporary fixtures used an owned executable filesystem. All permission-test host prerequisites were available.cargo build --locked -p strands-box-containment --all-features;cargo test --locked -p strands-box-containment --all-features -- --nocapturecargo clippy --locked -p strands-box-containment --all-targets --all-features;cargo fmt --checkcargo build --locked -p strands-box-containment --no-default-featurescargo build --locked -p strands-box -p strands-box-containment --all-features --bins0277002755inside and outside Box. Explicit special-mode requests remained refused.bash test-integ/run.shbash scripts/test-all.shThe sole deterministic failure is
CN-L-02, the Linux home-directory containment case. Its fixture compares a canonical home path with a noncanonical spelling and raisesStripPrefixError. A freshly rebuilt unchanged copy of the exact main revision reproduces the same failure. No candidate-only deterministic failure was found.The metadata assertions reuse the principles of macOS file-control cases
CN-F-02andCN-F-03. macOS source is unchanged; native macOS tests and other Linux targets were not rerun for this candidate. The inheritance run is supplemental evidence; the regression source does not create that special parent itself.Supplemental real-tool verification ran 32 commands on the original tested revision using coreutils 8.32 and Git 2.50.1. All 16 host controls and eight ordinary contained controls succeeded; eight explicit shared-mode operations failed as expected. Git results were confirmed with both empty and installed default templates. Final host metadata and syscall traces establish the distinction between inherited directory bits and refused explicit requests. These measurements do not establish successful package-manager workflows that request shared-group modes.
Independent adversarial review found no blocking production defect. At this earlier checkpoint, full repository validation was incomplete. The November 1 revision's completed hosted results are listed above.
just check, orcargo test --workspace --all-features)cargo test --workspace --locked --all-featureson hosted Linux ARM64 and macOS runners. Linux also passed the unexpected-skip audit. The original local time limit is retained above as historical evidence.cargo fmt --alland the documented workspace lint recipe.-D warningsand the vendored allowances required by CONTRIBUTING.md. That required recipe replaces the template's unsupported bare lint command; no new allowance was added. The changed permission test also passed strict scoped lint without allowances.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.