Skip to content

fix: block proc mem executable page writes - #241

Merged
kevin-orellana merged 2 commits into
mainfrom
feature/linux-proc-mem-exec-protection
Nov 2, 2026
Merged

kevin-orellana merged 2 commits into
mainfrom
feature/linux-proc-mem-exec-protection

Conversation

@kevin-orellana

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

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. A Linux workload inside Box could change memory containing executable code through /proc, Linux's filesystem for process information and controls. This bypassed Box's existing restrictions on system calls that change executable memory.

Solution. Box now mounts the workload's /proc filesystem read-only. The workload can still read permitted process information, but it cannot open process-memory files for writing.

Trade-off. This also blocks writes to other /proc controls. Programs cannot write the files used to assign user and group identities inside nested namespaces. These are isolated environments created within the workload. Box still permits namespace creation, but this change limits how programs can configure those environments.

Description

Linux previously mounted the workload's /proc filesystem as writable. A workload could open /proc/*/mem for writing and change an executable memory page.

The regression test applies containment, the restrictions Box places on a workload. It then attempts to change a memory page that permits reading and execution but not writing. It checks these process-memory routes:

  • /proc/self/mem
  • /proc/thread-self/mem
  • /proc/<pid>/mem
  • /proc/self/task/<tid>/mem
  • /proc/self/root/proc/self/mem
  • /proc/self/fd/<fd> for a read-only /proc/self/mem descriptor
  • a child process route

In these paths, <pid> means process ID, <tid> means thread ID, and <fd> means an open file descriptor number. A file descriptor is a handle a process uses to access an open file or communication channel.

The file-descriptor case first opens the process-memory file for reading. It then tries to reopen that same file for writing through /proc/self/fd/<fd>. The test requires the initial read-only open to succeed, so a setup failure cannot count as successful protection. The test also checks a direct memory assignment and a plain writable anonymous mapping, which allocates memory without a backing file.

This change preserves the existing executable-memory restriction. It does not add support for just-in-time code generation, where a program creates executable code while running. It does not establish isolation of the supervisor, the Box process that manages the workload, or validate cloud deployment targets.

Related Issues

Related security finding: Robosec finding

Related compatibility discussion: Issue #42

Type of Change

Bug fix

Testing

Hosted checks at c5641a0. GitHub's CI Gate passed. This continuous integration result is separate from the local evidence below. It does not establish complete test coverage or human approval.

Local test evidence

The local test revision is not recorded in this description. These results report tests on 64-bit Arm (ARM64) Linux, kernel 6.12.113-138.209.amzn2023.aarch64. Build and test concurrency were limited to two jobs.

Check Result Evidence
cargo build -p strands-box-containment --all-features Passed Package built successfully.
cargo test -p strands-box-containment --all-features --no-fail-fast -- --nocapture Passed Includes inherited-handle, child-IPC (interprocess communication), lifecycle, and profile tests. No skip messages were observed; this does not establish execution of every host-dependent case.
cargo clippy -p strands-box-containment --all-targets --all-features Passed No warnings appeared.
cargo fmt -p strands-box-containment --check Passed Formatting is unchanged.
git diff --check Passed No whitespace errors.
cargo build -p strands-box-containment --no-default-features Passed Retains the existing 66 unused macOS-symbol warnings.
bash scripts/test-all.sh box-examples Build passed; examples skipped No scripted examples exist on this branch.
EXPERIMENTAL_LINUX_SUPPORT=TRUE bash test-integ/run.sh Passed 124 cases passed; nine declared macOS-only cases skipped. No failures, errors, or quarantine.
Focused proc-memory regression Passed The contained route test ran without skipping.
Descriptor route alone, read-only /proc Passed Isolated the descriptor route from the other process-memory routes.
Descriptor route alone, writable /proc mutation Failed as expected Exit status 61 demonstrates that this route can write the executable page in this test when protection is removed.
Initial descriptor-open failure mutation Failed as expected Exit status 64 prevents a setup failure from counting as protection.

The two mutation checks deliberately removed a protection or broke setup and confirmed that the test failed. Both temporary mutations were restored before the full package gates ran. The integration run used the freshly built Box binaries. An initial run stopped at the Linux opt-in check; the corrected run used the setting from continuous integration. These checks cover the Linux host. Full workspace, native macOS, Runtime, Lambda MicroVM, and cloud qualification tests were not run locally for this follow-up.

Checklist

  • I have read the repository guidance and applicable containment instructions.
  • I have reviewed and understand every line of code in this PR, including generated code.
  • My change is focused and reasonably small.
  • Tests prove the fix is effective, including a failing check when protection is removed.
  • The Linux enforcement guide states the read-only /proc restriction and its nested identity-mapping limitation.
  • 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 mounted workload procfs writable. A workload could open /proc/*/mem and write to an executable page. That bypassed the executable-memory syscall filter.

## Solution

Mount workload procfs read-only. Add a Linux regression that tries each reachable /proc/*/mem route against a read-execute page. The test keeps direct memory writes and plain writable mappings as controls.

## Tests

cargo fmt --check passed.
git diff --check passed.
cargo test -p strands-box-containment passed.
cargo clippy -p strands-box-containment --all-targets exited 0 with existing macOS unused-code warnings.
The mutation that made /proc writable again failed proc_mem_cannot_write_executable_memory with code 61.
@kevin-orellana kevin-orellana changed the title Block proc mem executable page writes fix: block proc mem executable page writes Oct 30, 2026
@kevin-orellana
kevin-orellana enabled auto-merge (squash) October 30, 2026 18:30
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

This review covers head 1eafafb. The read-only /proc mount does close the /proc/*/mem route, and I confirmed it. But it also blocks every write to procfs's own files, including the nested user-namespace mapping that crates/containment/AGENTS.md and test code 28 say the workload keeps. Record that cost as a decision, and pin it with a test.

Checks that held
  • Every /proc/*/mem route in the test, plus reopening an O_RDONLY mem descriptor through /proc/self/fd/N with O_RDWR, returns EROFS on a read-only fresh procfs.
  • /dev/stdout and /proc/self/fd/1 writes still work, because the magic link resolves to the target's mount.
  • The workload cannot make /proc writable again: seccomp denies mount, mount_setattr, and the fs*/open_tree/move_mount calls.
  • The same bypass through other calls stays closed: seccomp denies ptrace and process_vm_writev.
  • Host procfs cannot reach the view as a grant, because floors.rs refuses /proc.
  • Nothing that runs after the view is built writes to /proc. The trusted side writes uid_map/setgroups before the view exists.
  • CI does not skip the new test: containment-deterministic.yml clears the AppArmor userns restriction.

The fix is small and targeted, and the mutation check against a writable /proc is good evidence.

@github-actions

Copy link
Copy Markdown

Assessment: Approve

This re-review covers head c5641a0; the earlier review was on 1eafafb. The blocking item is resolved: the PR description and docs/design/linux-enforcement.md now record that a read-only /proc blocks the identity maps of nested user namespaces. The descriptor route now reaches its writable reopen.

Checks that held
  • I ran proc_mem_cannot_write_executable_memory locally with the AppArmor userns restriction cleared. It passed and did not skip. With writable: true restored on /proc, it failed with code 61.
  • The fd route's first O_RDONLY open of /proc/self/mem succeeds inside the view, so code 64 cannot hide a real refusal.
  • The new docs sentence is accurate. The workload cannot mount a fresh procfs for a nested namespace, because seccomp denies the mount API.
  • Namespace module tests: 262 passed and 1 failed. The failure is allow_all_joins_the_host_network…, code 41, host loopback unreachable. It also fails with the view change reverted, so it is unrelated to this PR.

The fix is small and well pinned.

@kevin-orellana
kevin-orellana merged commit b25725d into main Nov 2, 2026
23 checks passed
@kevin-orellana
kevin-orellana deleted the feature/linux-proc-mem-exec-protection branch November 2, 2026 14:19
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