Skip to content

fix(cli): engage Landlock sandbox on --server receiver entry (UTS-16) - #5724

Merged
oferchen merged 1 commit into
masterfrom
fix/uts16-landlock-server-sandbox
Jun 11, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts16-landlock-server-sandbox

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Wires `fast_io::landlock::restrict_to_module_paths` into the lsh.sh-style `--server` receiver path before the token loop. This closes the chdir-symlink-race chmod-escape surfaced by the upstream testsuite once seccomp was disabled:

```
chdir-symlink-race: -r --size-only into upload/ root:
outside file mode changed from 600 to 666 (chmod escape)
```

The receiver was following an attacker-planted symlink and chmod-ing a file outside the destination tree. The daemon path already has the SEC-1.p Landlock sandbox via `engage_landlock_sandbox` in `module_access/transfer.rs:292`; the SSH `--server` entry never engaged it.

Changes

  1. `crates/cli/src/frontend/server/run.rs` — Engage `restrict_to_module_paths(&[dest_root])` after parsing positional args, before `run_server_stdio`. Receiver-only (sender / stat-only have no write target). Engage failures abort with a typed server error so the intended sandbox is never silently skipped.

  2. `crates/fast_io/src/landlock.rs` — Bump `AccessFs::from_all(ABI::V3)` → `ABI::V5` so kernels 6.7+ (including the target test host on 7.0) pick up the IPC scoping surface. BestEffort downgrade preserves V3 rights on older kernels.

  3. `crates/cli/Cargo.toml` — Forward the `landlock` feature into the CLI's `fast_io` dep on Linux. Mirrors the daemon pattern: non-Linux targets compile the stub module with the same public surface, so the call site needs no `#[cfg]` branching.

Test plan

  • CI: nextest (stable) — covers existing `landlock_overhead` bench + landlock unit tests
  • Upstream testsuite: `chdir-symlink-race` and `bare-do-open-symlink-race` flip from "positive control fails" to PASS
  • Verify legitimate in-module symlinks still transfer (no over-correction on `acls`, `alt-dest`, `atimes`)

Wires fast_io::landlock::restrict_to_module_paths into the lsh.sh-style
--server receiver path before the token loop. The upstream chdir-symlink-race
and bare-do-open-symlink-race tests swap a destination subdir for a symlink
pointing outside the requested root; without a kernel-enforced allowlist the
receiver follows the symlink and chmod's a file outside the destination tree
(observed: "outside file mode changed from 600 to 666 (chmod escape)" with
seccomp disabled).

Also:
- bump landlock module from ABI::V3 to ABI::V5 so kernels with IPC scoping
  (6.7+, including the target test host on 7.0) tighten the ruleset further.
  BestEffort downgrade preserves V3 rights on older kernels.
- forward the landlock feature into the CLI build on Linux so the binary
  links the real restrict_to_module_paths instead of the no-op stub.

The wire-in only fires for ServerRole::Receiver with a destination root in
config.args; sender and stat-only invocations skip the restriction so they
do not deny their own reads. Sandbox engage failures surface as a typed
server error - the intended sandbox did not engage and the connection must
abort rather than silently degrade.
@oferchen
oferchen force-pushed the fix/uts16-landlock-server-sandbox branch from 63bf271 to ffc3b35 Compare June 11, 2026 23:10
@oferchen
oferchen merged commit 93f93b9 into master Jun 11, 2026
11 of 13 checks passed
@github-actions github-actions Bot added the bug Something isn't working label Jun 11, 2026
oferchen added a commit that referenced this pull request Jun 12, 2026
* chore: fix master fmt drift + filter_map_bool_then clippy lint

Master CI broke on rustfmt 1.88 and clippy 1.88:

1. `crates/cli/src/frontend/server/run.rs:244` - `use fast_io::landlock::{...}`
   collapses to a single line under rustfmt 1.88 (introduced by PR #5724's
   landlock wire-in).
2. `crates/transfer/src/generator/filters.rs:589` - `let split = ...` long-form
   collapses to single-line under rustfmt 1.88.
3. `crates/transfer/src/generator/file_list/mod.rs:267` - rewrite
   `filter_map(|(b, rel)| (b == &entry.base).then(|| rel.clone()))` as the
   equivalent `filter(...).map(...)` pair so clippy 1.88's new
   `filter_map_bool_then` lint stays clean. Behaviour-identical.

Unblocks PRs #5725, #5726, #5727 once they rebase onto this.

* fix: drop extraneous deref in filter predicate

In .filter(), the destructured 'b' is already &PathBuf since iter() yields
&(PathBuf, PathBuf) and filter receives &Self::Item. The extra deref made it
PathBuf, causing E0277 'can't compare PathBuf with &PathBuf'.

* chore(cli): inline format args in --partial-dir test (clippy 1.88)

uninlined_format_args lint denies the build under clippy 1.88.
@oferchen
oferchen deleted the fix/uts16-landlock-server-sandbox branch June 12, 2026 14:39
oferchen added a commit that referenced this pull request Aug 24, 2026
…#5724)

Wires fast_io::landlock::restrict_to_module_paths into the lsh.sh-style
--server receiver path before the token loop. The upstream chdir-symlink-race
and bare-do-open-symlink-race tests swap a destination subdir for a symlink
pointing outside the requested root; without a kernel-enforced allowlist the
receiver follows the symlink and chmod's a file outside the destination tree
(observed: "outside file mode changed from 600 to 666 (chmod escape)" with
seccomp disabled).

Also:
- bump landlock module from ABI::V3 to ABI::V5 so kernels with IPC scoping
  (6.7+, including the target test host on 7.0) tighten the ruleset further.
  BestEffort downgrade preserves V3 rights on older kernels.
- forward the landlock feature into the CLI build on Linux so the binary
  links the real restrict_to_module_paths instead of the no-op stub.

The wire-in only fires for ServerRole::Receiver with a destination root in
config.args; sender and stat-only invocations skip the restriction so they
do not deny their own reads. Sandbox engage failures surface as a typed
server error - the intended sandbox did not engage and the connection must
abort rather than silently degrade.
oferchen added a commit that referenced this pull request Aug 24, 2026
* chore: fix master fmt drift + filter_map_bool_then clippy lint

Master CI broke on rustfmt 1.88 and clippy 1.88:

1. `crates/cli/src/frontend/server/run.rs:244` - `use fast_io::landlock::{...}`
   collapses to a single line under rustfmt 1.88 (introduced by PR #5724's
   landlock wire-in).
2. `crates/transfer/src/generator/filters.rs:589` - `let split = ...` long-form
   collapses to single-line under rustfmt 1.88.
3. `crates/transfer/src/generator/file_list/mod.rs:267` - rewrite
   `filter_map(|(b, rel)| (b == &entry.base).then(|| rel.clone()))` as the
   equivalent `filter(...).map(...)` pair so clippy 1.88's new
   `filter_map_bool_then` lint stays clean. Behaviour-identical.

Unblocks PRs #5725, #5726, #5727 once they rebase onto this.

* fix: drop extraneous deref in filter predicate

In .filter(), the destructured 'b' is already &PathBuf since iter() yields
&(PathBuf, PathBuf) and filter receives &Self::Item. The extra deref made it
PathBuf, causing E0277 'can't compare PathBuf with &PathBuf'.

* chore(cli): inline format args in --partial-dir test (clippy 1.88)

uninlined_format_args lint denies the build under clippy 1.88.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant