Skip to content

fix(daemon): validate private-directory ancestors through O_PATH handles - #3023

Open
codr1 wants to merge 1 commit into
DeusData:mainfrom
codr1:fix/landlock-private-directory-walk
Open

codr1 wants to merge 1 commit into
DeusData:mainfrom
codr1:fix/landlock-private-directory-walk

Conversation

@codr1

@codr1 codr1 commented Nov 17, 2026

Copy link
Copy Markdown

Fixes #3014

Problem

private_directory_tree_open (src/daemon/ipc.c) walks from / down to the cache or runtime directory and opens every component with O_RDONLY|O_DIRECTORY. Landlock counts that open as listing the directory. A process whose ruleset handles LANDLOCK_ACCESS_FS_READ_DIR and does not grant it on / therefore fails at the first component, and the daemon exits with "could not load saved runtime settings".

Change

Where O_PATH exists, the walk holds each component by an O_PATH handle (O_PATH|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW).

  • Every check on a component reads the handle (fstat, fstatfs), so the ownership, mode and symlink rules are unchanged.
  • fchmod does not work on an O_PATH handle, so a directory the walk created, and the final directory, are first reopened through the handle itself (openat(fd, ".", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW)). That needs the read-directory right on the private directory only, and cannot name another directory.
  • The function still returns an ordinary directory descriptor.
  • Without O_PATH the walk opens as before. On Linux a missing O_PATH is a compile error rather than a silent fallback.

One function and one helper in src/daemon/ipc.c; no interface, option or default changes.

Test

daemon_ipc_linux_private_directory_secures_inside_landlock_issue3014 in tests/test_daemon_ipc.c, modelled on the user-namespace smoke test beside it. A forked child builds a Landlock ruleset that handles READ_DIR, grants it only beneath the test's own parent directory, confirms that listing / is refused, and calls cbm_daemon_ipc_private_directory_secure on a directory that does not exist yet. The parent checks the exit code and that the directory exists, is owned by the caller and has mode 0700.

It uses SKIP_PLATFORM only where Landlock cannot exist: a non-Linux build, headers without linux/landlock.h, or a kernel that answers ENOSYS/EOPNOTSUPP to landlock_create_ruleset. A sandbox that cannot be built for any other reason is a failure.

What I ran

Machine: x86_64 Linux, kernel 6.6 (WSL2), Arch Linux userland, 24 cores, gcc 16.2.1. Base: main at cdfdf26.

  • scripts/test.sh --suites daemon_ipc with this change: 60 passed.
  • The same command with src/daemon/ipc.c put back to main and the new test kept: 59 passed, 1 failed, the new test (FAIL tests/test_daemon_ipc.c:5485, the child was refused).
  • scripts/lint.sh --ci CLANG_FORMAT=<clang-format 20.1.8> with cppcheck 2.20.0 first on PATH, the versions _lint.yml pins: passed.
  • scripts/test.sh (the full default leg): passed ("=== All tests passed ==="), 24 min 32 s; the daemon_ipc suite inside it: 60 passed, 0 failed, 0 skipped.
  • scripts/check-dco.sh origin/main..HEAD: OK.

Not run: macOS and Windows. The change is compiled out where O_PATH is not defined, and the test is compile-gated to Linux.

Developed with the aid of AI under human supervision.

private_directory_tree_open walks from "/" (or ".") down to the private
directory and opened every component O_RDONLY|O_DIRECTORY. Landlock
counts that open as listing the directory, so a process whose ruleset
handles LANDLOCK_ACCESS_FS_READ_DIR without granting it on "/" failed at
the first component, and the daemon exited with "could not load saved
runtime settings".

Where O_PATH exists the walk now holds each component by an O_PATH
handle. Every check reads the handle (fstat, fstatfs), so the ownership,
mode and symlink rules are unchanged. A handle is reopened through
itself as an ordinary directory descriptor before it is chmod'ed or
returned, which needs the read-directory right on the private directory
only. Without O_PATH the walk opens as before.

The new test runs the real path inside a Landlock domain that may list
nothing above the test's own directory. It fails without this change.

Fixes DeusData#3014

Signed-off-by: VB <7825101+codr1@users.noreply.github.com>
@codr1
codr1 requested a review from DeusData as a code owner November 17, 2026 17:12
@github-actions

Copy link
Copy Markdown

Thanks for opening this — it has been seen, and it is queued.

This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence.

Current review status: working through a backlog. 0.9.1-rc.1 is out, so the release freeze that held reviews is over — but it left a large queue of open pull requests behind it, and we are reading through them oldest-first. The background is in discussion #1144.

What that means for this PR, concretely:

  • It will not be closed for inactivity. No stale bot touches pull requests here.
  • It may still sit a while before a human reads it. That is on us, not on you.
  • Older PRs are read first, so a recent one is not being skipped — it is behind a queue.

Things that will genuinely speed it up whenever review does happen:

  • Keep it rebased on main — the tree is moving quickly right now, and a conflicting branch cannot be reviewed as the diff you intended.
  • Get CI green, or say which failures you believe are pre-existing.
  • Keep the change to one claim. Bundled features and refactors get split before they get merged, which costs you a round trip.
  • Every commit needs a sign-off (git commit -s) — CI enforces DCO.

If this fixes a bug, a reproduction we can run is worth more than a description of the symptom.

Thanks for contributing, and sorry in advance for the wait.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to skip the ancestor-directory check at startup (Landlock sandboxes)

1 participant