Skip to content

fix(server): landlock root must be the destination's directory - #7316

Merged
oferchen merged 1 commit into
masterfrom
fix/landlock-dest-file-parent
Aug 14, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/landlock-dest-file-parent

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Root cause

The receiver-side --server Landlock allowlist takes the destination operand as its root:

dest_path.canonicalize().ok()
    .or_else(|| dest_path.parent().and_then(|p| p.canonicalize().ok()))

When the operand names an existing regular file, canonicalize() succeeds on the file and the parent fallback never runs. The ruleset then grants exactly that one file - PathBeneath over a regular file grants that file and does not widen to its parent (crates/fast_io/src/landlock.rs). The receiver's mkstemp of a sibling temp in the same directory fails with EACCES and the transfer dies.

When the destination does not exist, canonicalize() fails, the fallback runs, and the parent directory is allowlisted - which is correct. So the bug is confined to the already-exists case.

Upstream

get_tmpname() (receiver.c:309) builds the temp name from the destination's own directory - it splits fname at its last / (receiver.c:321) and prefixes the temp basename there. That directory is therefore always required, whether or not the destination file exists.

Fix

landlock_root_for_dest() resolves to the directory the receiver writes into: the canonicalised operand when it is a directory, its parent otherwise, keeping the existing not-yet-created fallback. This makes the existing-file case behave like the already-correct not-yet-exists case; no other shape changes.

Scope

Linux only - Landlock does not exist on macOS or Windows, which is why those cells were green. Reachable from a plain oc-rsync src/f.bin host:/path/to/existing-file over a remote shell.

Verification

  • New unit test root_is_the_written_directory_for_every_operand_shape pins all three operand shapes (directory / existing file / absent).
  • Non-vacuity proven: forcing the pre-fix branch (if canonical.is_dir() -> if true) makes the existing-file assertion fail with left: .../dest/f.bin, right: .../dest; restoring the fix makes it pass.
  • MEASURED: cargo fmt --all -- --check; cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings; cargo nextest run -p cli --all-features -E 'test(landlock_root)' (1 passed).

The receiver's server-mode Landlock allowlist took the destination
operand itself as its root. When that operand names an existing regular
file, `canonicalize()` succeeds on the file and the parent fallback never
runs, so the ruleset grants exactly that one file - a `PathBeneath` rule
over a regular file does not widen to its parent. The receiver's
`mkstemp` of a sibling temp then fails with EACCES and the transfer dies.

Upstream builds every temp name inside the destination's own directory
(`get_tmpname()`, receiver.c:309, splits `fname` at its last `/`), so
that directory is always the required root. Resolving to the parent when
the canonicalised operand is not a directory makes an existing
destination behave like one that does not exist yet, which already
resolved to the parent.

Visible as a push to an existing destination file over a remote shell on
Linux; macOS and Windows have no Landlock and were unaffected.
@oferchen
oferchen enabled auto-merge (squash) August 14, 2026 04:02
@github-actions github-actions Bot added the bug Something isn't working label Aug 14, 2026
@oferchen
oferchen merged commit aec510c into master Aug 14, 2026
66 of 67 checks passed
@oferchen
oferchen deleted the fix/landlock-dest-file-parent branch August 14, 2026 06:42
oferchen added a commit that referenced this pull request Aug 24, 2026
The receiver's server-mode Landlock allowlist took the destination
operand itself as its root. When that operand names an existing regular
file, `canonicalize()` succeeds on the file and the parent fallback never
runs, so the ruleset grants exactly that one file - a `PathBeneath` rule
over a regular file does not widen to its parent. The receiver's
`mkstemp` of a sibling temp then fails with EACCES and the transfer dies.

Upstream builds every temp name inside the destination's own directory
(`get_tmpname()`, receiver.c:309, splits `fname` at its last `/`), so
that directory is always the required root. Resolving to the parent when
the canonicalised operand is not a directory makes an existing
destination behave like one that does not exist yet, which already
resolved to the parent.

Visible as a push to an existing destination file over a remote shell on
Linux; macOS and Windows have no Landlock and were unaffected.
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