Repository navigation
fix(containment): permit copy_file_range and sendfile on Linux - #451
Conversation
## Problem On Linux, the seccomp permit filter refuses `copy_file_range` and `sendfile` with `EPERM`. libuv copies a file with `copy_file_range`, then `sendfile`, and treats `EPERM` from either as a real failure. So `fs.copyFile` and `fs.cp` fail inside a box, and Node project scaffolders such as Next.js and Vite cannot copy their templates between permitted paths (#420). ## Solution Add `copy_file_range` and `sendfile` to `WORKLOAD_PERMITTED`. Both calls act only on descriptors the workload already holds, and the kernel checks the same read and write modes that `read` and `write` check. `sendfile` has no address argument, so a socket destination reaches only a peer that `connect` already reached. The operator approved this permit set change on 2026-11-13. Returning `ENOSYS` instead (as in the closed #182) does not fix Node: libuv falls back from `copy_file_range` to `sendfile`, but not from `sendfile` to read and write. `crates/containment/AGENTS.md` records the measurement and one residual: on kernels 5.12 to 5.14, 5.15.0 to 5.15.24, and 5.16.0 to 5.16.10, `sendfile` into a pipe reaches the Dirty Pipe defect (CVE-2022-0847). `docs/design/linux-enforcement.md` states the new permits. No interface moves. ## Tests - `optimized_copies_reach_only_permitted_descriptors` runs a probe through the real trampoline. It copies with each call into a file, a pipe, and a Unix socket. It also checks that a read-only grant (`EROFS`, then `EBADF`), an ungranted path (`ENOENT`), and an inherited descriptor (`EBADF`) stay closed. Without either permit, the test fails with `EPERM`. - `permit_filter_has_the_expected_workload_and_installer_entries` counts the two new entries. - Manual, ARM64 kernel 6.18: Node 22.22.2 `--jitless` through the trampoline. On main, `fs.copyFileSync` and `fs.cp` fail with `EPERM`; with this change, both copy the file. A `sendfile` into a loopback TCP socket delivers the bytes; into an unconnected TCP socket it returns `EPIPE`. - `cargo build`, `cargo test`, `cargo clippy --all-targets`, and `cargo fmt --check` for `strands-box-containment --all-features` pass. `profile_conformance` needs a `$TMPDIR` outside the operator home. Not run: x86-64 tests (only `cargo check` of the library and binaries). Node without `--jitless` in a box is still blocked by #42. Twelve `test-integ` MCP cases need write access to `/usr/bin` and did not run on this host.
|
Assessment: Request Changes The Checked and held
The probe design, which pins the effect through the real trampoline, is a solid pattern. |
|
Assessment: Request Changes (unchanged)
Re-checked at 8590a99
|
… correct the libuv fallback
|
Assessment: Approve ef09b24 resolves the open thread. The wrong claim about the libuv fallback is corrected, and keeping Re-checked at ef09b24
|
Description
On Linux, the seccomp permit filter refuses
copy_file_rangeandsendfilewithEPERM. libuv copies a file withcopy_file_range, thensendfile, and treatsEPERMfrom either as a real failure. So Node'sfs.copyFileandfs.cpfail inside a box, and scaffolders such as Next.js and Vite cannot copy their templates.This change adds both calls to
WORKLOAD_PERMITTED.readandwritecheck, so the mount view and the filesystem grants still bound them.sendfilehas no address argument. A socket destination reaches only a peer thatconnectalready reached, and the egress relay copies bytes in user space, so it cannot tellsendfilefromwrite.http.FileServeralso sends files withsendfile. On main, its response has status 200 and stops after 512 bytes.Why permit
sendfileinstead of answering it withEINVAL. libuv falls back to read and write whensendfilereturnsEINVAL(notEPERMorENOSYS), soEINVALwould also fix Node and Go. The permit is kept for speed. On this host, withcopy_file_rangeansweringEXDEV(a copy across filesystems), Node copied a 512 MB file from xfs to tmpfs in 217–270 ms withsendfileand 501–533 ms withEINVAL. For 3000 files of 8 KB, the ranges overlapped. The cost is the old-kernel residual below.crates/containment/AGENTS.mdrecords both, and says to switch toEINVALif Box starts to defend against unpatched kernels.Decision this depends on: the operator approved widening the workload permit set with these two calls on 2026-11-13. No
decisions.mdentry records it.Residual, recorded in
crates/containment/AGENTS.md: from Linux 5.12,sendfileinto a pipe callssplice_file_to_pipe. On kernels 5.12 to 5.14, 5.15.0 to 5.15.24, and 5.16.0 to 5.16.10, that reaches Dirty Pipe (CVE-2022-0847).splice,vmsplice,tee, and io_uring stay refused. Seccomp cannot see a descriptor's type, so it cannot refuse a pipe destination alone. Box does not defend against an unpatched kernel (tenets non-goals).Related Issues
Closes #420. Refs #182, #42.
Type of Change
Bug fix
Testing
optimized_copies_reach_only_permitted_descriptorsruns a probe through the real trampoline. It copies with each call into a file, a pipe, and a Unix socket. It checks that a read-only grant, an ungranted path, and an inherited descriptor stay closed. With either permit removed, the test fails withEPERM(checked byfeature-criticmutation).--jitlessthrough the trampoline: on main,fs.copyFileSyncandfs.cpfail withEPERM; with this change, both copy.sendfileinto a loopback TCP socket delivers the bytes; into an unconnected TCP socket it returnsEPIPE.cargo build,test,clippy --all-targets(0 warnings), andfmt --checkforstrands-box-containment --all-featurespass.profile_conformanceneedsTMPDIRoutside the operator home on this host; withTMPDIR=/tmpit passes 68/68, on main and here.test-integ/run.sh: 119 pass, 10 macOS-only skips, 12 fail inmcp_fixture.rssetup (no write access to/usr/bin, beforestrands-boxruns).Not checked locally, so CI must cover it: x86-64 tests (only
cargo checkof the library and binaries ran). Node without--jitlessin a box is still blocked by #42.cargo test -p strands-box-containment --all-features)cargo fmt --allandcargo clippy --all-targets --all-features -- -D warnings(containment crate)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.