Repository navigation
Conversation
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>
|
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. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
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
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.
Fixes #3014
Problem
private_directory_tree_open(src/daemon/ipc.c) walks from/down to the cache or runtime directory and opens every component withO_RDONLY|O_DIRECTORY. Landlock counts that open as listing the directory. A process whose ruleset handlesLANDLOCK_ACCESS_FS_READ_DIRand 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_PATHexists, the walk holds each component by anO_PATHhandle (O_PATH|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW).fstat,fstatfs), so the ownership, mode and symlink rules are unchanged.fchmoddoes not work on anO_PATHhandle, 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.O_PATHthe walk opens as before. On Linux a missingO_PATHis 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_issue3014intests/test_daemon_ipc.c, modelled on the user-namespace smoke test beside it. A forked child builds a Landlock ruleset that handlesREAD_DIR, grants it only beneath the test's own parent directory, confirms that listing/is refused, and callscbm_daemon_ipc_private_directory_secureon 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_PLATFORMonly where Landlock cannot exist: a non-Linux build, headers withoutlinux/landlock.h, or a kernel that answersENOSYS/EOPNOTSUPPtolandlock_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:
mainat cdfdf26.scripts/test.sh --suites daemon_ipcwith this change: 60 passed.src/daemon/ipc.cput back tomainand 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 onPATH, the versions_lint.ymlpins: passed.scripts/test.sh(the full default leg): passed ("=== All tests passed ==="), 24 min 32 s; thedaemon_ipcsuite 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_PATHis not defined, and the test is compile-gated to Linux.Developed with the aid of AI under human supervision.