Skip to content

fix(daemon): open the lock file through the ownership walk at mode 0600 - #7439

Merged
oferchen merged 2 commits into
masterfrom
fix/daemon-lock-file-ownership-walk
Aug 22, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/daemon-lock-file-ownership-walk

Conversation

@oferchen

Copy link
Copy Markdown
Owner

The gap

lock file = PATH is operator-named in oc-rsyncd.conf, and the daemon opens it as whatever user it runs as — typically root, and before the per-module privilege drop. Both opens went straight to OpenOptions:

OpenOptions::new().create(true).truncate(false).read(true).write(true).open(&path)   // create
OpenOptions::new().read(true).write(true).open(&self.path)                           // per claim

A symlink planted at any component redirects that privileged O_CREAT open to a file the operator never named. The leaf need not exist yet, so a leaf-only O_NOFOLLOW could not reject it either — the parent-component case is exactly what the ownership walk exists for.

Upstream closes it with the same primitive it uses for every other operator-named aux file:

/* connection.c:35 — claim_connection() */
if ((fd = open_no_attacker_symlinks(fname, O_RDWR|O_CREAT, 0600)) < 0)

Why this was the last one

oc already had the walk and already routed the daemon config, motd, secrets file, --password-file, --log-file and both merge-file parsers onto it. The lock file was the one daemon aux-file open still on a bare path, because no existing helper opened O_RDWR|O_CREAT — operator_open_read and operator_open_append were the only variants. This adds operator_open_rw_create beside them; all three delegate to the same private operator_open_with, so there is one walk, not a third copy.

The mode is upstream's, not incidental

OpenOptions::create(true) requests 0666, which lands on 0644 under the common 022 umask — a shared lock file left world-readable on a daemon with a permissive umask. Upstream passes 0600 explicitly.

Two deliberate behaviour changes

1. The per-claim reopen now carries O_CREAT, matching upstream's single O_RDWR|O_CREAT per claim_connection(). Previously, a lock file removed after startup made every later claim fail; upstream recreates it. It also removes a second unguarded resolution of the operator path.

2. That invalidated a test's DETECTOR, not its claim — stated explicitly rather than re-baselined. negative_max_connections_still_opens_the_lock_file_first proves a disabled module must not short-circuit ahead of the open (upstream connection.c:31), and it detected the open by deleting the lock file. With O_CREAT, a missing file is no longer an error, so that detector would have silently stopped detecting anything. It is now a directory at the lock path, which fails EISDIR even with O_CREAT. The assertion is unchanged; the comment records why, so it is not "simplified" back to remove_file.

Verification

The new pin asserts the created mode is exactly 0600. That is umask-independent by construction — a umask can only clear bits, and 0600 has no group or other bits left to clear — so it discriminates rather than restating whatever the environment produces.

RED proven by setting the constant to 0666:

assertion `left == right` failed: lock file must be created 0600 per connection.c:35, got 644

644 is precisely the pre-fix behaviour, so this test is red against master and green only with upstream's constant.

cargo nextest run -p daemon -p fast_io --all-features --no-fail-fast → 2570 run, 2570 passed, 6 skipped. fmt + clippy clean.

Scope note

create_dir_all(parent) in ConnectionLimiter::open is left as-is. Upstream does not create the lock file's parent at all; removing it would change behaviour for operators relying on the auto-created directory, which is a separate decision from routing the open.

`lock file = PATH` is named by the operator in oc-rsyncd.conf, and the
daemon opens it as whatever user it runs as - typically root, and before
the per-module privilege drop. Both opens went straight to
`OpenOptions`, so a symlink planted at any component redirected a
privileged `O_CREAT` open to a file the operator never named. The leaf
need not exist yet, so a leaf-only `O_NOFOLLOW` could not have rejected
it either.

Upstream closes this with the same primitive it uses for every other
operator-named auxiliary file:

    connection.c:35  open_no_attacker_symlinks(fname, O_RDWR|O_CREAT, 0600)

oc already had that walk in `fast_io::owner_walk` and already routed the
daemon config, motd, secrets file, --password-file, --log-file and both
merge-file parsers onto it. The lock file was the one daemon aux-file
open left on a bare path, because no existing helper opened
`O_RDWR|O_CREAT` - so this adds `operator_open_rw_create` alongside the
existing read and append variants, all three delegating to the same
private `operator_open_with`.

The mode is upstream's, not incidental. `OpenOptions::create(true)`
requests 0666, which lands on 0644 under the common 022 umask, leaving a
shared lock file world-readable on a daemon with a permissive umask.
Upstream passes 0600 explicitly.

Two behaviour notes, both deliberate:

- The reopen per claim now carries `O_CREAT`, matching upstream's single
  `O_RDWR|O_CREAT` per `claim_connection()`. Previously a lock file
  removed after startup made every later claim fail; upstream recreates
  it. It also removes a second unguarded path resolution.

- That change invalidated the DETECTOR in
  `negative_max_connections_still_opens_the_lock_file_first`, not its
  claim. The test proves a disabled module does not short-circuit ahead
  of the open, and it detected the open by deleting the lock file. With
  `O_CREAT` a missing file is no longer an error, so the detector is now
  a DIRECTORY at the lock path, which fails EISDIR even with `O_CREAT`.
  The assertion it makes is unchanged; only the unopenable condition
  moved, and the comment says why so it is not simplified back.

Windows keeps the plain open: there is no `st_uid` to trust, matching
how the rest of the tree gates fast_io's operator-path helpers.

The new pin asserts the created mode is exactly 0600. That is
umask-independent by construction - a umask only clears bits, and 0600
has no group or other bits left to clear - so it discriminates rather
than restating the environment. RED proven by setting the constant to
0666: the test fails with `got 644`, which is precisely the pre-fix
behaviour.

daemon + fast_io: 2570 run, 2570 passed, 6 skipped (--no-fail-fast).
@github-actions github-actions Bot added the bug Something isn't working label Aug 22, 2026
The constant is read only inside the `#[cfg(unix)]` arm of
`open_lock_file`, so on Windows it is dead code. CI builds with
`-D warnings`, which turned "constant `LOCK_FILE_MODE` is never used"
into a hard error and failed all eight Windows cells - the Windows
stable/beta/nightly matrix, IOCP, ACL/xattr, daemon, the Windows
feature-flag cell and the best-effort Windows interop leg.

Reproduced locally with the windows-gnu cross-check rather than guessed
at, since `gh run view --log-failed` returns nothing on this repo:

    RUSTFLAGS="-D warnings" cargo check -p daemon \
      --target x86_64-pc-windows-gnu --all-targets
    error: constant `LOCK_FILE_MODE` is never used
      --> crates/daemon/src/daemon/module_state/connection_limiter.rs:76:7

Clean afterwards on windows-gnu and on the native target.
@oferchen
oferchen merged commit c6e5dc4 into master Aug 22, 2026
73 checks passed
@oferchen
oferchen deleted the fix/daemon-lock-file-ownership-walk branch August 22, 2026 12:43
oferchen added a commit that referenced this pull request Aug 24, 2026
…7477)

The docs were last refreshed at #7423; 55 PRs have merged since, and the
testsuite figures they quote had drifted far enough to understate the
current state by roughly half.

CHANGELOG: fill in Unreleased for everything merged since #7423. The
dominant theme is routing every operator-named auxiliary file open onto
the ownership walk - upstream's open_no_attacker_symlinks() applied at the
call sites upstream applies it - plus a daemon hardening batch and an
alt-dest correctness batch.

README and SECURITY: the per-leg outcome tables were re-derived from the
committed expect manifests rather than carried forward. Failures fell and
the corpus grew, so every figure moved:

  non-root pipe  43 -> 21 fail   (345 -> 349 corpus)
  root pipe      62 -> 29 fail   (345 -> 349 corpus)
  non-root tcp   42 -> 29 fail   (155 -> 158 corpus)
  root tcp       55 -> 38 fail   (155 -> 158 corpus)

Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55
across all four.

SECURITY, two CVE rows that had gone stale:
- CVE-2026-53790 said "under audit". The refusal has since been applied at
  the live sink - oc-rsync's own single-character config expander, which
  upstream does not have, so an upstream-shaped port alone would have been
  inert (#7465, #7430, #7445).
- CVE-2026-53795 listed only the staging family. The auxiliary-file family
  followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459,
  #7463); what remains is the per-option-family confinement.
oferchen added a commit that referenced this pull request Aug 24, 2026
…00 (#7439)

* fix(daemon): open the lock file through the ownership walk at mode 0600

`lock file = PATH` is named by the operator in oc-rsyncd.conf, and the
daemon opens it as whatever user it runs as - typically root, and before
the per-module privilege drop. Both opens went straight to
`OpenOptions`, so a symlink planted at any component redirected a
privileged `O_CREAT` open to a file the operator never named. The leaf
need not exist yet, so a leaf-only `O_NOFOLLOW` could not have rejected
it either.

Upstream closes this with the same primitive it uses for every other
operator-named auxiliary file:

    connection.c:35  open_no_attacker_symlinks(fname, O_RDWR|O_CREAT, 0600)

oc already had that walk in `fast_io::owner_walk` and already routed the
daemon config, motd, secrets file, --password-file, --log-file and both
merge-file parsers onto it. The lock file was the one daemon aux-file
open left on a bare path, because no existing helper opened
`O_RDWR|O_CREAT` - so this adds `operator_open_rw_create` alongside the
existing read and append variants, all three delegating to the same
private `operator_open_with`.

The mode is upstream's, not incidental. `OpenOptions::create(true)`
requests 0666, which lands on 0644 under the common 022 umask, leaving a
shared lock file world-readable on a daemon with a permissive umask.
Upstream passes 0600 explicitly.

Two behaviour notes, both deliberate:

- The reopen per claim now carries `O_CREAT`, matching upstream's single
  `O_RDWR|O_CREAT` per `claim_connection()`. Previously a lock file
  removed after startup made every later claim fail; upstream recreates
  it. It also removes a second unguarded path resolution.

- That change invalidated the DETECTOR in
  `negative_max_connections_still_opens_the_lock_file_first`, not its
  claim. The test proves a disabled module does not short-circuit ahead
  of the open, and it detected the open by deleting the lock file. With
  `O_CREAT` a missing file is no longer an error, so the detector is now
  a DIRECTORY at the lock path, which fails EISDIR even with `O_CREAT`.
  The assertion it makes is unchanged; only the unopenable condition
  moved, and the comment says why so it is not simplified back.

Windows keeps the plain open: there is no `st_uid` to trust, matching
how the rest of the tree gates fast_io's operator-path helpers.

The new pin asserts the created mode is exactly 0600. That is
umask-independent by construction - a umask only clears bits, and 0600
has no group or other bits left to clear - so it discriminates rather
than restating the environment. RED proven by setting the constant to
0666: the test fails with `got 644`, which is precisely the pre-fix
behaviour.

daemon + fast_io: 2570 run, 2570 passed, 6 skipped (--no-fail-fast).

* fix(daemon): gate LOCK_FILE_MODE on unix

The constant is read only inside the `#[cfg(unix)]` arm of
`open_lock_file`, so on Windows it is dead code. CI builds with
`-D warnings`, which turned "constant `LOCK_FILE_MODE` is never used"
into a hard error and failed all eight Windows cells - the Windows
stable/beta/nightly matrix, IOCP, ACL/xattr, daemon, the Windows
feature-flag cell and the best-effort Windows interop leg.

Reproduced locally with the windows-gnu cross-check rather than guessed
at, since `gh run view --log-failed` returns nothing on this repo:

    RUSTFLAGS="-D warnings" cargo check -p daemon \
      --target x86_64-pc-windows-gnu --all-targets
    error: constant `LOCK_FILE_MODE` is never used
      --> crates/daemon/src/daemon/module_state/connection_limiter.rs:76:7

Clean afterwards on windows-gnu and on the native target.
oferchen added a commit that referenced this pull request Aug 24, 2026
…7477)

The docs were last refreshed at #7423; 55 PRs have merged since, and the
testsuite figures they quote had drifted far enough to understate the
current state by roughly half.

CHANGELOG: fill in Unreleased for everything merged since #7423. The
dominant theme is routing every operator-named auxiliary file open onto
the ownership walk - upstream's open_no_attacker_symlinks() applied at the
call sites upstream applies it - plus a daemon hardening batch and an
alt-dest correctness batch.

README and SECURITY: the per-leg outcome tables were re-derived from the
committed expect manifests rather than carried forward. Failures fell and
the corpus grew, so every figure moved:

  non-root pipe  43 -> 21 fail   (345 -> 349 corpus)
  root pipe      62 -> 29 fail   (345 -> 349 corpus)
  non-root tcp   42 -> 29 fail   (155 -> 158 corpus)
  root tcp       55 -> 38 fail   (155 -> 158 corpus)

Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55
across all four.

SECURITY, two CVE rows that had gone stale:
- CVE-2026-53790 said "under audit". The refusal has since been applied at
  the live sink - oc-rsync's own single-character config expander, which
  upstream does not have, so an upstream-shaped port alone would have been
  inert (#7465, #7430, #7445).
- CVE-2026-53795 listed only the staging family. The auxiliary-file family
  followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459,
  #7463); what remains is the per-option-family confinement.
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