Repository navigation
fix(containment): refuse Linux terminal input injection - #126
Merged
Merged
Conversation
## Problem The Linux filter permits ioctl requests without checking the request number. A workload can request synthetic input on an inherited terminal when the surrounding kernel permits TIOCSTI. ## Solution Refuse TIOCSTI through the existing argument-scoped filter. Compare the low 32 request bits, as Linux does, so upper bits cannot bypass the refusal. Keep other ioctl requests available. Legacy programs that use TIOCSTI fail with EPERM inside Box. No public interface or configuration key changes. ## Tests ARM64 Linux: terminal_input_injection_is_refused_before_descriptor_lookup and terminal_queries_still_work_under_the_filters pass without skips. The former uses an invalid descriptor and covers nonzero upper request bits. Removing the refusal fails the first test. Refusing every ioctl fails the second test. Restoring the implementation passes both tests. All 22 syscall table tests pass. Containment clippy with repository lint allowances and the no-default-features build pass. The ARM64 Linux library cross-check passes. macOS just check passes, including workspace formatting, linting, and tests with all features. Independent adversarial review found no code defect. No end-to-end terminal injection reproduction or full interactive shell compatibility test was run. Linux runtime checks used kernel 7.0.12-linuxkit; no Linux 6.1 runtime result is claimed.
|
Assessment: Approve A focused, well-reasoned security fix that closes the TIOCSTI input-injection vector (first item of #51). It reuses the established argument-scoped pattern, and the tests directly address the "refusal read as success" trap called out in the issue. Review notes
Clear commit message, thorough mutation testing, and the design documents its reasoning well. |
zastrowm
approved these changes
Oct 20, 2026
kevin-orellana
enabled auto-merge (squash)
October 20, 2026 21:38
abhisheksp
approved these changes
Oct 20, 2026
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human readable section
Problem statement: Sandboxed processes can use a system call
ioctlto relay messages to a terminal's feed. This can be abused to run arbitrary commands once the sandboxed process runs.Solution: Remove ability to relay synthetic input/output to this terminal channel.
Tradeoff: For a few, niche terminal programs that rely on this, they may lose ability to relay signals/messages to the terminal.
Description
The Linux filter permits
ioctlwithout checking its request number. A workload that inherits a controlling terminal can therefore request synthetic input throughTIOCSTIwhen the surrounding kernel allows it.Add an argument-scoped refusal for
TIOCSTI. The filter returnsEPERMbefore the kernel looks up the descriptor. Match the request's low 32 bits, as Linux does, so nonzero upper bits cannot bypass the rule. Otherioctlrequests retain their existing behavior.Programs that use
TIOCSTIto simulate terminal input will fail inside Box. The rule has no policy override. This change covers this request only; it does not isolate the shared terminal or claim complete terminal safety.Rationale
A workload must not make the operator's shell run commands by pretending that the operator typed them. Ordinary terminal input, output, settings, and job control do not require this request. Block it in Box so protection does not depend on the surrounding kernel's configuration.
The compatibility cost applies to specific features, not to all uses of an application. Examples include hstr's command insertion and Emacs returning queued text when it suspends. hstr also supplies shell integration without TIOCSTI. These are source findings, not application compatibility results.
Refuse only
TIOCSTI: blocking all terminal-control requests would also break legitimate terminal operations. Keep the refusal below policy, without an override that restores synthetic input to the operator's terminal. Shared-terminal risks outside this request remain outside this PR.Related Issues
Related to #51. This PR covers only its terminal-input injection item.
Type of Change
Bug fix
Testing
GitHub CI passed for commit
98dca00f59345e754c82b7f600077e46247d4e9f, including Linux/macOS unit tests, lint, deterministic containment, and the CI Gate. Claude Code and Codex compatibility checks also passed on this exact commit, with the launch-mode limit below.Review follow-up
dee28bbbfcd0937f4aa47609fba443158b811932changes only the compatibility test. It checks all four window-size fields using distinct, nonzero pixel dimensions. Both Linux ARM64 terminal tests, containment lint, formatting, and independent review passed. Zeroing either returned pixel field independently makes the test fail; restoring it passes. Production code remains identical to the application-tested commit above. Continuous integration is running for this follow-up.Claude Code and Codex compatibility
Both programs ran inside the patched Box on ARM64 Linux (
7.0.12-linuxkit) in a disposable terminal. The outer Docker container enabled the privileges required to create Box's namespaces. Each program made real model calls through Box's gateway.2.1.304with Claude Opus 5: headless file-edit and shell task passed in 14.65 seconds. Interactive typed input, resizing from 80×24 to 100×30, a shell task, and Ctrl-C exit passed in 25.07 seconds.0.163.0withopenai.gpt-5.6-terra: headless file-edit and shell task passed in 8.34 seconds. The interactive scenario passed in 17.21 seconds with--no-alt-screen --no-daemon.Codex launch-mode limit: default daemon mode reported an incomplete local package under the test's isolated filesystem grants. The documented
--no-daemonmode passed. This is not a claim that default daemon startup works inside Box.The Box binary SHA-256 was
d764db39cfa0726f456b859f42d10aaca073b36ae9285003f326c9238c9251a8; the containment trampoline SHA-256 was6c1f1bbc9c18599787acadd58a316b56e91a019ffb886e495cb25d4c618999b2.Filter and workspace checks
ARM64 Linux, Docker Desktop kernel
7.0.12-linuxkit, Rust1.98.1:cargo test --locked -p strands-box-containment --all-features --lib terminal_ -- --nocapture: 2 passed, no skips. Injection requests use descriptor-1, so the test cannot insert input. The control returnsEBADF; the filter returnsEPERM. Requests with nonzero upper bits are included.cargo test --locked -p strands-box-containment --all-features --lib backend::linux::namespace::syscall::tests: 22 passed, no skips.ioctlcalls fails the compatibility test. Restoring the implementation passes both tests.cargo clippy --locked -p strands-box-containment --all-features --all-targets -- -D warnings -A dead_code -A clippy::chunks_exact_to_as_chunks: passed. These allowances match the repository gate.cargo build --locked -p strands-box-containment --no-default-features: passed, with warnings from existing platform code.cargo check --locked -p strands-box-containment --lib --target aarch64-unknown-linux-gnu: passed.No manual end-to-end terminal-injection reproduction was run. The application results cover the scenarios above, not every shell/editor feature or plugin. No Linux 6.1 runtime result is claimed. Independent adversarial review found no code defect.
macOS ARM64:
just checkpassed (format, workspace clippy with repository allowances, and workspace tests with all features). Existing ignored tests remain ignored.just check, orcargo test --workspace --all-features)cargo fmt --alland workspace clippy throughjust check, with repository lint allowancesChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.