Repository navigation
fix: harden Linux namespace supervisor memory - #243
Conversation
## Problem The Linux namespace workload could open namespace PID 1 memory through procfs when host tracing policy was permissive. That kept the supervisor reachable from the contained workload. ## Solution Namespace PID 1 now sets `PR_SET_DUMPABLE` to `0` before it forks the workload. If the kernel refuses that lock, PID 1 exits before it starts the workload. The Linux probe binary now has a supervisor-memory check, and a new trampoline integration test proves the workload receives `EACCES` for `/proc/1/mem`. ## Tests - `cargo test -p strands-box-containment --all-features` - `cargo fmt -p strands-box-containment --check` - `cargo clippy -p strands-box-containment --all-targets --all-features` - `cargo check -p strands-box-containment --all-features --target aarch64-unknown-linux-gnu --lib --bins` - Docker Linux: `cargo test -p strands-box-containment --all-features --test supervisor_memory_linux -- --nocapture` - Docker Linux: `cargo test -p strands-box-containment --all-features failed_non_dumpable_refuses_launch -- --nocapture` - Docker Linux: `cargo test -p strands-box-containment --all-features a_reaper_that_remains_dumpable_terminates_its_namespace -- --nocapture` - Docker Linux: `cargo clippy -p strands-box-containment --all-targets --all-features` - `git diff --check` Baseline evidence from the remote Linux run showed the workload opened `/proc/1/mem`. The patched Docker Linux run returned `SUPERVISOR_MEMORY_DENIED`.
|
Assessment: Comment This review covers head Review Categories
Checked and held:
|
|
Automated review follow-up is in
Focused |
|
Assessment: Request Changes This review covers head Review Categories
Checked and held:
|
|
Automated review follow-up for the setup-status blocker is in
|
|
Assessment: Approve This review covers head A correction to my last review: I wrote that every reaper test passes Checked and held:
|
|
Assessment: Approve (one non-blocking comment) This review covers head Checked and held:
|
|
Assessment: Approve This review covers head Checked and held:
|
|
Assessment: Approve (one non-blocking comment) This review covers head Checked and held:
|
|
Assessment: Approve This review covers head Checked and held:
|
|
Assessment: Approve This review covers head Checked and held:
I could not run these tests on this host. Unprivileged user namespaces are blocked here ( |
Human readable section
Problem. On some Linux hosts, a workload inside Box could open a file exposing the memory of the Box process that manages it. This process is the namespace reaper, which collects child exit statuses. The file,
/proc/1/mem, identifies its memory from inside the workload's process environment. Access depended on the host allowing memory inspection between processes owned by the same user.Solution. Before starting the workload, Box applies a Linux setting that restricts access to the reaper's memory. If setup fails, Box reports failure and does not start the workload. The regression test checks that the workload cannot open
/proc/1/mem.Trade-off. This change protects the reported memory-access route and keeps the existing namespace reaper design. It does not add restrictions on which system calls the reaper can make.
Description
The namespace reaper has process ID 1 inside the workload's process namespace, which gives processes their own view of process IDs. It collects the exit status of child processes.
Before starting the workload, the reaper closes unnecessary file descriptors, which are handles for open files and communication channels. It then sets
PR_SET_DUMPABLE=0, the Linux setting used here to restrict memory inspection. Box reports successful setup only after both steps succeed. If either step fails, process ID 1 exits without starting the workload.The reaper must retain the pipe writer used to report setup status until it sends that status. It sends the success byte and closes the writer before creating the workload process. A regression test uses a real setup-status pipe and checks that the workload does not inherit its writer.
The Linux probe requires a read-only open of reaper memory to fail with
EACCES, meaning permission denied. It separately attempts a read-write open. That open must fail with either permission denial orEROFS, meaning a read-only filesystem. This lets the test work with the read-only process filesystem in PR #241 without treating that mount alone as reaper isolation.For a non-root launcher, the probe also checks that reaper memory no longer has the workload's owner. This prevents Yama, a Linux restriction on process tracing, from hiding a missing reaper protection. The harness passes the original host user identity because both processes map to user ID zero inside containment. Root launches still require read denial, but ownership can remain unchanged. For root, the harness first verifies host
ptrace_scope=0; otherwise it prints a skip. A separate test checks that decision for permissive, restrictive, empty, and unavailable settings.The test stages its executable under the launch identity and runs on supported ARM64 Linux. It retains a successful self-memory read as its permitted control. Two additional tests exercise failure to apply the
PR_SET_DUMPABLEsetting.These checks cover the reported reaper-memory route. The change does not add a seccomp filter, which restricts the system calls a process can make, to the reaper.
The design guide now explains the reaper memory guard, startup refusal, and its distinction from a read-only process filesystem. It also states that the reaper remains outside the workload's seccomp filters.
Related Issues
Related to the Linux supervisor-isolation security finding. No public GitHub issue.
Type of Change
Testing
Merge follow-up at
030d7291763361a1d3ebc9be2797097e72c8c2fa. PR #241 has merged intomain. This follow-up merges that revision and retains both memory-protection explanations in the design guide. The production reaper code is unchanged from the human-approved30ae3cd.The old PR #241 unit test inherited the reaper's memory-inspection setting before executable launch. Its permitted self-memory read then failed with exit code 64. The test now runs after executable launch, as the saved integration candidate already did. It retains all seven denied access routes and the successful self-read, direct-write, and writable-mapping controls. The supervisor test alone retains the root Yama prerequisite. No PR #248 setup-writer change is included.
Validation on native ARM64 Amazon Linux 2023, Rust 1.98.1, with
EXPERIMENTAL_LINUX_SUPPORT=TRUE:git diff --checkpassed.The tested source tree matches this commit. The CI Gate at
030d729passed, including Linux and macOS workspace and deterministic suites. The hosted Linux memory target reported three passes, zero failures, and no skips. All CodeQL language analyses passed. The automated review at030d729assessed this revision as Approve with no new findings. All four review discussions are resolved. That reviewer could not execute namespace tests on its host; the runtime evidence above remains separate.GitHub dismissed the earlier human approval when this merge follow-up was pushed. Renewed human approval remains required. Protected auto-merge remains enabled.
Documentation follow-up at
30ae3cdaea56c3141370dfdcd2c67a7ec4b11079. This follow-up adds the design explanation only. No Rust source, manifests, or tests changed from9fb885705da278c6eb65e89557c49e5e57a35132. Source inspection, the repository prose checker,git diff --check, and all 13 relative links and anchors passed. Runtime suites were not repeated locally for this documentation delta. GitHub reruns the runtime suites selected from the complete PR diff. Independent source and prose review passed. The guide uses the defined namespace reaper terminology and keeps test names in review evidence. The automated review at30ae3cdassessed this head as Approve with no new findings. The CI Gate at30ae3cdpassed, including Linux and macOS workspace and deterministic suites. All CodeQL language analysis jobs also passed at this head. These results do not establish complete coverage or formal maintainer approval.The automated review at
d0027f6approved the behavior explanation with one nonblocking terminology comment.30ae3cdcorrects that wording. The supporting regressions areworkload_cannot_write_namespace_supervisor_memoryanda_reaper_that_remains_dumpable_terminates_its_namespace; the guide omits their names under its writing rules.Previous test-only follow-up:
9fb885705da278c6eb65e89557c49e5e57a35132. The follow-up changes only the regression tests and their documentation. Independent source review found no remaining issues. The complete local workspace suite passed: 4,587 passed, zero failed, and 17 declared ignored tests. The hosted checks at9fb8857passed, including Linux and macOS workspace and deterministic suites. Human approval remains required.All hosted checks at the previous head
b50a5cepassed. That result does not attest later revisions.Test evidence at
9fb8857On native ARM64 Amazon Linux 2023, Rust 1.98.1, with
EXPERIMENTAL_LINUX_SUPPORT=TRUEand hostkernel.yama.ptrace_scope=0:cargo test --workspace --all-features --no-fail-fast -- --nocapturepassed.cargo fmt --all --check, repository-configured workspace Clippy, the Box and containment build, andgit diff --checkpassed.strands-box runcommand.Integration with PR #241 and PR #248
I tested a combined candidate using PR #241 at
c5641a0, PR #248 atd806fc2, and the supervisor changes throughb50a5ce. The final9fb8857follow-up changes only root test prerequisites and documentation, not production code. The combined candidate's measured root runs already used verified Yama zero. Its merge resolution keeps the workload setup writer until executable launch, as PR #248 requires. Do not restore this standalone branch's early writer closure when combining them.Retain the final root prerequisite in the combined supervisor test without skipping the separate executable-memory test.
The PR #241 process-memory test needed to run after executable launch, rather than inherit the supervisor's non-dumpable state. The tested integration resolution moves all seven access routes into the executed probe and retains successful memory-access controls. The merge follow-up now includes that test migration. PR #248's separate setup-writer change remains outside this PR.
Both memory probes passed as ordinary user, root, and through the full Box command. Deliberately removing each memory safeguard failed its corresponding test. Closing the setup writer early failed 10 of 12 setup tests. All faults were restored before final validation. The deterministic containment suite passed 124 cases, with nine declared macOS-only skips.
Complete integration rerun: The complete combined workspace suite passed with 4,616 passes, zero failures, and 17 declared ignored tests. It used the original command and four-test-thread setting, unchanged source, and unchanged test binaries. The previously failing policy-latency test passed. Four runtime skip-message lines remain separate from declared ignored tests. The run took 1,141 seconds.
Historical limitation: The earlier combined workspace run had 4,615 passes, one policy-latency failure, and 17 declared ignored tests. Its affected target passed all 18 tests in both focused retries. The complete rerun above now supplies a clean full-suite result. The earlier failure's cause remains unestablished; no threshold or policy code changed, and that failed run remains preserved.
Cargo rebuilt product executables during the complete rerun. Both product-executable sets are preserved, and the earlier set was restored for the frozen deterministic and full-command evidence. The rerun does not claim new deterministic or full-command coverage of its rebuilt product executables.
Previous hosted checks at
be5ab39. GitHub's CI Gate passed. This continuous integration result is historical. It does not establish complete test coverage or human approval.Local test evidence
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
The earlier workspace checks below identify revision
be5ab39. They remain historical evidence. Other runs retain their original timing labels. The Linux development desktop is identified asdd.just check, orcargo test --workspace --all-features)9fb8857, the complete workspace suite passed with all features and no fail-fast. The tested source hashes match the committed tree.ddhost did not havejust, so I ran the Rust gate steps directly from the PR-head worktree.ddLinux passedcargo fmt --all --checkatbe5ab39with Rust 1.98.1.ddLinux passed repo-equivalentcargo clippy --workspace --all-targets --all-features -- -D warningswith the repo vendored-lint allowances atbe5ab39with Rust 1.98.1.ddLinux passedEXPERIMENTAL_LINUX_SUPPORT=TRUE cargo test --workspace --all-featuresatbe5ab39with Rust 1.98.1.cargo test -p strands-box-containment --all-featurespassed on macOS before the review follow-up.cargo test -p strands-box-containment --all-features --test supervisor_memory_linux -- --nocapturebefore the review follow-up.cargo test -p strands-box-containment --all-features failed_non_dumpable_refuses_launch -- --nocapturebefore the review follow-up.cargo test -p strands-box-containment --all-features a_reaper_that_remains_dumpable_terminates_its_namespace -- --nocapturebefore the review follow-up.cargo check -p strands-box-containment --all-features --target aarch64-unknown-linux-gnu --lib --binspassed locally before the review follow-up.ddLinux passedcargo test -p strands-box-containment --all-features --test supervisor_memory_linux -- --nocaptureafter the first review follow-up.ddLinux passedcargo test -p strands-box-containment --all-features failed_non_dumpable_refuses_launch -- --nocaptureafter the first review follow-up.ddLinux passedcargo test -p strands-box-containment --all-features a_reaper_that_remains_dumpable_terminates_its_namespace -- --nocaptureafter the first review follow-up.ddLinux passedcargo test -p strands-box-containment --all-features the_reaper_closes_the_exec_confirm_writer_before_the_workload_runs -- --nocaptureafter the setup-status fix.ddLinux passedcargo test -p strands-box-containment --all-features the_reaper_writes_the_exec_confirm_byte_and_a_failure_byte -- --nocaptureafter the setup-status fix.ddLinux passedcargo test -p strands-box-containment --all-features --test supervisor_memory_linux -- --nocaptureafter the setup-status fix.ddLinux passedcargo test -p strands-box-containment --all-features failed_non_dumpable_refuses_launch -- --nocaptureafter the setup-status fix.ddLinux passedcargo test -p strands-box-containment --all-features a_reaper_that_remains_dumpable_terminates_its_namespace -- --nocaptureafter the setup-status fix.ddLinux passedcargo test -p strands-box-containment --all-featuresafter the setup-status fix.cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warnings9fb8857. Formatting and configured Clippy passed. Bare strict Clippy still reports the same six existing bundled-shell diagnostics.ddLinux atbe5ab39with Rust 1.98.1. Formatting passed without source changes.crates/shellcode. This checkbox records execution, not a bare strict-Clippy pass.just clippy. CONTRIBUTING.md requires those allowances for bundled shell code.clippy::too_many_arguments,clippy::only_used_in_recursion,clippy::await_holding_refcell_ref,clippy::explicit_auto_deref,clippy::chunks_exact_to_as_chunks,dead_code, andnon_snake_case.git diff --checkpassed.Review evidence and limits
The automated review at
9fb8857assessed9fb8857as Approve with no new findings. All three review conversations are resolved. This assessment is not human approval.The hosted review at
b50a5ceapproved it with one nonblocking root-prerequisite concern.9fb8857fixes that concern and updates the guard documentation.Independent source review rechecked the final three-file correction and found no remaining issues. The owner ran the complete workspace suite and ordinary-user, root, and full-command checks.
The previous automated adversarial review assessed
be5ab39as Approve. The reviewer removed each status-writer safeguard and confirmed that the regression tests failed.The automated reviewer confirmed the earlier setup-status blocker was fixed. Its separate host-network test failure persisted with the memory fix disabled.
The standalone full workspace suite passed on
ddat both documented revisions. The combined candidate's complete rerun also passed; the earlier timing failure remains preserved as stated above.GitHub's required CI Gate passed at test-only head
9fb8857, as linked above. Automated assessment does not replace required human approval.Checklist
Codex added and reviewed the documentation explanation at Kevin's request. The existing runtime evidence retains its original revisions and limits. Formal 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.