Repository navigation
fix(linux): sanitize statfs for Codex database startup - #356
Conversation
## Problem Codex probes its data directory's filesystem before opening SQLite. The Linux syscall allowlist denies statfs, so Codex reports a damaged database and exits even with a fresh writable directory. ## Solution Permit statfs and update the allowlist census. Add a production-launcher regression that compares filesystem types and preserves hidden-file and read-only-file restrictions. Document filesystem-wide metadata exposure. ## Tests The focused regression failed with EPERM when statfs was removed and passed with the change. Exact Codex 0.167.0.932 reached its interactive prompt on fresh startup and restart; all five databases passed integrity checks both times. Formatting, workspace build, Clippy with repository allowances, the full workspace/examples suite, the no-default-features build, and the x86_64 library compile check passed. The deterministic containment suite passed 131 cases, with 10 declared macOS exclusions and no failures or errors. No-default build warnings matched the clean base. Existing ignored tests and unavailable daemon/alias checks remain; native macOS and model-backed coding workflows were not tested locally.
|
Assessment: Comment The mediation looks careful: path resolution stays confined, buffers are written with Assumptions and rules checked that held
The new tests check that every non-approved byte is zero, which is a strong guard against leaks. |
abhisheksp
left a comment
There was a problem hiding this comment.
This is definitely very involved. We should do a follow up security posture exercise
Merge review and remaining follow-upsThe approved revision is An independent review rechecked the three automated findings against the source and existing defect-detection evidence. All six changed Rust files still match the tested implementation. No production-code change is required to address these nonblocking comments before merging this approved revision.
The two documentation items remain follow-up work for this PR. Abhishek's requested security-posture exercise also remains outstanding; its scope and owner still need assignment. Merging does not complete that assessment. The approved source is unchanged. Resolving the three threads records these nonblocking dispositions and preserves their limitations and follow-ups above. This merge check reused existing test and mutation evidence; it did not rerun the package suites or the third-party dataset example. |
Pull Request is not mergeable
`permit_filter_has_112_workload_entries_and_one_installer_entry` asserts `WORKLOAD_PERMITTED.len() == 112`, but the table holds 113: main's strands-agents#356 ("sanitize statfs for Codex database startup") added the `statfs` entry without bumping the count. The entry is not `cfg`-gated, so the assertion fails `left: 113, right: 112` on aarch64 Linux under `--all-features` on main itself, and this branch inherits it by merging main. This PR is an AWS-credentials change and does not touch containment. The test is commented out, not corrected in place, because the right count belongs to the containment owner; the test author was notified to restore it with the correct number and to re-check the companion `rules.len()` assertion. ## Tests No behaviour change; the commented-out test is the only edit. The containment crate builds, and `cargo fmt --check` is clean.
…ing it Addresses the PR strands-agents#342 re-review of c424b83. Commenting the test out dropped four still-correct seccomp guards (`seccomp`/`pkey_mprotect` must stay out of `WORKLOAD_PERMITTED`, and `setresuid`/ `setresgid` keep one argument-scoped rule each). The real fix is two numbers: main's strands-agents#356 added the `statfs` entry, so `WORKLOAD_PERMITTED.len()` is 113 and `build_permit_rules(...).len()` is 116. The test is restored with the counts set to 113 and 116 and renamed to `permit_filter_has_113_workload_entries_and_one_installer_entry`. The four guards are kept. ## Tests The containment crate builds and `cargo fmt --check` is clean. The restored test is Linux-only (`cfg(target_os = "linux")`); CI's aarch64 Linux job exercises it.
Human readable section
Problem: Codex reports a damaged database and exits inside Strands Box v0.2.1 on Linux, even with a new writable data directory.
Solution: Box answers Codex's filesystem query with the metadata needed for startup while removing storage counts and identifiers. Codex stays unchanged.
Trade-off: Programs receive zero capacity and free-space counts, which some applications may treat as a full filesystem. Queries support absolute paths only, and surrounding runtimes must permit the added operations.
Description
The failure was reproduced with Codex CLI 0.167.0 (build 0.167.0.932) on Linux ARM64. Before opening SQLite, Codex calls
statfs, a Linux system call that identifies the filesystem and reports its storage statistics. It uses that information to choose database behavior for network filesystems. Box v0.2.1 rejects the call withEPERM(Operation not permitted), which Codex reports as a database problem.This Box-only change lets the unchanged Codex binary finish startup and reopen its databases. No changes to Box's command-line options or
box.tomlconfiguration are required.What the query returns
Programs can identify the filesystem behind a visible path, but they can't use this query to measure the surrounding operating system's storage usage. Programs that interpret a zero free-space count as a full filesystem might reject an operation.
How Box answers the query
Box uses Linux's secure computing (seccomp) facility to filter system calls. As with Box's existing filters, the filter uses classic Berkeley Packet Filter (BPF) instructions. For
statfs, it returns a user-notification action: Linux pauses the call and sends a request to Box's existing launcher, the process that starts the sandbox. This adds no extended BPF (eBPF) program, loader, orCAP_BPFrequirement.The launcher copies the pathname from the requesting process and resolves it inside that process's filesystem view. It uses
openat2to keep lookup within the requesting process's root directory. After querying the resolved filesystem, it copies the filtered result into the workload's output buffer withprocess_vm_writev, which respects read-only memory mappings. The reply completes the blocked call without executing the originalstatfscall.To read and write those buffers, the launcher retains
CAP_SYS_PTRACE, the kernel privilege used for process-memory access, within the sandbox's private user namespace. It drops every other capability. A user namespace limits where that capability applies; kernel checks prevent this authority from accessing memory in user namespaces in the surrounding operating system. The workload and the helper that manages its descendants still drop every capability.Before executing a contained Linux program, Box sets up a notification listener and transfers it to the launcher. This file descriptor lets the launcher receive notifications for paused calls. Failed setup or transfer prevents the program from starting. If the query service later fails fatally, the launcher exits. Box's existing cleanup mechanism then terminates the sandboxed program and its descendants. These failure paths don't send signals using a process ID that might have been reused.
Figure 1: A filesystem query during Codex startup. Box writes filtered information into Codex's output buffer. A separate status reply completes the paused call.
Editable draw.io source.
Linux requirements and behavior limits
Every contained Linux program installs the listener, including programs that never call
statfs. The surrounding runtime must permit listener setup and notification control calls, constrained path lookup throughopenat2, and buffer transfers throughprocess_vm_readvandprocess_vm_writev. Blocking listener setup prevents startup; blocking buffer access can make an individual query fail. Box preserves those restrictions rather than weakening the kernel's process-memory checks. It does not requestCAP_SYS_PTRACEin the surrounding operating system.These interfaces are available in Linux 6.1 and 6.12. The v0.2.1 release record documents validation on kernel
6.1.188, and the Amazon Elastic Kubernetes Service (EKS) deployment record uses6.12.111. This change doesn't require a kernel upgrade from either tested series. Those records don't define a numerical minimum supported kernel version.Box's Linux availability check tests only whether a user namespace can be created. It doesn't establish that the surrounding runtime permits all required operations. The query also has these limits:
EOPNOTSUPP(Operation not supported). The relatedfstatfscall, which queries an open file descriptor, remains denied to the workload.Related Issues
No Box bug report is linked. The upstream trigger is Codex's filesystem check before SQLite startup (openai/codex#56552).
Type of Change
Bug fix
Testing
The local code checks below passed for implementation commit
eb552fad316ede5d0705e4f937db76699c96f9bb, based on3eda3e2fefea748ea9d91988aa3812dfbb3508d3. They ran on Amazon Linux 2023 ARM64 with kernel6.12.113-138.209.amzn2023.aarch64and Rust 1.98.1. An independent agent review found no remaining concrete defect.PRAGMA integrity_check; restart reopened the same files. Hashes confirmed that the Codex binary and the tested Box binaries stayed unchanged.scripts/test-all.shcompleted the workspace tests with--no-fail-fast.The diagram commit changes only documentation; application code is identical to the tested implementation commit. The figure was exported with draw.io desktop 32.4.1 in the pinned container, at scale 2 with a 20-unit border. A control render matched the upstream reference PNG byte for byte. Layout checks reported no errors or warnings, and the exported image was visually reviewed.
The workspace Clippy command preserves its existing warning allowances. The separate containment-package check used none.
Hosted checks
For implementation commit
eb552fad, hosted Rust unit tests on Linux and macOS, Rust lint, and packaging tests passed, as did CodeQL code analysis.The diagram commit has separate continuous integration and CodeQL analysis runs. The pull request remains a draft, so hosted containment and verdict jobs are skipped. The previous implementation run's CI Gate log records that these skipped draft jobs prevent the combined check from passing. The automated Strands review for the diagram commit is waiting for manual approval.
Validation limits
The Codex checks use test configuration on XFS, the filesystem on the test host, and stop after startup. They submit no model requests and don't establish that a complete coding workflow succeeds. A live network filesystem wasn't exercised. Cloud checks for Amazon Bedrock AgentCore Runtime and container environments weren't rerun for this commit. Those unrun checks are coverage limits; no compatibility failure in those environments was reproduced. Local validation was Linux-only; hosted Rust tests provide the macOS result noted above.
The workspace suite retains its existing ignored tests. The credential daemon was unavailable. The Linux checks couldn't verify that files granted execution without read permission stay unreadable through other paths. The manual software development kit tutorial wasn't run because it requires external provider access.
just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
AI assistance: Codex helped prepare the implementation, validation, and this description.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.