Skip to content

[0.0.24] fix(security): set no_new_privs before landlock_restrict_self - #2284

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1376/fix-landlock-no-new-privs
Oct 20, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1376/fix-landlock-no-new-privs

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Priority: P1 | Area: runtime | Labels: fix,P1,area:runtime,area:security | Milestone: 0.0.24 | RFC: OQ-012 | Task: CTX-1376

Closes #2282

Problem

Every admitted Layer-2 tool spawn on Linux was refused on an unprivileged
host, which the 0.0.24 runtime matrix caught through git-panel:

E_SPAWN_FAILED: spawn failed: unavailable: spawn failed for 'git' under tool confinement (fail-closed): Operation not permitted (os error 1)

Root cause

crates/bitty-sandbox/src/linux.rs applied the Landlock EXECUTE ruleset in
the child pre_exec hook by calling landlock_restrict_self without first
setting PR_SET_NO_NEW_PRIVS. Landlock requires that prerequisite for
unprivileged callers (or CAP_SYS_ADMIN), so the syscall answered EPERM and
Command::spawn failed; plugin_runtime/spawn.rs reported the fail-closed
confinement refusal.

Evidence:

  • syscall-level repro: the same ruleset sequence returns EPERM from
    landlock_restrict_self, and 0 after prctl(PR_SET_NO_NEW_PRIVS, 1);
  • unshare -rm (CAP_SYS_ADMIN in a user namespace) made the pre-fix tests
    pass without the prerequisite, proving it was the only blocker;
  • pre-fix cargo test -p bitty-sandbox printed SKIP: host forbids unprivileged landlock_restrict_self (Operation not permitted) for all three
    confinement tests — the skip is what hid the defect.

Fix

  • Set no_new_privs in the same child pre_exec path, immediately before
    restrict_self, and keep the failure mode fail-closed with the existing
    typed diagnostic. no_new_privs is not optional hardening here: it is what
    keeps the confined exec tree from regaining privilege through a
    setuid/setgid binary, so it belongs with the ruleset.
  • Drop the EPERM skip from the confinement tests (a spawn error is now a
    regression, never host policy) and add confined_child_sets_no_new_privs,
    which reads /proc/self/status from inside the confined child.
  • Harden the runtime proof: admitted_git_spawn_runs_under_inherited_confinement
    now requires a completed confined git status in a temp repository instead
    of accepting a fail-closed refusal.

Security model unchanged: no allow-all, no ambient PATH, no confinement
bypass. The [tools.git] verb/arg gate, the process.spawn:git install grant,
and the exec allowlist still gate the spawn; this only restores the inherited
confinement that was already accepted.

Regression (grant/deny pair)

  • granted_production_backend_runs_confined_git — granted + real
    git_spawn_backend: confined git status runs, exit_code == 0,
    untrusted == true.
  • spawn_without_grant_is_capability_denied — no grant: E_CAPABILITY_DENIED
    (existing).
  • production_backend_denies_unallowlisted_verbs_without_spawning +
    host_tools_authorizer_enforces_the_accepted_contract — undeclared
    executable / non-allowlisted verb denied before any process (existing).
  • shell_escape_denied_at_os_level, non_allowlisted_initial_exec_denied —
    OS-level denial still enforced (now actually executed, not skipped).

Gates

  • cargo fmt --all -- --check — clean.
  • just clippy (workspace all-targets + dev-tools, -D warnings) — clean.
  • cargo nextest run -p bitty-sandbox -p bitty-runtime -p bitty-lua --locked
    — 2933 passed, 2 skipped.
  • cargo check --target x86_64-pc-windows-gnu --workspace --all-targets —
    clean.
  • just scratch-paths — OK.
  • just ci-local not run: the shared filesystem hit 100% during the build
    (host-level caches from concurrent tasks); the local gate set above plus
    remote CI covers this change.

Post-merge: re-run the 0.0.24 matrix probe for plugin-git-panel from pinned
origin/main.

@Xuepoo Xuepoo added this to the 0.0.24 milestone Oct 19, 2026
@Xuepoo Xuepoo added fix Bug fix P1 Priority: high area:runtime Area: runtime orchestration area:security Area: security corpus / audit labels Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 38fd9d1d-9410-495f-a482-729780886bb8
📥 Commits

Reviewing files that changed from the base of the PR and between a888b51 and d4a5f6d.

📒 Files selected for processing: 4
  • crates/bitty-runtime/src/plugin_runtime/spawn.rs
  • crates/bitty-runtime/tests/spawn_surface.rs
  • crates/bitty-sandbox/src/lib.rs
  • crates/bitty-sandbox/src/linux.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo

Xuepoo commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Post-fix matrix probe (evidence)

Re-ran the 0.0.24 matrix probe for plugin-git-panel from pinned origin/main
(862df1f9), isolated XDG store, exactly the manifest's five capabilities
granted, against a debug binary of this branch (d4a5f6dc).

The confinement refusal is gone. An instrumented run shows the admitted
spawn actually executing under the armed ruleset:

spawn ok 'git' args=["branch", "-a"] pid=825544 confinement=true

Before the fix the same probe reported, before any process existed:

spawn failed for 'git' under tool confinement (fail-closed): Operation not permitted (os error 1)

The probe now advances past the spawn gate and still FAILs on a different,
pre-existing
gate — the RC-1 instruction budget:

vm suspended: InstructionBudgetExceeded { used: 10072955, budget: 10000000 }

That number is deterministic across four runs and two host working
directories (a one-branch repo and a several-hundred-branch worktree), so it is
not the 8 KiB spawn payload; it matches #1825 (10.08M at 0.0.22, where no
inherited tool confinement existed yet), which was closed without a fix.
Filed as #2285 with the measurement and the candidate causes (fuel accounting
for host-callback dispatch vs. the 50 ms wall budget being smaller than two real
git invocations). This PR does not change any RC-1 budget, by design.

Evidence: recording/release-runtime-matrix-0.0.24/rerun-git-panel-final/
(clean run, screenshot shots/plugin-git-panel-plugin-git-panel.png) and
rerun-git-panel-spawn/ (instrumented spawn proof).

CodeRabbit reported its review-limit warning on this PR (no findings posted).

@Xuepoo
Xuepoo merged commit b5b49dd into main Oct 20, 2026
17 checks passed
@Xuepoo
Xuepoo deleted the ctx-1376/fix-landlock-no-new-privs branch October 20, 2026 00:07
Xuepoo added a commit that referenced this pull request Oct 20, 2026
Cover the full `v0.0.23..main` range instead of the earlier partial passes:
all 71 merged commits are grouped under Added, Changed, Fixed, Security, and
Documentation, with PR numbers and the affected CTX tasks.

Explicit call-outs: copy keeps combining marks and ZWJ (#2266), multi-line
paste duplication and ghost fixed by the cursor clamp across wide spacers
(#2272), combining marks paint so decomposed `é` matches precomposed (#2279),
kitty font query and `bitty +show-font` (#2277), bounded native clipboard
acquisition path B (#2273), bounded `bitty.fs.list` (#2271), the
`bitty.history` Lua surface (#2268), the production ComponentBroker plus
activation state (#2267, #2276), Enter-confirm paste (#2269), the `fill` DPI
fix (#2283), landlock `no_new_privs` (#2284), and spawn descriptor
reservation (#2289).

Partials are marked honestly: #2254's request surface is still pending, the
#2213 disposition stays open, #2286 is feature-gated and unwired, the macOS
clipboard read stays a typed refusal, and the RC-1 fuel accounting fix is not
claimed because PR #2292 is unmerged. The heading reads `unreleased` because
the release is on hold; the tag date is set at tag time.

Docs-only: no code, scripts, workflows, or pins touched.
Xuepoo added a commit that referenced this pull request Oct 20, 2026
Cover the full `v0.0.23..main` range instead of the earlier partial passes:
all 71 merged commits are grouped under Added, Changed, Fixed, Security, and
Documentation, with PR numbers and the affected CTX tasks.

Explicit call-outs: copy keeps combining marks and ZWJ (#2266), multi-line
paste duplication and ghost fixed by the cursor clamp across wide spacers
(#2272), combining marks paint so decomposed `é` matches precomposed (#2279),
kitty font query and `bitty +show-font` (#2277), bounded native clipboard
acquisition path B (#2273), bounded `bitty.fs.list` (#2271), the
`bitty.history` Lua surface (#2268), the production ComponentBroker plus
activation state (#2267, #2276), Enter-confirm paste (#2269), the `fill` DPI
fix (#2283), landlock `no_new_privs` (#2284), and spawn descriptor
reservation (#2289).

Partials are marked honestly: #2254's request surface is still pending, the
#2213 disposition stays open, #2286 is feature-gated and unwired, the macOS
clipboard read stays a typed refusal, and the RC-1 fuel accounting fix is not
claimed because PR #2292 is unmerged. The heading reads `unreleased` because
the release is on hold; the tag date is set at tag time.

Docs-only: no code, scripts, workflows, or pins touched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Area: runtime orchestration area:security Area: security corpus / audit fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.0.24] git-panel spawn of git denied under tool confinement

1 participant