Repository navigation
fix(containment): restrict Linux terminal and console controls - #255
Conversation
## Problem The inherited terminal remains a host resource. The existing TIOCSTI refusal leaves console controls and line-discipline changes reachable from an untrusted workload. The baseline terminal_discipline_cannot_change_or_break_input test demonstrates that TIOCSETD can replace terminal input processing. ## Solution Refuse TIOCLINUX and TIOCSETD beside TIOCSTI in the existing deny-only filter. Compare the low 32 request bits, as the kernel does. Keep ordinary terminal operations permitted. Document the restricted requests and remaining terminal limits. No public API or policy grant changes. ## Tests The containment suite passes 553 tests with all features. The five added tests cover truncated request arguments, unchanged terminal discipline and input queue, normal terminal operations, and foreground interrupts. Baseline and separate TIOCLINUX/TIOCSETD removal controls fail the relevant denial tests. Successful-operation controls pass on both baseline and repaired builds. A disposable full-CLI harness passes 17 scenarios, including input/output, resizing, interrupts, and restoration. Native validation uses ARM64 Amazon Linux 2023 and kernel 6.12.111. A real virtual console is unavailable; this does not claim console effect coverage, full terminal isolation, or cloud qualification.
## Problem An untrusted workload can inherit the operator console and change its keyboard, display, or switching state. The existing terminal filter permits these requests. ## Solution Add twenty request denials to the existing low-32-bit filter. Preserve ordinary terminal interaction and separately numbered queries. KDFONTOP shares font queries and changes, so both are refused. No public interface changes. Request constants come from proposed rust-lang/libc#5684. The declared libc 0.2.189 dependency lacks them. This draft requires its backport and release, then a real dependency update. Keep handwritten constants out of Box. ## Tests With an isolated libc constants overlay, all seven terminal tests passed. console_mutations_are_refused_before_device_dispatch detects each of twenty removed denials and a wrong 64-bit comparison. The read-only query control detects accidental KDGETMODE refusal. All 22 mutation checks detected the defect. Full Box disposable-terminal checks passed 82 cases, including restoration and foreground interrupts. The disposable console guest passed 25 cases, including six mutation routes and an outside observer after child exit. Containment passed 552 top-level tests, all-feature and no-default builds, strict lint, and formatting. Full workspace tests and lint remain pending. The declared-dependency check fails on the twenty missing libc constants. No physical keyboard/display, minimum-kernel, root-workload, or cloud qualification ran. The broad deterministic suite was not rerun for this draft.
|
Assessment: Request Changes I reviewed head Assumptions and rules checked that held
Apart from the rule conflict, the change is narrow and well tested, and the permitted-query tests are a good guard against refusing too much. |
|
Assessment: Comment (approve once the rule wording keeps its old scope) Re-review at Checked and held
|
|
Assessment: Approve Re-review at Checked and held
|
Human readable section
Problem. An untrusted workload can inherit the operator's Linux terminal or console and interfere with input, keyboard, display, or switching state.
Solution. Refuse console paste, terminal input-processing changes, and twenty console mutations. Keep ordinary terminal input/output, settings, resizing, foreground interrupts, and separately numbered read-only console queries.
Trade-off. Console management programs lose these operations. Font queries share a request with font changes, so those queries are also refused. Ordinary settings and terminal escape sequences remain permitted; this is not complete terminal isolation.
Dependencies. The filter defines the missing request constants privately from Linux's published headers. The existing released
libc0.2.189 dependency, manifests, and lockfile remain unchanged. rust-lang/libc#5684 stays open as an optional upstream contribution; this Box fix does not depend on its merge or release.Description
Refuse console paste and terminal input-processing changes. Add request-specific denials for keyboard/display modes, keyboard lock state and lights, accent tables, fonts, color palettes, screen/Unicode maps, console switching, deallocation, and console-wide resizing. Cover
VT_SETACTIVATE, which combines activation with mode changes, beside the separate operations.The filter compares the low 32 request bits, matching Linux's argument handling. It retains the input-injection refusal and includes the paste and input-processing refusals from #240. Read-only requests remain available when their request number distinguishes them.
KDFONTOPcarries its operation behind a pointer, so this scalar filter refuses the entire request. Ordinary resizing usesTIOCSWINSZand remains permitted.The protected side is the surrounding operating system and its resources. These restrictions apply to untrusted contained processes.
This PR supersedes #240 and includes its complete head,
c47b6bd2c1dcb498b5a675e129cb237df9892667. Review the terminal and console restrictions together here. The earlier PR retains its discussion and validation evidence. This PR targetsmainand has no merge prerequisite on #240.Current head:
37b44c66f7bf630f5a888ee805bac1b7701e0e9a. Independent adversarial code review at3640621found no implementation defect. The hosted reviewer then found conflicting instructions about constant sources. The documentation-only follow-up names the twenty-console-request exception while preserving the general rule for every other number and missing name. Issue #253 now states the same acceptance criterion. Kevin approved this scope and keeping upstream libc work optional. The hosted re-review at37b44c6approves the final wording and reports no open finding. Both addressed review threads are resolved. These reviews are not formal human approval.Authored and reviewed with Codex assistance.
Related Issues
Addresses #253 and the terminal-control portion of #51. Supersedes #240 with all its changes included. This PR does not close the broader scope of #51. The optional upstream contribution rust-lang/libc#5684 remains open.
Type of Change
Bug fix
Testing
Console paste effect validation, November 2 UTC. A fresh disposable ARM64 console guest passed 54 cases: two identities, three filter modes, three upper-bit patterns, and selection-only, paste-only, and combined operations. An outside parent checked exact input bytes or preserved selection after child exit. Privileged unfiltered controls injected a harmless marker; the production filters prevented it. Removing only the
TIOCLINUXcomparison restored the forbidden effect in all nine privileged cases. Filtered ordinary-user input, output, settings, resize/query controls, and outside restoration passed.The guest used Linux
6.12.113-138.209.amzn2023.aarch64, a dummy console, 512 MiB, one CPU, and no network. This kernel already refuses selection and paste to uid 1000 with no effective capabilities. The successful effect control used uid 0 with administrator capability inside the guest; it is not an ordinary-user exploit reproduction or root-launched Box qualification. The guest ran both retained production filters from #255 at3640621, byte-identical at37b44c6, rather than the full Box launcher. ItsTIOCLINUXrule is the restriction introduced by #240. Full launcher evidence remains the separate host runs. No physical keyboard/display, minimum-kernel, or cloud qualification is claimed. Raw evidence is retained in the implementation workspace underevidence/console-paste/.Both follow-up commits change only
crates/containment/AGENTS.md. Documentation consistency andgit diff --checkpassed; code and tests are byte-identical to3640621. The hosted test gate passed for that code revision. The results below are retained code evidence, not newly executed tests for the documentation-only commit.Current checks use the declared, released dependencies. Cargo metadata confirms registry
libc0.2.189, with no Cargo patch or fork dependency.scripts/test-all.shpassed 4,579 top-level tests across 138 groups, with zero failures and 17 ignored tests. One nested re-execution is excluded. The example build passed. No scripted examples exist; the manual SDK tutorial did not run.Broader-suite limits. Four runtime checks remain limited: missing credential daemon, missing installed socket-alias helper, removed cardinality probe, and an unavailable alias-read assertion. The performance probe reports the existing absolute latency-target miss in #150; passing relative assertions do not establish performance qualification.
The earlier 25-case disposable-console guest run used the previous constants overlay. The fresh registry build produces byte-identical filter instructions (SHA-256
d9d3d9b02354b5990b05befef0126eefa86ea6cbe569ba2f09b769885342e58e; 587 permit and 322 restriction instructions). The guest tested six mode/switching routes, includingVT_SETACTIVATE, with an outside observer after child exit. It also tested console queries, settings/restoration, ordinary resizing, and output. These are retained guest results, not a newly executed guest run.Environment limits. The ARM64 guest used Linux
6.12.113-138.209.amzn2023.aarch64, a dummy console, 512 MiB, one CPU, no network, and workload uid/gid 1000. It did not test a physical keyboard/framebuffer or the complete Box launcher in the guest. Fourteen other new mutations have filter-denial tests and source inspection without console-effect reproduction. Minimum kernels, root workloads, native macOS, and cloud qualification remain untested locally. Ordinary settings and terminal escape sequences remain permitted.just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.