Skip to content

fix(containment): retain Linux bind mount targets - #254

Merged
kevin-orellana merged 3 commits into
mainfrom
feature/linux-bind-mount-targets
Nov 2, 2026
Merged

kevin-orellana merged 3 commits into
mainfrom
feature/linux-bind-mount-targets

Conversation

@kevin-orellana

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

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Linux mount setup can use a changed path after validating a filesystem grant. A nested target can then reach an unintended location. nested_directory_targets_do_not_create_outside_after_source_pinning and nested_file_targets_do_not_mount_outside_after_source_pinning cover the reported directory and file cases.

Solution: Retain open references while preparing and attaching bind mounts. Refuse missing targets inside exposed host trees. Resolve permitted aliases inside the staged filesystem. Apply permissions through the retained mount, then check its flags and placement.

Trade-off: Setup refuses when a nested target disappears or the final placement check cannot confirm the same mount. missing_nested_targets_are_not_recreated and the remount_flags tests pin these refusals. Legitimate nested grants remain usable, as checked by legitimate_nested_directory_and_file_grants_remain_usable.

Description

The repair extends the existing mount-target mechanism behind the current filesystem grant contract. It changes no public interface or policy authority.

Enclosing mounts precede descendants, and canonical source mounts precede aliases that depend on them. An alias reuses its canonical mount when object identity and access flags match. a_read_only_directory_alias_preserves_the_canonical_write_grant checks permission preservation. an_alias_bind_does_not_replace_nested_metadata_mounts checks mount ordering.

Alias traversal remains bounded and follows normal filesystem ordering inside the staged root. directory_alias_resolves_a_link_before_its_parent_component checks link resolution before a parent component. absolute_file_alias_remains_writable_inside_the_view checks absolute aliases. an_authored_alias_replaced_with_a_loop_refuses_startup checks refusal.

Write-protected files also use permitted aliases. a_protected_file_under_an_earlier_writable_directory_alias_remains_read_only and its later-alias counterpart cover both orders. Additional protection_alias cases cover a linked read tree, a file alias, missing targets, loops, and replaced object identity. Protection targets are never created.

A protection alias must stay at the verified location of the writable grant that produced it, plus the protected file's canonical relative path. Recording the actual grant location preserves an alias within a separately bound read tree. A check against only the authored target or canonical source would reject that supported composition. an_independent_writable_directory_alias_keeps_its_protection_and_sibling_write checks a separate alias bind. The relative and absolute descendant-redirect tests require the new location refusal before mounting protection.

Permission remounts retain the newly attached mount reference. A separate pathname identifies descendant mounts for recursive permission changes. Final checks verify the retained mount's flags, identity, and placement. Eight remount_flags tests cover file and directory grants across four write/execute combinations, each with unchanged and replaced-ancestor controls. a_submount_under_a_read_only_grant_is_also_read_only checks a retained top reference with a real nested mount.

Codex assisted with implementation, tests, documentation, and review.

Related Issues

Related: #159, #160.

Type of Change

Bug fix

Testing

Review status: All three hosted findings have follow-up corrections. Final independent adversarial review found no remaining concrete source defect. Local validation passed for a3b14f59b0ed036f2c1ce7f1efd05a96f5bf274b. The renewed hosted assessment reports "Approve" with no new findings on this head. The required hosted check and all applicable test jobs passed. This pull request is ready for human review. Formal human approval remains required.

Local validation ran on native Amazon Linux 2023, AArch64, with Rust and Cargo 1.98.1. The frozen six-file source manifest matches a3b14f59b0ed036f2c1ce7f1efd05a96f5bf274b, whose parent is 73ce032a5cb569a4b399ad130bcf44da788a5aca.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and the workspace Clippy command prescribed by just clippy, including its documented allowances.

CONTRIBUTING requires the lint allowances in justfile. The exact workspace recipe passed. A previous separate run without allowances failed on six existing vendored Shell diagnostics.

Check Result and scope
Focused mount-view library tests 179 passed; zero failures or ignored tests; 260 filtered. Uncaptured output contained no explicit skips.
EXPERIMENTAL_LINUX_SUPPORT=TRUE cargo test --workspace --all-features Exit 0; 4,637 passed; zero failures; 17 reported ignored entries across 140 result groups. Containment library: 439 passed, zero ignored.
Formatting and workspace Clippy Passed. Allowances: too_many_arguments, only_used_in_recursion, await_holding_refcell_ref, explicit_auto_deref, chunks_exact_to_as_chunks, dead_code, non_snake_case.
Product and containment build cargo build -p strands-box -p strands-box-containment --all-features: exit 0.
Separate integration suite bash test-integ/run.sh: GREEN; 124 passed; zero failures or errors; nine declared macOS-only skips. Debug product binaries and release test harness.
No-default-feature build and compiler check Exit 0. All 66 unused-code warnings match saved upstream e4ca8b8 diagnostics by code, message, and primary source file. Zero added or removed warnings. No baseline test or workload ran.
Hosted Linux and macOS integration Both jobs passed. Linux: 124 passed and nine macOS-only skips. macOS: 121 passed and 12 Linux-only skips. Each artifact contains 133 unique records, with no failures, errors, or integrity problems.
Hosted workspace, lint, packaging, native macOS, and security analysis CI passed, including the required CI Gate. The actual workspace test steps passed: Linux 4,643 passes and 17 ignored; macOS 4,362 passes and 16 ignored. Counts exclude captured helper-process summaries. CodeQL passed.
Final adversarial review Independent review found no remaining concrete source finding; all six frozen source hashes verified. The renewed hosted assessment reports no new findings.

Evidence limits:

  • Earlier independent reviews missed two protection-alias compositions. Hosted feedback led to the alias compatibility fix, retained remount permissions, and protection-location enforcement.
  • Integration verdicts have a raw commit field of unknown. The local driver records the source manifest and selected product hash. Hosted checkout logs identify merge baccc7cc08a880a39772a17cb596bd7bc25640be, combining main e4ca8b8 with this head. Hosted logs confirm the release product path; the macOS artifact retains no product hash or binary bytes.
  • Saved baseline logs record failures for the two original cases. Their saved instrumentation patch omits the original untracked test body, so those artifacts cannot reconstruct the complete harness.
  • Fresh baseline regression runs and protection-removal tests were not completed. Final patched-code tests passed; fresh mutation sensitivity was not measured.
  • The simple descendant-to-decoy schedule can also fail the existing protected-source identity check. The new tests establish earlier location refusal, not a reproduced prior end-to-end bypass.
  • Descendant enumeration and remounts still use mount-table pathnames. This repair does not establish protection against every concurrent descendant change.
  • Outside snapshots cover paths, modes, contents, and link text. They do not cover every timestamp, owner, extended attribute, or inode identity. Descriptor-count checks cover 22 general fixtures, not every alias fixture.
  • Successful captured workspace output can hide tests that return early. The no-skip statement applies only to the focused uncaptured run. Hosted Linux uses uncaptured success output and a skip checker; it permits a missing real credential-daemon fixture and omission of the known executable-alias read assertion. Write assertions still ran. The macOS test step succeeded, despite the workflow allowing test failure; its captured output cannot establish that every prerequisite ran.
  • The scripted-example runner found no runnable examples; the live SDK tutorial was not run.
  • No local native macOS, Linux x86_64, cloud, or release qualification was performed. The hosted reviewer could not run namespace tests on its runner. Formal human approval remains separate from these completed checks.

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
  • My changes generate no new warnings

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 mount setup can follow a changed path after source validation.
The saved baseline fails nested_directory_targets_do_not_create_outside_after_source_pinning
and nested_file_targets_do_not_mount_outside_after_source_pinning.

## Solution

Retain mount targets through preparation, attachment, and placement checks.
Refuse missing targets below exposed host trees, as checked by
missing_nested_targets_are_not_recreated.
Resolve permitted aliases inside the staged root. The test
absolute_file_alias_remains_writable_inside_the_view checks this behavior.
Preserve canonical permissions and dependent mount ordering, as checked by
a_read_only_directory_alias_preserves_the_canonical_write_grant and
an_alias_bind_does_not_replace_nested_metadata_mounts.
No public interface or policy authority changes.

## Tests

The focused nested_grants suite passed 30 tests across 39 fixture cases.
Its uncaptured output contains no explicit skips.
The workspace suite passed with EXPERIMENTAL_LINUX_SUPPORT=TRUE; 17 tests were ignored.
Containment builds passed with all features and without default features.
Formatting and workspace Clippy passed with the repository's justfile allowances.
The build without default features emitted 66 warnings, without a baseline comparison.
The separate deterministic suite was GREEN: 124 passed, zero failures or errors,
and nine declared macOS-only skips. It used debug product binaries.
No scripted examples remain. The live SDK tutorial was not run.
Saved baseline logs show the reported failures, but the original test body is absent
from the saved baseline patch. Fresh baseline and protection-removal checks were
not completed.
Recursive remounts still resolve pathnames. The tests do not cover every race
after mount-placement verification or every outside metadata field.
Native validation covers Linux AArch64 only. Hosted checks remain separate.
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Assessment: Request Changes

The descriptor-retaining walk closes the two reported nested-target cases. One result changes for a configuration that used to run: a write protection under a skipped writable alias now refuses startup (see the inline comment). The remaining flag-remount window fails open, and the PR already holds a descriptor that would close it.

Review details
  • Correctness: A protection entry is the one bind origin that does not resolve aliases. Because the alias bind can now be skipped, its staged spelling stays a symlink. I proved this with a plan + establish run at both d74f5dd and this head. I could not run namespace tests on this x86_64 runner, because user namespaces are blocked here.
  • Security residual: remount_* resolves location() after require_new_mount. If a redirect succeeds, the bind keeps its inherited rw/exec flags.
  • Tests: No fixture combines protect_write with an alias. No hook sits between placement verification and the remount.

Checked and held:

  • order_mounts: a min-index Kahn sort keeps the depth order when the only edges are parent edges. Canonical edges only delay aliases. A cycle cannot form from fully resolved sources.
  • Refusal and protection entries are appended after order_mounts, so "a refusal outranks" keeps its order.
  • The runtime minimum on merged-usr (/lib→usr/lib, /lib64): the staging root has no link, so location == target. The behavior is the same as before.
  • An exec alias inside a bound tree with a covering canonical entry is skipped, as before. A dependency alias without a canonical entry is now bound executable at its resolved location.
  • A missing component is refused under any planned bind except the pending one. Ancestors are always ordered first, so only a race reaches this path.
  • An alias walk stays within the staging root: absolute links rebase to the root, .. pops retained descriptors, and the walk stops after 40 links.
  • No frozen surface or pub use changed, which matches crates/containment/AGENTS.md: "A defect fix behind the current shape needs none."

The test hooks around source pin, target open, and mount make the race claims checkable.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 1, 2026 07:45
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review of 73ce032)

Both findings from the previous review are fixed:

  • Protection under a skipped alias: it now resolves through the staged link, and protection_alias.rs pins both orders.
  • Fail-open remount: the top mount is remounted through the retained descriptor. The flags are then verified with fstatvfs, and require_same_mount repeats the placement check. remount_flags.rs covers all four write/exec pairs with a swap after verification.

One new gap remains, in the inline comment: alias-spelled protections accept any link redirect.

Checked and held at this head
  • require_mount_flags computes the same bit set that each remount_* constant requests, including the device-node exception for writable, non-exec devices.
  • The top mount is remounted last, after the submounts (deepest first). The shadowed-EINVAL exemption no longer applies to the retained top mount.
  • In the retained_permissions swap case, the canonical entry refuses and the retained mount keeps the granted flags.
  • Protection entries still never create targets (create = None), and loops still refuse.
  • The design doc records the remaining residual: submount enumeration uses pathnames.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review of a3b14f5; no new findings)

The protection-redirect finding from 73ce032 is fixed. A protection reached through an alias must now land at the verified location of the writable grant that produced it, plus the protected file's relative path. I re-ran my earlier probe without privilege:

  • unchanged tree: proj-link/sub/policy → Ok at the expected staged location;
  • sub swapped for sub -> decoy: refused with "resolved to an unexpected location". The canonical spelling still refuses with ENOTDIR.
Checked and held at this head
  • Skipped alias inside a bound tree: the reuse branch records its resolved (canonical) location, so a protection reached through the staged link matches it.
  • Separately mounted alias: the normal branch records the location after require_same_mount. The new tests cover redirects to relative and absolute descendants, and a sibling write stays permitted.
  • File alias: the suffix is empty, and Path equality compares by component, so target.join("") still matches.
  • Missing producer location: if no location was recorded for the grant, any() is false and startup refuses. That is fail-closed.
  • Ordering: protections are appended after order_mounts, so the grant that produces a protection is always established first. materialize clears mount_locations before each run.
  • Placement re-check: require_same_mount re-checks against the location that was already validated, so a redirect after preparation still fails the landed check.
  • Tightening: regular_file is now set for protections, so a protection whose final path component is a symlink is no longer accepted as a mountpoint.

Human approval and the hosted checks are still required. I could not run the namespace tests on this runner.

@kevin-orellana
kevin-orellana merged commit 5ba7010 into main Nov 2, 2026
25 checks passed
@kevin-orellana
kevin-orellana deleted the feature/linux-bind-mount-targets branch November 2, 2026 22:05
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