Skip to content

fix(linux): protect denial ancestors while preserving permitted renames - #266

Merged
kevin-orellana merged 2 commits into
mainfrom
feature/denial-ancestor-protection
Nov 3, 2026
Merged

kevin-orellana merged 2 commits into
mainfrom
feature/denial-ancestor-protection

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Through native filesystem calls, a Linux workload can rename an ancestor, then recreate and write an explicitly denied path.
For example, a write grant on /work and a deny on /work/project/private must survive an attempted rename of /work/project.
The denial mask moves with the original ancestor instead of protecting the configured location.

Solution. Keep each intermediate ancestor fixed inside the workload mount namespace while preserving ordinary moves within the writable grant.
Both denied files and denied directories use the same protection.

Trade-off. Each affected writable grant needs extra startup mounts.
The tested repair preserves unrelated moves; existing boundaries between separate grants or filesystems still apply.

Description

For each affected writable directory, establish its original grant, bind the protected ancestors onto themselves, then establish the original grant again.
The final bind covers the ancestor mounts without detaching them.
Linux retains their directory-entry protection, while permitted child paths share one visible mount.
Nested grants and denial masks retain their ordering.
Both grant binds reuse the existing source-pinning and mounted-identity checks.

This follows the covered ancestor mounts in Anthropic sandbox-runtime.
A visible-mount candidate stopped the forbidden moves but broke permitted cross-parent renames.
The covered-mount implementation passes both checks.

The production tests drive the built Box launcher with a native filesystem probe.
They check the workload result and independently verify the surrounding filesystem.
No configuration key, public API, dependency, or syscall rule changes.

Related Issues

Adjacent mount-view repairs: #254 and #261. Combined validation with those changes and #241 remains pending.

Type of Change

Bug fix

Testing

Local platform: Amazon Linux 2023 ARM64, Linux 6.12.113, Rust 1.98.1, non-root user.
The full workspace run used EXPERIMENTAL_LINUX_SUPPORT=TRUE, all features, and the required launcher and alias binaries.
The full workspace and earlier suite results below cover 796cb45.
Follow-up b57236c changes only test assertions and documentation; its six affected tests, formatting, and affected Clippy targets also pass.

Check Result
Full workspace build and tests 4,603 passed, zero failed, 17 marked ignored; the custom library harness also passed
Full containment suite 551 passed; no failures, ignored tests, or explicit prerequisite skips
Product denial, filesystem, and protected-state suites 32 passed; no failures or skips
Native ancestor replacement 24/24 refused; zero writes at the denied path; original bytes remained intact and hidden at the checked paths
Unrelated cross-parent file and directory moves 24/24 passed, including host content and source-removal checks
Existing renameat2 filter controls 18/18 refused; these measure the existing filter, separately from this repair
Formatting and workspace Clippy Passed with the repository's vendored lint allowances

The workspace count includes 13 documentation tests. It excludes 25 empty targets and one nested child summary.
The custom box_library harness runs assertions without a standard Rust test summary; Cargo completed it successfully.
The 17 ignored entries include child-process helpers, stress tests, live HTTPS fixtures, existing append and policy-macro defects, alias-read protection, and one documentation example.
The Linux skip checker accepted exactly two reported gaps: alias-read assertions and the unavailable real credential daemon.
The four new denial-ancestor tests executed without skips.

The native cases cover three ancestor levels and absolute or directory-relative renameat calls.
Two destination layouts coincide for the outermost ancestor; the count describes executed cases, not unique paths.
denied_files_survive_each_native_ancestor_rename and denied_directories_survive_each_native_ancestor_rename check both denial types.
unrelated_native_renames_across_denial_ancestors_remain_permitted checks the compatibility requirement.
Containment tests also cover nested read-only and metadata-only grants and existing authority-file protection.

An initial product run lacked the launcher binary. After building it explicitly, the entire 32-test selection passed.
That first attempt is excluded from the acceptance results.

Limits: local measurements cover one ARM64 kernel. Other kernels and architectures, startup races, arbitrary aliases, trusted broker moves, and privileged host mutation remain unqualified.
Newer kernels that can create a mount namespace without child mounts need separate qualification of the mount-lifetime assumption.
The repair's startup performance, cloud deployments, and release readiness remain unqualified.

The automated review of 796cb45 found no blocking issues.
Follow-up b57236c addresses its error-code assertion suggestion: all native ancestor cases now require EBUSY, while renameat2 retains its separate EPERM expectation.
The rerun again measured 24/24 native refusals, zero denied-path writes, 24/24 permitted moves, and 18/18 filter controls.
The two metadata-grant cases also passed. Neither suite reported a prerequisite skip.
The current-head hosted suite passes, including Linux and macOS workspace and containment tests, lint, native macOS checks, and the required CI gate.
The completed automated re-review of b57236c reports no new findings. The earlier inline thread is resolved.
This automated assessment is not a formal human approval. The delegated ownership review is recorded below.
Two existing documentation passages now match the native authority-ancestor refusal and distinguish the Linux broker limitation.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • I ran cargo fmt --all and workspace Clippy with -D warnings and the current just clippy vendored allowances

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added tests that prove the fix and preserve permitted operations
  • I have updated the documentation accordingly
  • My changes generate no new warnings

AI assistance: Codex implemented and tested this change and performed an independent code review.
At Kevin's request, Codex reviewed the complete current diff at b57236c and completed the ownership checklist on his behalf.
The checked item records that delegated agent review. Formal human maintainer approval remains required.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

Native ancestor renames can move a denial mask away from an operator's configured path.
The workload can recreate that path and write host content there.
The denied-files and denied-directories cases in box_denial_ancestors reproduce this failure when ancestor protection is removed.
Visible ancestor mounts stop those replacements but break permitted cross-parent moves.

## Solution

Collect the intermediate ancestors of file and directory refusals beneath writable grants.
Establish the writable grant, bind those ancestors onto themselves, then cover them with the original grant.
Hidden mounts keep the ancestors fixed inside the workload mount namespace while ordinary child paths share the visible grant.
Keep nested-grant ordering and reuse existing source-pinning and mounted-identity checks for both grant binds.
No public interface, dependency, or syscall rule changes.
Qualify the native scope in the Linux design and the separate trusted Shell residual.

## Tests

box_denial_ancestors::denied_files_survive_each_native_ancestor_rename and denied_directories_survive_each_native_ancestor_rename refuse all 24 native replacements.
They check denied-path writes, hidden original bytes, and final host content.
unrelated_native_renames_across_denial_ancestors_remain_permitted passes all 24 cross-parent controls with host checks.
renameat2_variants_remain_refused_for_denied_ancestors preserves 18 existing filter refusals.

The file_refusal_parent_moves_preserve_permitted_children and directory_refusal_parent_moves_preserve_permitted_children tests cover permitted moves, hard links, and nested read-only grants.
The file_refusal_ancestors_remain_protected_above_metadata_only_grants and directory_refusal_ancestors_remain_protected_above_metadata_only_grants tests cover metadata-only children.
The existing box_protected_state suite passes all four authority-protection tests.
Full containment passes 551 tests; the focused product selection passes 32 tests.
The full workspace run passes 4,603 reported tests and the custom library harness, with zero failures.
It reports 17 ignored entries and two expected prerequisite gaps: alias-read assertions and the real credential daemon.
The Linux skip checker accepts both gaps. Empty targets and a nested child summary are excluded from the count.
Formatting and workspace Clippy pass with the repository's vendored lint allowances.

Removing refusal-ancestor collection reopens all 24 native denied-path writes and fails both metadata tests.
The visible-pin candidate fails the unrelated-renames test.
New move/link assertions were not each independently mutated.
An initial product run lacked the launcher; the complete 32-test rerun passed after an explicit launcher build.

Measured on non-root ARM64 Amazon Linux 2023, kernel 6.12.113, Rust 1.98.1.
Other kernels, architectures, startup races, arbitrary aliases, trusted broker moves, privileged host mutation, and combined repairs remain unqualified.
Newer empty-mount-namespace behavior remains a source-derived qualification risk, not a reproduced bypass.
The repair's startup performance, cloud deployments, and release readiness remain unqualified.
@kevin-orellana kevin-orellana changed the title Fix Linux denial ancestor replacement while preserving permitted renames fix(linux): protect denial ancestors while preserving permitted renames Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Comment (I found no blocking issues)

I reviewed head 796cb45. I traced the case analysis for the new refusal-ancestor planning and for the covered re-bind in materialize, and I found no case that gives a wrong result. My one inline comment is about a test assertion that is weaker than the mechanism it tests.

Assumptions and rules checked that held
  • Mechanism: A hidden self-bind under a covering grant bind refuses ancestor rename/RENAME_EXCHANGE with EBUSY, and cross-parent file and directory moves and hard links still work. I reproduced this independently under sudo unshare -m on x86_64 kernel 7.0, which widens the PR's single ARM64 6.12 measurement.
  • Planning scope: These cases all plan the correct ancestor set:
    • a deny that is a direct child of the grant (no ancestors);
    • a deny equal to the grant (the refusal dedup removes the grant entry);
    • nested read-only grants and nested writable grants (protected at both levels);
    • metadata-only Dir roots and refused trees (pruned by retain).
  • Valid before this change: Every config whose new ancestor bind can fail (a symlinked or absent ancestor) already failed in the O_NOFOLLOW refusal walk. The PR adds no new startup refusal for a config that worked before.
  • Write protections: Moving their parents from visible to covered keeps the same set. Only Grant-origin writable binds can hold directory parents. Socket and /dev binds are files.
  • Workload escape routes: umount2, unshare, open_tree and move_mount stay denied by seccomp, and capabilities are dropped. The workload cannot uncover or detach the hidden layer.
  • Startup race with another namespace: An ancestor swapped between the grant bind and the self-bind makes the later refusal walk fail closed.
  • Frozen surfaces and premises: No config key, CLI, public pub use or syscall rule changes. The commit message has the required Problem/Solution/Tests sections.

Pre-existing and outside this diff: docs/design/decisions.md (the "On Linux, when the authority directory sits more than one level below a write grant…" paragraph) and the doc comment on box_direct_filesystem.rs::this_boxs_authority_survives_a_rename_of_its_parent still say the Linux ancestor rename succeeds. The test body already asserts EBUSY, and linux-enforcement.md now says otherwise, so both are worth updating in a follow-up.

The covered-mount approach is a clean way to get both properties without changing any interface.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 2, 2026 03:30
## Problem

The native ancestor regression accepted cross-mount errors from the rejected visible-pin design. Two existing documentation passages still described successful Linux authority-ancestor moves.

## Solution

Require EBUSY for native ancestor renames in both product and metadata-grant tests. Preserve EPERM expectations for the existing renameat2 filter. Describe the native refusal on both platforms and retain the separate Linux broker limitation.

## Tests

Rerun the two metadata-grant tests and all four production denial-ancestor tests with all features. Check formatting and affected Clippy targets. The production implementation is unchanged from the full workspace run at 796cb45.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve (no new findings)

I re-reviewed head b57236c against 796cb45, the commit I reviewed before. The new commit fixes the earlier test suggestion and the stale documentation. It changes no production code.

What I checked on this commit
  • Tests are stricter: denial_matrix now requires EBUSY for every renameat row, and metadata_refusal_ancestors now asserts EBUSY instead of is_err().
  • Tests pass on a second platform: as root on x86_64 kernel 7.0, {file,directory}_refusal_ancestors_remain_protected_above_metadata_only_grants and {file,directory}_refusal_parent_moves_preserve_permitted_children all pass. Unprivileged, the runner skips them.
  • The tests catch a regression: I removed the covering self.establish(entry, root)? in materialize as a temporary change, then restored it. Both *_refusal_parent_moves_preserve_permitted_children tests then fail with EXDEV. So dropping the covering bind now fails at unit level, and also in the tightened grant-root rows of the product matrix.
  • The docs agree with each other: decisions.md and the doc comment on this_boxs_authority_survives_a_rename_of_its_parent now match linux-enforcement.md and the test body. Linux returns EBUSY and macOS returns EPERM, and the separate Linux Shell-move limit is still stated as in crates/box/AGENTS.md.

Everything that held at 796cb45 still holds, because the production code is the same.

@kevin-orellana
kevin-orellana merged commit 693661c into main Nov 3, 2026
24 checks passed
@kevin-orellana
kevin-orellana deleted the feature/denial-ancestor-protection branch November 3, 2026 16:33
@akujane akujane mentioned this pull request Nov 4, 2026
5 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Agent Containment bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants