Skip to content

fix(copy): fall back to ordinary copy when seccomp denies FICLONE - #831

Closed
foxsky wants to merge 1 commit into
openclaw:mainfrom
foxsky:fix/ficlone-eperm-fallback
Closed

foxsky wants to merge 1 commit into
openclaw:mainfrom
foxsky:fix/ficlone-eperm-fallback

Conversation

@foxsky

@foxsky foxsky commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: Root.copyIn and other native file copies with clone: "auto" fail with helper-failed ("native file copy failed | FICLONE: Operation not permitted") inside containers whose seccomp or LSM policy denies the FICLONE ioctl, such as LXC on ext4.

User Impact

User impact: on such hosts, clone: "auto" copies now fall back to an ordinary copy instead of failing, and clone: "always" reports unsupported-platform instead of helper-failed. OpenClaw's updater hits this in its updater-runtime-retention step, which blocks package updates on LXC hosts until the fixed version is the one running the update.

Why This Change Was Made

Container seccomp profiles deny FICLONE with EPERM by ioctl number, and the auto policy only treated ENOTSUP/EOPNOTSUPP/EXDEV/EINVAL/ENOSYS/ENOTTY as "clone unavailable". The change adds EPERM to that set for FICLONE only.

This differs from the openat2 rule in linux_open.rs ("EPERM on an actual operation must never select a fallback"). There the fallback would weaken path resolution. Here the target was just created with O_EXCL, so the kernel's own FICLONE EPERM (immutable or append-only destination) cannot apply. The ordinary-copy fallback also writes through the same exclusive descriptor using normal I/O, so a real policy denial still fails closed. copy_file_range handling is unchanged.

Evidence

Checked on a real Proxmox LXC host (container=lxc, ext4, seccomp filter active). There, FICLONE returns EPERM even for arguments the kernel would reject with other errors (a directory source, the same fd), which confirms the filter matches on the ioctl number. copy_file_range works on this host.

  • Public API A/B (root(dir).copyIn(..., { clone: "auto" }), FS_SAFE_NATIVE_MODE=require, rebuilt native addon):

    • this branch without the EPERM line: helper-failed native file copy failed | cause: FICLONE: Operation not permitted (os error 1)
    • this branch: copy succeeds with the expected bytes
  • test/root-copy-options.test.ts "honors clone=always only when…": the environment probe now accepts EPERM. On this host it fails with helper-failed without the fix and passes with it (38 passed, 1 skipped).

  • New Rust unit test ficlone_policy_denials_select_ordinary_copy. cargo test --workspace passes (134 tests in the fs-safe-native library suite).

  • 14 copy and clone test files under FS_SAFE_NATIVE_MODE=require: 269 passed, 14 skipped, 0 failed after the probe update.

  • cargo clippy --workspace --locked -- -D warnings is clean apart from a fetch_update deprecation in watch.rs, which also fails on unmodified main with Rust 1.99.

  • lint:file-size, lint:fs-boundary, docs:check pass. git diff --check is clean.

  • Codex autoreview (P0–P2): scoped-clean.

  • Gap: full pnpm check didn't run locally because its archive WASM build needs clang with the wasm32 target. CI covers it.

  • Tests added or updated when behavior changed

  • Security and compatibility impact considered

  • CHANGELOG.md updated when release-relevant

  • No credentials, private paths, private hosts, or sensitive contents included

Container seccomp and LSM policies (for example LXC on ext4) deny the
FICLONE ioctl with EPERM by ioctl number. clone: "auto" treated that as a
hard helper failure instead of an unavailable clone, so Root.copyIn and
callers such as the OpenClaw updater failed with "native file copy failed".

The target is created with O_EXCL immediately before FICLONE, so the
kernel's own EPERM (immutable or append-only destination) cannot apply.
The ordinary-copy fallback writes through the same exclusive descriptor
with normal I/O, so any real policy denial still fails closed.
@foxsky
foxsky requested a review from a team as a code owner October 3, 2026 22:26
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 6:30 PM ET / 22:30 UTC.

ClawSweeper review

What this changes

The PR lets Linux native file copies fall back when FICLONE returns EPERM, preserves strict cloning refusal, and updates regression coverage and the changelog.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and v0.23.0 still reject seccomp-denied FICLONE instead of falling back. The patch is focused and supported by a real LXC public-API comparison; another open PR independently covers the same defect.

Priority: P2
Reviewed head: 57a58a674e966835229feed29421531de1e48728

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused fix with relevant real-host comparison and regression coverage; no blocking correctness defect was identified.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied real LXC/ext4 comparison exercises Root.copyIn through the rebuilt native file-copy owner in require mode, showing the FICLONE error before classification and expected destination bytes afterward. Supplemental coverage checks strict refusal; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied real LXC/ext4 comparison exercises Root.copyIn through the rebuilt native file-copy owner in require mode, showing the FICLONE error before classification and expected destination bytes afterward. Supplemental coverage checks strict refusal; no stored-data contract changes.
Evidence reviewed 8 items Introduced change: The pinned main-to-head diff changes only FICLONE error classification, focused tests, and an Unreleased changelog entry. EPERM from target creation, copy_file_range, and other operations is not reclassified.
Main and release still lack the fix: Inspection of pinned main and v0.23.0 shows the FICLONE unavailable-error set omits EPERM. Neither already implements the requested fallback.
Fallback remains guarded: Failed cloning performs identity-checked cleanup; cleanup failure becomes EIO and prevents retry. Auto mode then creates a fresh target with EXCL and NOFOLLOW under the retained parent. Contrary to the new comment and body explanation, fallback does not reuse the clone destination descriptor; this discrepancy does not establish a runtime safety defect.
Findings None None.
Security None None.

How this fits together

fs-safe copies admitted source files into exclusive destination stages before guarded publication. Its native transfer layer chooses cloning, copy offload, or ordinary reads and writes while preserving filesystem safety checks.

flowchart TD
  A[Admitted source file] --> B[Exclusive destination stage]
  B --> C[Attempt Linux cloning]
  C --> D{Clone policy and result}
  D --> E[Successful clone]
  D --> F[Checked cleanup and ordinary copy]
  D --> G[Strict refusal or terminal error]
  E --> H[Guarded publication]
  F --> H
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

None.

Technical review

Best possible solution:

Land one shared FICLONE-only fix across the overlapping candidates, retaining checked cleanup, exclusive recreation, and strict cloning refusal.

Do we have a high-confidence way to reproduce the issue?

Yes: Root.copyIn with clone auto and native require mode on a host denying FICLONE with EPERM follows the source-proven failure path, corroborated by the contributor’s real LXC comparison. The reviewer did not execute it.

Is this the best way to solve the issue?

Yes: classifying only the clone ioctl denial as unavailable uses the existing guarded fallback without broadening permission-error recovery elsewhere.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 29f13fdeacc0.

Labels

Label changes:

  • add P2: This repairs native automatic copying on Linux hosts that deny the clone ioctl, with a bounded change to error classification.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied real LXC/ext4 comparison exercises Root.copyIn through the rebuilt native file-copy owner in require mode, showing the FICLONE error before classification and expected destination bytes afterward. Supplemental coverage checks strict refusal; no stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied real LXC/ext4 comparison exercises Root.copyIn through the rebuilt native file-copy owner in require mode, showing the FICLONE error before classification and expected destination bytes afterward. Supplemental coverage checks strict refusal; no stored-data contract changes.

Label justifications:

  • P2: This repairs native automatic copying on Linux hosts that deny the clone ioctl, with a bounded change to error classification.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied real LXC/ext4 comparison exercises Root.copyIn through the rebuilt native file-copy owner in require mode, showing the FICLONE error before classification and expected destination bytes afterward. Supplemental coverage checks strict refusal; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied real LXC/ext4 comparison exercises Root.copyIn through the rebuilt native file-copy owner in require mode, showing the FICLONE error before classification and expected destination bytes afterward. Supplemental coverage checks strict refusal; no stored-data contract changes.

Evidence

What I checked:

  • Introduced change: The pinned main-to-head diff changes only FICLONE error classification, focused tests, and an Unreleased changelog entry. EPERM from target creation, copy_file_range, and other operations is not reclassified. (native/src/unix.rs:884, 57a58a674e96)
  • Main and release still lack the fix: Inspection of pinned main and v0.23.0 shows the FICLONE unavailable-error set omits EPERM. Neither already implements the requested fallback. (native/src/unix.rs:882, 223a30531ea8)
  • Fallback remains guarded: Failed cloning performs identity-checked cleanup; cleanup failure becomes EIO and prevents retry. Auto mode then creates a fresh target with EXCL and NOFOLLOW under the retained parent. Contrary to the new comment and body explanation, fallback does not reuse the clone destination descriptor; this discrepancy does not establish a runtime safety defect. (native/src/file_copy.rs:153, 57a58a674e96)
  • Existing public transfer contract: The writing documentation defines auto as cloning followed by offload or ordinary copying when unavailable, and always as requiring cloning. The existing JavaScript boundary maps ENOTSUP to unsupported-platform for always. (docs/writing.md:409, 57a58a674e96)
  • Real after-fix evidence: The complete supplied PR body records a real Proxmox LXC/ext4 host with active seccomp, a rebuilt addon in native require mode, and a Root.copyIn auto comparison: removing the EPERM classification produces the FICLONE helper-failed error; the patched branch copies the expected bytes. It also reports strict-clone refusal coverage and supplemental native and copy-suite results. This is contributor evidence, not reviewer execution. (57a58a674e96)
  • Independent overlapping implementation: fix(atomic): fall back when Linux FICLONE is denied with EPERM #829 is open and adds the same FICLONE-only EPERM classification. Its inspected body and patch additionally describe real LXC verification, an isolated seccomp regression, and documentation. It is overlapping candidate work, not a merged fix or grounds to close this PR under the target policy. (native/src/unix.rs, ce08d5f06cf4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

steipete pushed a commit that referenced this pull request Oct 5, 2026
Linux containers whose seccomp or LSM policy denies `FICLONE` with `EPERM` caused native copies with `clone: "auto"` to fail instead of copying bytes. The file-clone primitive now classifies that ioctl denial as unavailable cloning: `auto` uses the existing guarded ordinary-copy path, while `always` reports `unsupported-platform` and removes the stage. Strict `copyTree` cloning is unchanged. This addresses the updater failure tracked in openclaw/openclaw#164113.

The target was just created with `O_EXCL`, so FICLONE's immutable/append-only destination explanation for EPERM does not apply. The fallback recreates the destination through the same guarded exclusive path and still fails closed if normal writes are denied. This deliberately differs from openat2's EPERM rule: it does not weaken path resolution. The rationale from @foxsky's duplicate #831 is incorporated inline, with co-author credit in the squash commit; a one-caller classification helper was unnecessary.

The isolated Linux seccomp regression denies only `ioctl(FICLONE)`, verifies correct non-cloned bytes in auto mode, and verifies always-mode failure without a leftover stage. The writing guide, clone support probe, and Unreleased changelog are updated.

Validation: `cargo test --workspace --locked` and Clippy passed on macOS; 64 focused copy tests passed with the native addon loaded (nine platform skips); Codex autoreview is clean at P0–P2. Exact-head Linux CI runs the seccomp regression, alongside the full OS matrix and CodeQL. Full `pnpm check` passed lint, build, allocator-build, and documentation checks locally, but the full test phase was stopped after widespread timing failures on a busy host.

Thanks @Mohl for the fix and seccomp regression, and @foxsky for the security rationale.

Exact-head CI passed on `6fe1c458485a699b12a71806d8093b1e0dfb92ed`: all OS lanes, the Linux seccomp regression, mutation-policy proofs, coverage, benchmarks, and CodeQL. [CI run](https://github.com/openclaw/fs-safe/actions/runs/37258456239).

Co-authored-by: Mohl <[email protected]>
Co-authored-by: foxsky <[email protected]>
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix and the careful security rationale, @foxsky! We landed the same production change in the earlier-submitted #829, which also includes an isolated seccomp regression proving that auto falls back and always fails without leaving a stage.

Your explanation of the newly created exclusive target and why this fallback remains fail-closed is incorporated in the code comment, including the distinction from openat2's EPERM rule. You are credited as a co-author in the squash commit. Closing this as a duplicate of #829, with thanks for helping make the fix clearer.

@steipete steipete closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants