Repository navigation
landlock: add optional filesystem confinement derived from mount list - #401
Open
marhabynova wants to merge 1 commit into
Open
marhabynova wants to merge 1 commit into
marhabynova wants to merge 1 commit into
Conversation
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.
Problem
nsjail currently has no LSM layer. In configurations where mount-namespace isolation is unavailable or weakened (e.g.
--disable_clone_newnsor--no_pivotrootwith retained capabilities), filesystem boundaries rely solely on mount/chroot setup.Solution
Add an opt-in Landlock filesystem confinement layer (
--landlock off|best_effort|requiredandNsJailConfig.landlock, defaulting toLANDLOCK_OFF):landlock.cc): Probes the kernel Landlock ABI version vialandlock_create_ruleset(LANDLOCK_CREATE_RULESET_VERSION)and maskshandled_access_fsfor ABI 1–5 without requiring newer<linux/landlock.h>headers on older build hosts.LANDLOCK_RULE_PATH_BENEATHrules fromNsJailConfig.mount()aftercontain::containProc()(so paths resolve inside the jail) and beforesandbox::applyPolicy(). Honorsrw,noexec,prefix_dst_env, file vs. directory targets, and comma-separatedro/rw/noexec/execmountoptionstokens.LANDLOCK_BEST_EFFORTlogs a warning and continues if the kernel lacks Landlock orlandlock_restrict_self()fails;LANDLOCK_REQUIREDfails closed.tests/landlock_test.cc), integration tests (tests/landlock.sh, wired intomake testviatest-landlock), cmdline checks (test-cmdline), and documentation inREADME.md/nsjail.1.Verification
make -j$(nproc) nsjail tests/landlock_test && ./tests/landlock_test(passes; also verified with ASan+UBSan onlandlock.ccandtests/landlock_test.cc)make test-cmdline test-landlock(9/9 cmdline checks pass; 11/11 Landlock checks pass on Linux 7.2.8: unmounted path denial, RO write denial, RW write allow,noexecexec denial,--configLANDLOCK_REQUIRED)clang-format --dry-run -Werror landlock.cc landlock.h tests/landlock_test.ccandgit diff --checkcleanCloses #375 (filesystem layer; network/scope rules can be added separately if desired).