Skip to content

fix(containment): require exec grants for writable libraries - #261

Merged
kevin-orellana merged 5 commits into
mainfrom
feature/linux-writable-library-execution
Nov 3, 2026
Merged

kevin-orellana merged 5 commits into
mainfrom
feature/linux-writable-library-execution

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem. Linux dependency discovery could make a writable library executable without an execution grant for that library. A read-only executable mount did not protect its bytes from writes through another granted path. A permitted application could load bytes that the workload changed during the same launch or an earlier launch.

Solution. Refuse startup when a discovered dependency is writable and lacks explicit execution authority. Preserve explicit execution grants and the broader execution mode used by tools. Keep existing automatic loading for immutable libraries, including verified immutable hard links.

Trade-off. Agents with writable private libraries now need explicit execution permission for those libraries, or must remove write access. Adding a read grant does not resolve this refusal. Unknown alias permissions, remapped ownership, nested mounts, or unrecognized filesystem types can still require explicit execution permission. The change adds no library copying or new loader. Startup performance was not benchmarked.

Description

The Linux check separates a dependency's execution admission from inherited restrictions on reading its dependencies. The existing floors, explicit denials, read restrictions, and source-identity checks remain. A system-library read allowance does not exempt writable dependencies from execution authorization. Overlapping execution and write grants retain their warning and permitted behavior.

Hard links require a narrower execution check than the existing conservative read check. A retained descriptor identifies the library. The check retains restrictions for workload-owned files, group or other write bits, successful effective-credential write access, and errors other than permission denial. A read-only file owned by the workload remains restricted because its owner can change its permissions.

The immutable exception also checks the dependency and writable directory mount records. The directory must contain no nested mounts. Across different mounts, neither may remap ownership, and both must use recognized ordinary local filesystems: ext2, ext3, ext4, XFS, Btrfs, tmpfs, or ramfs. Retained descriptor mount IDs identify the source and writable-directory mount records. File device numbers are not compared with mountinfo device numbers; Btrfs subvolumes can report different values. Other filesystem types and uncertain information retain the restriction. Direct writable paths, replaceable resolution paths, and explicit writable file aliases do not use this exception. Existing derived-read restrictions remain unchanged.

The measured defect is an execution-permission bypass inside containment. The tests do not demonstrate access to ungranted host resources. The check uses current filesystem grants and does not track historical file authorship.

Related Issues

No public issue linked.

Type of Change

Bug fix

Testing

Documentation follow-up at dc91bc40e5d37e9d8bea22e24ddfa1d3e6b3fdb5 clarifies agent execution grants and the tool/server exception. Independent source and prose review, relative-link and anchor checks, and git diff --check passed. Only two Markdown files changed; runtime tests were not rerun locally. Hosted checks passed for this documentation head: CI Gate and all five CodeQL language analyses. The automated assessment reported Approve with no new findings at dc91bc4. This is not human approval.

Hosted Linux and macOS workspace and deterministic jobs tested merge 7832b5e682f28cadd3a5983cd2ad21a31f54ed2c, combining this head with main 93a376126fab710da750c37f97ad4c63bb5705e4. Checkout logs and the merge parents establish that revision; the deterministic report itself prints commit=unknown. Linux recorded 124 passes and 9 declared skips; macOS recorded 121 passes and 12 declared skips. Both recorded all 133 cases, with zero failures or errors.

Hosted limits remain: Linux workspace logs omit the alias-read assertion and the unavailable credential-daemon fixture. The write assertions ran. Native macOS bridge checks skipped because the runner lacks the macOS 27 SDK. The separate Verdict job was filtered out. Passing jobs do not establish complete coverage, release qualification, or human security acceptance.

The runtime evidence below applies to 448b0a23e15ce89e905d07cbb111b61a050550ae, except where an earlier revision is named.

Validation uses Amazon Linux 2023 on ARM64 (64-bit Arm), kernel 6.12.113-138.209.amzn2023.aarch64, and Rust 1.98.1.

Check Result
Complete containment package, all features 576 passed, zero failed, zero ignored. No prerequisite skip messages.
Contained integration coverage 12 tests across 19 contained cases passed. They cover same-run and cross-run writes, symbolic links, hard links, indirect dependencies, both library search formats, and allowed controls.
Unmodified e4ca8b8 baseline Same-run and cross-run fixtures executed workload-written library bytes without a library execution grant.
Repair removal Removing only the initial execution guard produced eight regression failures. Four permitted-operation tests still passed.
Immutable hard-link compatibility A disposable foreign-owned, mode-0755 library with two hard links and an unrelated writable workspace failed startup on d9a39b9. The earlier correction at 132274b loaded the same library and wrote the expected workspace output.
Writable hard-link control A foreign-owned, mode-0666 library with an alias inside the writable workspace was refused before application output in the earlier manual campaign. Writable-alias regressions at 448b0a2 also passed.
Separate local filesystem and bind-mount compatibility A disposable immutable library loaded and wrote expected output at ec09f12 with a separate tmpfs workspace and with an ordinary same-device bind mount. Both configurations refused startup at 132274b. The bind control used a private namespace and left the parent mount namespace unchanged. A writable alias remains refused.
Btrfs subvolume compatibility A real Btrfs image with subvolumes reproduced file device numbers differing from mountinfo. Both same-subvolume and separate sys/home-subvolume configurations failed at ec09f12 and loaded the immutable library with expected workspace output on the corrected source. Each comparison used an identical configuration. The private mount namespace exited and the loop device detached; the parent namespace was unchanged.
Permission and mount controls Tests preserve owned read-only files, direct writes, explicit writable aliases, inherited read restrictions, retained identity, uncertain errors, and nested-mount restrictions.
Independent code review No actionable findings in the final independent agent review. Human approval remains required.
Workspace tests 4,624 passed, zero failed, and 17 ignored across the reported Cargo targets, with all features and the Linux opt-in. Nested child results are excluded from the total. The repository output audit passed with its two documented omissions.
Workspace build, formatting, Clippy Passed. Clippy uses the repository allowances listed below. The build retains existing vendored-shell warnings.
Hosted CI Linux and macOS jobs and the final CI Gate passed for 448b0a2. Run 41386594245.
Hosted CodeQL All five language analyses passed for 448b0a2. Run 41386590516.
Automated re-review The reviewer reported Approve with no new finding on 448b0a2. Its formal GitHub submission is COMMENTED. Assessment.

The validated runtime source is 448b0a23e15ce89e905d07cbb111b61a050550ae; the documentation follow-up leaves that runtime source unchanged.

The final manual campaign repeated the two Btrfs comparisons. Earlier manual hard-link, tmpfs, and bind-mount controls above retain their recorded earlier revisions. They were not manually rerun on 448b0a2; its standard regression suites passed.

just is unavailable on this host, so its recipes ran directly. Workspace tests use EXPERIMENTAL_LINUX_SUPPORT=TRUE. Workspace Clippy uses --workspace --all-targets --all-features -- -D warnings, plus the repository allowances for clippy::too_many_arguments, clippy::only_used_in_recursion, clippy::await_holding_refcell_ref, clippy::explicit_auto_deref, clippy::chunks_exact_to_as_chunks, dead_code, and non_snake_case.

The real compatibility fixture uses directory Read permission. In the earlier manual campaign, a file-only Read grant produced the same loader mapping failure on untouched e4ca8b8 and the then-tested repair revision. That existing mount-overlap behavior remains outside this patch.

The workspace run omitted the real credential-daemon fixture and the Linux alias-read assertion. These are the two omissions accepted by the repository output audit. Existing ignored tests remain separate. Ownership-remapped and nested mount rejection has unit coverage; an actual ownership-remapped mount was not exercised.

Existing platform-excluded test binaries report zero tests on Linux. Package totals do not establish execution of every conditional test body. Hosted macOS validation at 448b0a2 passed. Combined-repair qualification and human security acceptance remain separate.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Prepared with Codex. The recorded source review is an agent review, not human approval.


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 dependency discovery could make workload-writable library bytes executable without an execution grant for that library. A read-only mount did not stop changes through another writable path.

## Solution

Refuse writable dependencies without explicit execution authority. Preserve explicit Exec File and Root grants, broad tool execution, existing read restrictions, floors, denials, and source-identity checks. Document the startup refusal and compatibility cost.

## Tests

The containment package passed 561 tests with all features on Amazon Linux 2023 ARM64. Twelve new integration tests cover 19 contained cases, including same-run and cross-run writes. The unchanged baseline executed the fixture libraries. Removing only the execution guard made eight regression tests fail, while four permitted-operation tests passed. Build, formatting, Clippy, and independent code review passed. No native macOS or combined-repair qualification ran.

`same_run_library_writes_require_explicit_execution_permission` and
`a_library_staged_by_an_earlier_launch_requires_explicit_execution_permission`
pin staged-write refusals and their explicit-execution controls.
`explicit_execution_grants_preserve_writable_library_loads` and
`broad_execution_preserves_writable_library_loads` pin permitted loading.
`an_immutable_private_library_preserves_unrelated_workspace_writes` pins
immutable loading with useful workspace writes.
`explicit_library_denial_still_overrides_broad_execution` pins denial precedence.
The `loader_admission` unit suite pins read restrictions, floors, and identity checks.
Comment thread docs/design/containment.md Resolved
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Request Changes

The guard correctly closes the case of genuinely writable libraries. But it inherits the nlink > 1 alias heuristic, which used to only add a read restriction and now stops startup, including for root-owned system libraries (shown on the runner in the inline comment). The decision record also needs to move along with the behaviour.

Checks that held
  • A library under a workspace Write+Root grant with no Exec is refused. A File or Root Exec grant that covers the resolved path admits it, and the overlap warning is kept.
  • A writable native interpreter (PT_INTERP) goes through the same guard.
  • broad_exec (tool leaves) bypasses the guard, as documented.
  • An explicit Deny still wins, because require_not_refused runs before the guard.
  • An immutable dependency of a writable program keeps only the read checks. No Exec is added.
  • Scope::Dir Exec can never match, which is right because cell_refusal rejects that cell.
  • The containment pub use façade is unchanged: a defect fix behind the frozen shape.
  • No pre-existing review comments, so nothing is duplicated.

The real-launch integration coverage across file and directory grants, symlinks, hard links, and staged writes is thorough.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) November 2, 2026 02:15
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Request Changes (re-review at 132274b)

The new ownership, permission and same-mount exemption fixes the case where the workspace and a hard-linked system library share a mount. When they are on different mounts it still refuses, including on ostree hosts. Details are in my reply on the existing view.rs thread. The decisions.md thread is also still open: the entry "Box bounds derived reads … derives no exec closure" is unchanged and still says system-library allowances are enough.

Checks that held at this head
  • A workspace on the same mount as a root-owned, mode 755, multiply linked libc now plans (reproduced on the runner).
  • A read-only hard link owned by the workload still needs Exec, because its owner can change the mode (documented and tested).
  • The write check runs on the retained descriptor (opened_identity, faccessat2 on the fd), so swapping the path after admission can't change the answer.
  • If the write root's identity has changed since config time, or if statx mount ID or mountinfo is unavailable or malformed, the answer stays "may be writable".
  • A nested mount under the write root, reached by either its original or its resolved spelling, cancels the exemption.
  • The exemption covers execution admission only; the dependency-read restriction is unchanged.

Permit the existing immutable hard-link exception across ordinary local
mounts when neither remaps ownership. Match retained descriptor devices
to the mount records and preserve conservative refusal for nested mounts,
layered or unknown filesystems, inconsistent metadata, and uncertain
permissions. Existing direct-write and dependency-read checks remain.

Add mount-record controls and document the supported exception. Real
launches cover separate tmpfs and ordinary bind mounts, with an unchanged
writable-alias refusal control.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Request Changes (re-review at ec09f12)

The cross-mount exemption now covers ext4 and tmpfs layouts, including a library and a workspace on different local filesystems. One inline finding remains: it matches records by device number, and that comparison fails on btrfs, which also undoes the btrfs same-mount case that worked at 132274b. I accept your reply on the decisions.md thread: the read-derivation rule that entry records is unchanged, and the Exec requirement is documented as a separate check.

Checks that held at this head
  • A library and workspace on different mounts of ordinary local filesystems (ext4 library, tmpfs workspace) now plan (reproduced).
  • If either mount is idmapped, the alias stays "may be writable" (unit-tested).
  • Duplicate mount IDs, malformed lines and unknown filesystem types stay "may be writable".
  • Nested mounts under the write root, by either its original or its resolved spelling, still cancel the exemption.
  • The ownership, mode and faccessat2 gate on the retained descriptor is unchanged; anything other than EACCES stays restricted.

Btrfs subvolumes report inode device numbers that can differ from the
superblock device in mountinfo. Locate mount records by the retained
statx mount IDs instead of requiring device-number equality.

Preserve inode permissions, admitted root identity, ownership mapping,
filesystem type, and nested-mount checks. Add Btrfs mount-record controls
and correct the design guide.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at 448b0a2)

The only change since ec09f12 is that mount records are now found by the mount IDs of the retained descriptors instead of by st_dev. That fixes the btrfs regression, and I found no new issue. The decisions.md thread was settled in the previous round.

Checks that held at this head
  • Root-owned, read-only, hard-linked libraries plan on ext4 (same mount), ext4/tmpfs, btrfs (same subvolume), and btrfs across subvolumes (reproduced on the runner).
  • Matching by mount ID alone loses no protection: statx STATX_MNT_ID corresponds to mountinfo field 1, and duplicate IDs still fail closed.
  • Idmapped mounts, unrecognized filesystem types, and nested mounts under the write root still keep the alias restricted.
  • Workload-owned files and group/other-writable files still need Exec, and any faccessat2 result other than EACCES stays restricted.
  • The exemption covers execution admission only; the dependency-read restriction is unchanged.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Approve (re-review at dc91bc4)

The only changes since 448b0a2 are in docs/design/linux-enforcement.md and docs/user/config.md. The code is the same as the version I approved. No new findings.

Checks that held at this head
  • "Tool and MCP filesystem tables reject exec": REMOVED_TOOL_FILESYSTEM_EXEC and REMOVED_MCP_FILESYSTEM_EXEC in record/config/mod.rs refuse it, and tests cover both.
  • "Tools and local MCP servers retain broader execution permission": both start with RuntimeReach::Leaf in run/hosted.rs, and boundary.rs maps that to allow_broad_exec().
  • The design page summarizes the rule and links to config.md#linux-writable-libraries for the details, so each fact has one owner (root AGENTS.md, Docs table). The new anchor follows the existing <a id> pattern.
  • The described behavior matches the code: a writable loader or library needs an explicit exec grant, aliases are covered, and the hard-link exemption still requires the ownership, permission and mount checks.

@kevin-orellana
kevin-orellana merged commit 26521e4 into main Nov 3, 2026
23 checks passed
@kevin-orellana
kevin-orellana deleted the feature/linux-writable-library-execution branch November 3, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants