Skip to content

fix(containment): pin Linux refusal mount targets - #159

Merged
kevin-orellana merged 4 commits into
mainfrom
feature/linux-refusal-mount-targets
Oct 27, 2026
Merged

kevin-orellana merged 4 commits into
mainfrom
feature/linux-refusal-mount-targets

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Suppose Box allows access to /work but denies /work/project/private. On Linux, Box blocks access by mounting a cover over the denied path. If another host process replaces project or private with a symbolic link during startup, Box can follow that link. The cover can then land at the wrong location.

Solution: Box opens the target directory or file and keeps a reference to it while mounting the cover. It then checks that the cover is at the intended path. If that check fails, Box stops startup.

Trade-off: If a denied directory is missing inside a shared host directory, Box now stops startup. Previously, setup could create that directory on the host.

Description

Fresh filesystem mounts and empty-file refusals resolve each target component with openat and O_NOFOLLOW. Missing components are created only outside planned host binds.

This intentionally covers every Fresh mount: the staging root, /proc, /tmp, empty grants, and directory refusals. All use the same mount setup code and must verify where the mount landed. Setup requires the inherited /proc to remain readable until Box switches into the completed filesystem view. If descriptor information or the mount table cannot be read, startup fails.

Mounting uses the retained descriptor. The subsequent check reopens the intended spelling without following links and verifies a new mount identifier at that exact path. Empty-file refusals remount the verified mount read-only through its descriptor.

The tests cover ancestor and leaf replacement before assembly, replacement after the target opens, replacement with real directories, absent denied directories, and concurrent exchanges. Successful views must deny protected access while preserving sibling writes. Tests compare outside-tree contents and the original file's bytes after the child exits.

The test harness uses the existing namespace prerequisite probe and reports explicit skips when the host refuses those prerequisites. Child panics exit with failure.

The grant-source Bind arm, dependency admission, configuration schema, and public interfaces are unchanged. The combined code with #157 passed 532 containment tests on Linux at heads c1c0300 and e061220. Both merge orders produced the same tree without conflicts. See the combined validation results.

Broker message reads also retain partial bytes when another call finishes. Previously, handling that completion discarded the read buffer, which could hang or close the connection. A regression sends one prefix byte and waits until the server consumes it. It then completes another call before sending the remaining bytes. Protocol fields, size limits, and timeout settings are unchanged.

AI assistance: Codex prepared the implementation, tests, and this description at the contributor's request.

Related Issues

No public issue linked. This PR does not include the private report or its artifacts.

Type of Change

Bug fix

Testing

Current head: c1c03008b630a22342ff7000b6ef7f21a82c799b, including main at f0dc6f4. The merge keeps both loader-admission and refusal tests. Local Linux execution used Amazon Linux 2023 userspace on AArch64, kernel 7.0.12-linuxkit, and Rust 1.98.1 in a dedicated privileged Docker container.

Check Result
Integrated containment library, configured UID 1000, one test thread 361 passed, zero failures or skips, including loader and refusal regressions
Broker host tests, container root 43 passed; two process-reaping failures also reproduced in the retained pre-fix binary
Partial-message regression Failed before the broker fix after consuming one prefix byte and completing another call; passed with the fix
Partial-message and reused-program-ID tests 20 repetitions each passed
cargo fmt --all -- --check and git diff --check Passed
Workspace Clippy Passed with the allowances listed in the repository's just clippy recipe
Hosted Linux workspace tests Passed at c1c0300. The job excludes 18 containment tests; the local 361-test run above includes them.
Hosted macOS workspace tests Passed at c1c0300, including the partial-message and reused-program-ID regressions.
Hosted Linux ARM deterministic suite GREEN: 120 passed, zero failures, nine platform-specific skips.
Hosted macOS deterministic suite GREEN: 121 passed, zero failures, eight platform-specific skips.
Hosted formatting and lint Passed with the same lint allowances as just clippy.
Other hosted checks Native macOS build/tests, CodeQL, PR title, and CI Gate passed. The separate Verdict job skipped.

The two local broker failures are a_protocol_error_reaps_the_open_mcp_process_group and broker_shutdown_joins_a_live_mcp_exchange_and_reaps_its_process_group. Both fail before and after this change in the local container. Earlier integrated test attempts exhausted the shared Docker disk; those attempts are excluded from the passing count above.

Earlier refusal validation recorded 128 concurrent replacements: 64 established views with denial intact and 64 startup refusals. No outside mounts or writes occurred. A negative control using pathname mount targets failed the late-replacement regressions. The no-default-features containment build completed with existing dead-code warnings.

At prior head afd0439, the hosted Linux ARM deterministic suite passed: 120 cases, zero failures, and nine platform-specific skips. Hosted macOS deterministic tests and Linux unit tests also passed. The macOS unit job failed the reused-program-ID test; the broker fix and regression above address interrupted frame reads. The current-head results above supersede that earlier failed macOS run.

The Cargo fixture read-grant correction is now also present in main. The earlier full local scripts/test-all.sh run stopped during workspace compilation. These results do not establish Runtime, Lambda, or release qualification. Finite replacement trials do not prove every possible schedule or host mutation after startup.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
    • Verified the hosted workspace runs at c1c0300. macOS ran the workspace with all features and no test-name filter. Linux used its documented exclusions. Existing ignored tests remain. The earlier local workspace run was incomplete.
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings
    • Formatting and workspace Clippy passed locally and in the hosted job. CONTRIBUTING requires just clippy because the vendored shell needs lint allowances. The recipe applies -D warnings plus allowances for too_many_arguments, only_used_in_recursion, await_holding_refcell_ref, explicit_auto_deref, chunks_exact_to_as_chunks, dead_code, and non_snake_case. This unchecked box records that the literal command without allowances was not used. The required repository lint check passed.

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 any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
    • Not applicable: this restores existing refusal behavior without a new configuration or public interface.
  • My changes generate no new warnings
    • Verified with the repository workspace Clippy recipe and its explicit lint allowances.

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

## Problem

Linux refusal setup resolves mutable pathnames before the root pivot.
A replaced component can redirect a mount or create a mountpoint on the host.

## Solution

Open each target component without following symbolic links.
Create missing mountpoints only outside planned host binds.
Mount through the retained descriptor and require a new mount identity at the intended path.
Apply the same target handling to fresh filesystems and empty-file refusals.
Keep the grant-source Bind arm and public interfaces unchanged.

## Tests

The final Linux ARM64 library binary passed 346 tests as a configured non-root user.
All 12 refusal tests passed, including 128 concurrent replacement trials.
The trials produced 64 denied established views and 64 startup refusals.
They observed no outside mounts, outside writes, or changes to original authority bytes.
Ancestor, leaf, missing-directory, permitted-sibling, and child-panic cases passed.
The path-target mutation failed the late-replacement regressions.
Formatting, the default-disabled build, and containment Clippy passed.
Clippy used the repository allowance for chunks_exact_to_as_chunks.
The broader workspace run stopped with Docker during compilation.
Deterministic, macOS, hosted, and cloud qualification remain incomplete.
@kevin-orellana kevin-orellana self-assigned this Oct 23, 2026
@kevin-orellana
kevin-orellana marked this pull request as ready for review October 23, 2026 07:14
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The two-step approach — pin each target component with O_PATH | O_NOFOLLOW, mount over /proc/self/fd/N, then reopen by name and confirm a new mnt_id lands at the exact spelling in mountinfo — is a sound defense against the ancestor/leaf symlink swap described. The mountinfo parsing (nth(3) → mount_point) is correct and robust to the variable optional fields, and previous.contains(id) combined with the landed check closes the mount-id-reuse gap. Test coverage across before-open, after-open, real-directory, missing-target, and concurrent-exchange timings is thorough and fails closed.

Review notes
  • Scope broadening: require_new_mount now applies to all Fresh mounts, not only refusals — looks intentional and beneficial, but isn't reflected in the PR narrative (see inline note).
  • Readability: walk's dual resolve/create responsibility signalled via Option<&MountView> is a little indirect (see inline suggestions). Logic is correct.
  • Process: PR is marked draft and self-reports that the full-workspace cargo test and full-workspace clippy -D warnings did not complete, and that deterministic/macOS runs were not done. These gates should be green before merge. Also coordinate with fix(containment): keep Linux metadata-only parents empty and read-only #157, which touches Fresh grant preparation in the same module.
  • No public interface change observed (private targets module; namespace_test_is_permitted only widened to pub(super)), consistent with the interface-freeze expectations.

Nice work pinning the target by descriptor and verifying placement rather than trusting the path — the layered fd-then-reverify design is the right call here.

@github-actions

Copy link
Copy Markdown

Re-reviewed at afd0439. The only new change since my last pass is cn_w_06.rs adding cargo_home to the read roots for [tool.cargo]. Since cargo_home was already in the write list and "write does not imply read," the contained cargo invocation needs this explicit read grant for its CARGO_HOME cache — correct and consistent with that premise. Test-only, no production or interface impact.

The production fix is unchanged and still looks sound. My two earlier readability suggestions (the walk resolve/create flag and the create.unwrap()) remain open but are non-blocking. Assessment stays Comment; the draft-gate items (full-workspace cargo test and clippy -D warnings, deterministic/macOS runs, and #157 coordination) are the remaining things to close before merge.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) October 23, 2026 16:47
@kevin-orellana kevin-orellana added the linux Linux containment and Linux launch work label Oct 23, 2026
Comment thread crates/box/src/run/broker/host.rs Resolved
@github-actions

Copy link
Copy Markdown

Re-reviewed at c1c0300. Two things changed since afd0439: the cn_w_06.rs cargo read-grant is now in main (no longer in this diff), and a net-new broker fix landed in crates/box/src/run/broker/host.rs.

Broker fix — looks correct. The bug is that read_frame was recreated fresh inside each select! retry, so a partially buffered frame was discarded whenever a Call-completion branch fired (a cancel-unsafe future dropped mid-read). Pinning a single read_frame future once per outer iteration and reusing &mut next_frame across the inner loop is the right, idiomatic fix: the future is only re-created on the next outer iteration (after break frame), so a completed future is never re-polled, and the idle-timeout semantics are unchanged. The regression test is solid — it uses FIONREAD to confirm the server actually consumed the single prefix byte before completing the first Call, and it fails closed under a 10s timeout. serve_transport is private, so no interface change.

Notes
  • Scope: the broker fix is a different subsystem from the containment mount work. It's now clearly documented in the description and causally linked to the macOS a_reused_program_id_never_reports_a_closed_calls_status failure this PR surfaced, so bundling is defensible — a standalone PR would still have been cleaner, but no action needed.
  • Minor: one non-blocking inline note on constructing next_frame on the pending path.
  • Process: the draft-gate items remain — current-head hosted checks + native macOS are pending, the strict full-workspace clippy -D warnings/cargo test --all-features attestations are unchecked, and fix(containment): keep Linux metadata-only parents empty and read-only #157 coordination still applies. The two local broker failures are documented as pre-existing (reproduce on the unmodified binary).

Assessment stays Comment. Nice, targeted fix with a regression test that pins down the exact partial-read timing.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

Updated the validation evidence for the unchanged head c1c03008b630a22342ff7000b6ef7f21a82c799b.

The Linux and macOS workspace jobs passed. Both include passing results for the partial-message and reused-program-ID regressions. Linux retains 18 containment-test exclusions; the local non-root 361-test run covers those tests. Existing ignored tests remain.

The deterministic suites also passed: Linux reported 120 passes and nine platform-specific skips; macOS reported 121 passes and eight platform-specific skips. Both reported zero failures.

The hosted lint job passed. CONTRIBUTING requires the just clippy recipe with its vendored-code allowances. The description now lists those allowances. The literal no-allowance checkbox remains unchecked to avoid claiming a command that did not pass.

The previous pending-check text was stale. I replaced it with these receipts and retained the documented local limitations. I am requesting another automated review against this updated evidence. This update does not claim formal approval or close the remaining review threads.

@github-actions

Copy link
Copy Markdown

Re-checked at c1c0300. No code has changed since my last review — the only update is the refreshed CI evidence.

I confirmed the check-runs on this exact head via the API: all 20 are green (plus one benign skipped review-verdict gate). That includes Rust / Lint, Rust / Unit Tests on ubuntu-latest and macos-latest, Containment / Deterministic on ubuntu-24.04-arm and macos-latest, Native Filesystem / macOS, and CodeQL across all analyzers. This resolves the process/draft-gate items I'd been tracking (hosted + native-macOS runs and the lint gate) — the previously-failing macOS reused-program-ID regression now passes with the broker fix in place.

No new code to review. The two remaining open inline threads (the walk resolve/create flag and the next_frame-on-the-pending-path note) are non-blocking readability suggestions left to your discretion.

Assessment stays Comment; from my side there are no blocking items. The remaining caveats are the ones you've already documented in the description (local full-workspace run incomplete; no Runtime/Lambda/release qualification; finite replacement trials), plus the usual maintainer sign-off and #157 coordination.

@kevin-orellana

Copy link
Copy Markdown
Collaborator Author

The #157 compatibility check is complete for the two current PR heads. Their combined code passed the full containment test suite on Linux.

I combined these heads in an isolated checkout, including their existing main ancestry. The merge needed no conflict resolution. Reversing the merge order produced the same tree.

Check Result
Full containment suite, all features 532 passed: 376 library tests, 48 trampoline tests, and 108 integration tests. Zero failures, ignored tests, test-name exclusions, or runtime prerequisite skips.
a_refusal_beneath_a_metadata_only_directory_establishes Passed. The directory stayed empty and read-only, denied children stayed hidden, and outside denial/protection controls remained effective. Both outer-grant configurations passed.
Refusal replacement regressions Passed for ancestor and leaf replacements, before assembly and after opening, including replacement directories and missing targets under writable host binds.
concurrent_replacements_cannot_redirect_directory_or_file_refusals 128 trials: 64 established views preserved denial, and 64 refused startup. Zero outside mounts, outside host writes, or authority-file changes.

The command was:

cargo test --locked -p strands-box-containment --all-features -- --test-threads=1 --nocapture

Environment: Amazon Linux 2023, AArch64, kernel 6.12.111-136.204.amzn2023.aarch64, Rust 1.98.1, non-root execution. CARGO_TARGET_DIR named a fresh absolute canonical directory.

The initial build used ../target, which embedded a parent component in probe paths and caused three child_ipc failures. A fresh canonical build directory corrected that test setup. No source changes were needed.

Please reassess the outstanding #157 coordination note using these results. This verifies the containment interaction at the listed heads. It does not claim a combined full-workspace run, deployment qualification, or maintainer approval. Neither PR was pushed or merged.

@github-actions

Copy link
Copy Markdown

Re-checked at c1c0300 — no code changes since my last pass. The only new item is the #157 compatibility evidence.

That addresses the last coordination note I'd been tracking: merging #157 (e061220) with #159 (c1c0300) applied cleanly (no conflicts, order-independent), and the combined tree passed the full containment suite --all-features --test-threads=1 with 532 tests and zero failures/skips — including the refusal-replacement and concurrent-exchange regressions this PR adds. The child_ipc failures you noted were a CARGO_TARGET_DIR path artifact, not a source issue, so no concern there.

From my side there are now no blocking items and no open coordination concerns. The remaining caveats are the ones you've already documented (no combined full-workspace run, no Runtime/Lambda/release qualification, finite replacement trials) plus maintainer sign-off — all outside what I can clear in review. Assessment stays Comment.

@kevin-orellana
kevin-orellana merged commit 33469c7 into main Oct 27, 2026
21 checks passed
@kevin-orellana
kevin-orellana deleted the feature/linux-refusal-mount-targets branch October 27, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linux Linux containment and Linux launch work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants