Skip to content

fix(sandbox): preserve Linux overlayfs directory identity across copy-up - #6910

Merged
M4n5ter merged 2 commits into
apache:rust-previewfrom
Colafornia:fix/sandbox-overlayfs-directory-identity
Nov 15, 2026
Merged

M4n5ter merged 2 commits into
apache:rust-previewfrom
Colafornia:fix/sandbox-overlayfs-directory-identity

Conversation

@Colafornia

@Colafornia Colafornia commented Nov 14, 2026 •

Copy link
Copy Markdown
Member
English

Summary

Preserve workspace directory grants when Linux overlayfs copies a lower-layer directory to the writable upper layer. Creating .maka-workspace.json must not invalidate the grant used by ACP session/new and later tools.

Refs #6667 and #6815.

Root cause and identity boundary

DirectoryIdentity hashes (volume, ino, birth). Directory copy-up can change birth time while preserving the visible directory inode. Omit birth only for overlayfs, and obtain its instance UUID through the existing FS_IOC_GETFSUUID path.

A nonzero f_fsid is insufficient: with uuid=off/null, overlayfs returns the backing filesystem's fsid. Independent overlays can then share both fsid and a lower directory's inode. The initial PR accepted one overlay's grant after the same path was mounted with another upper directory. This revision removes overlayfs from the fsid branch and rejects mounts that cannot expose an instance UUID. It also removes the synthetic statfs helper and its obsolete test.

The earlier claim that overlayfs always rejects FS_IOC_GETFSUUID, or that uuid=off implies a zero fsid, was incorrect on the tested kernel. The ioctl returns a persistent instance UUID with uuid=on/auto; uuid=off/null returns ENOTTY, mapped to Unsupported.

Verification

Verified at 0899774dcd68e904154cfb4f32cd433a72ea41fa (based on origin/rust-preview 0b1e112aace9cff744a4064f6395b4676576c054):

  • Linux aarch64, kernel 7.2.12-orbstack-00394-gbecdd6130068: cargo clippy --locked -p maka-sandbox --all-targets --no-deps -F schemars/uuid1 -- -D warnings passed (0 warnings), and cargo test --locked -p maka-sandbox --lib -F schemars/uuid1 passed (10 passed, 2 explicitly ignored live-mount tests).
  • Ran the ignored live-mount tests explicitly in a disposable Docker container (CAP_SYS_ADMIN, tmpfs-backed overlays) with MAKA_TEST_OVERLAYFS_DIR and -- --ignored --nocapture: uuid=on (captured_grant_survives_linux_overlayfs_copy_up) and uuid=off (captured_grant_rejects_linux_overlayfs_without_uuid) both passed. (Additional uuid=auto/uuid=null mounts and the separate maka-fs-tools::directory::open harness verifying persistence across unmount/remount and cross-instance rejection were verified against the same diff at 0daa2ef6dc612300b893f82d27de368144c60509, where the rejection test also failed prior to the fix.)
  • macOS arm64 (Darwin 27.2.0 / macOS 27.2.1): cargo clippy --locked -p maka-sandbox --all-targets --no-deps -F schemars/uuid1 -- -D warnings passed (0 clippy warnings), and cargo test --locked -p maka-sandbox -F schemars/uuid1 passed (11 lib tests + 4 integration tests passed).
  • cargo fmt -p maka-sandbox -- --check, node scripts/asf-license-headers.mjs check, and git diff --check passed.

The live-mount tests remain explicitly #[ignore] by default and are not wired into CI. Only Windows tests, Linux bubblewrap integration, and full just check are left to CI.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Google Antigravity authored the initial change. OpenAI Codex verified and fixed the overlay identity collision, updated regression coverage, and ran the pre-rebase Linux checks; Google Antigravity rebased onto origin/rust-preview and re-ran Linux clippy, unit, live-mount (uuid=on/uuid=off), and macOS checks. Preserve both Generated-by trailers when squashing.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No
中文

概述

保持 Linux overlayfs 目录从只读下层复制到可写上层后的工作区授权有效。创建 .maka-workspace.json 不应使 ACP session/new 和后续工具使用的目录授权失效。

关联 #6667 与 #6815。

根因与身份边界

DirectoryIdentity 对 (volume, ino, birth) 计算哈希。目录复制到上层时,可见的 inode 保持不变,但创建时间可能改变。因此仅对 overlayfs 省略创建时间,并通过已有的 FS_IOC_GETFSUUID 路径获取实例 UUID。

非零 f_fsid 不足以证明实例身份:uuid=off/null 下,overlayfs 返回底层文件系统的 fsid。不同 overlay 实例可能同时共享这个 fsid 和下层目录的 inode。初版 PR 在同一路径换挂另一个上层目录后,仍接受原实例的授权。本次修订移除 overlayfs 的 fsid 分支,拒绝无法提供实例 UUID 的挂载,并删除合成 statfs 测试及其专用辅助函数。

此前关于 overlayfs 总是拒绝 FS_IOC_GETFSUUID、或 uuid=off 意味着 fsid 为零的描述,在本次内核实测中均不成立。uuid=on/auto 时 ioctl 返回持久化的实例 UUID;uuid=off/null 时返回 ENOTTY,映射为 Unsupported。

验证

验证提交:0899774dcd68e904154cfb4f32cd433a72ea41fa(基于 origin/rust-preview 0b1e112aace9cff744a4064f6395b4676576c054):

  • Linux aarch64,内核 7.2.12-orbstack-00394-gbecdd6130068:cargo clippy --locked -p maka-sandbox --all-targets --no-deps -F schemars/uuid1 -- -D warnings 通过(0 告警),cargo test --locked -p maka-sandbox --lib -F schemars/uuid1 通过(10 项通过,2 项真实挂载测试显式忽略)。
  • 在带 CAP_SYS_ADMIN 的一次性 Docker 容器内用 tmpfs 支撑 overlay 挂载,通过 MAKA_TEST_OVERLAYFS_DIR 和 -- --ignored --nocapture 显式运行真实挂载测试:uuid=on(captured_grant_survives_linux_overlayfs_copy_up)与 uuid=off(captured_grant_rejects_linux_overlayfs_without_uuid)均通过。(其余 uuid=auto/uuid=null 挂载,以及调用生产 DirectoryIdentity 与 maka-fs-tools::directory::open 验证跨卸载重挂持久化与跨实例拒绝的独立验证程序,已在同 diff 的 rebase 前提交 0daa2ef6dc612300b893f82d27de368144c60509 上通过,且该拒绝测试在修复前复现失败。)
  • macOS arm64(Darwin 27.2.0 / macOS 27.2.1):cargo clippy --locked -p maka-sandbox --all-targets --no-deps -F schemars/uuid1 -- -D warnings 通过(0 clippy 告警),cargo test --locked -p maka-sandbox -F schemars/uuid1 通过(11 项单元测试 + 4 项集成测试通过)。
  • cargo fmt -p maka-sandbox -- --check、node scripts/asf-license-headers.mjs check 与 git diff --check 通过。

真实挂载测试默认保持显式 #[ignore],尚未接入 CI。仅 Windows 测试、Linux bubblewrap 集成与完整 just check 由 CI 覆盖。

AI 使用

  • 没有生成式工具作出实质性贡献
  • 生成式工具作出了实质性贡献

Google Antigravity 编写初版改动;OpenAI Codex 验证并修复 overlay 身份碰撞、更新回归测试并执行 rebase 前 Linux 检查;Google Antigravity 将分支 rebase 至 origin/rust-preview 并重跑 Linux clippy、单元测试、真实挂载测试(uuid=on/uuid=off)及 macOS 全套检查。Squash 时请保留两个 Generated-by trailers。

审查清单

  • 测试覆盖本次变更且在修改前失败
  • 格式、类型检查和受影响套件均已在本地通过

本 PR 是否带来行为变更?

  • 是 — 如上文概述所述
  • 否

@github-actions github-actions Bot added the effort/M Under 500 readable lines label Nov 15, 2026
Reuse FS_IOC_GETFSUUID instead of accepting a shared backing fsid. Reject overlays without an instance UUID while preserving copy-up stability. Replace the synthetic fsid test with an explicit live-mount rejection test.

Generated-by: OpenAI Codex
@Colafornia
Colafornia force-pushed the fix/sandbox-overlayfs-directory-identity branch from 0daa2ef to 0899774 Compare November 15, 2026 11:46
@Colafornia
Colafornia marked this pull request as ready for review November 15, 2026 11:47
@M4n5ter
M4n5ter merged commit b3f3cc6 into apache:rust-preview Nov 15, 2026
29 of 31 checks passed
@Colafornia
Colafornia deleted the fix/sandbox-overlayfs-directory-identity branch November 16, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants