Repository navigation
fix(server): landlock root must be the destination's directory - #7316
Merged
Merged
Conversation
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
enabled auto-merge (squash)
August 14, 2026 04:02
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The receiver-side
--serverLandlock allowlist takes the destination operand as its root: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 -PathBeneathover a regular file grants that file and does not widen to its parent (crates/fast_io/src/landlock.rs). The receiver'smkstempof a sibling temp in the same directory fails withEACCESand 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 splitsfnameat 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-fileover a remote shell.Verification
root_is_the_written_directory_for_every_operand_shapepins all three operand shapes (directory / existing file / absent).if canonical.is_dir()->if true) makes the existing-file assertion fail withleft: .../dest/f.bin,right: .../dest; restoring the fix makes it pass.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).