8000 landlock: add optional filesystem confinement derived from mount list by marhabynova · Pull Request #401 · google/nsjail · GitHub
[go: up one dir, main page]

Skip to content

landlock: add optional filesystem confinement derived from mount list - #401

Open
marhabynova wants to merge 1 commit into
google:masterfrom
marhabynova:feat/landlock-fs
Open

marhabynova wants to merge 1 commit into
google:masterfrom
marhabynova:feat/landlock-fs

Conversation

@marhabynova
Copy link
Copy Markdown

Problem

nsjail currently has no LSM layer. In configurations where mount-namespace isolation is unavailable or weakened (e.g. --disable_clone_newns or --no_pivotroot with retained capabilities), filesystem boundaries rely solely on mount/chroot setup.

Solution

Add an opt-in Landlock filesystem confinement layer (--landlock off|best_effort|required and NsJailConfig.landlock, defaulting to LANDLOCK_OFF):

  • Runtime ABI probing & graceful downgrade (landlock.cc): Probes the kernel Landlock ABI version via landlock_create_ruleset(LANDLOCK_CREATE_RULESET_VERSION) and masks handled_access_fs for ABI 1–5 without requiring newer <linux/landlock.h> headers on older build hosts.
  • Mount-derived rules: Derives LANDLOCK_RULE_PATH_BENEATH rules from NsJailConfig.mount() after contain::containProc() (so paths resolve inside the jail) and before sandbox::applyPolicy(). Honors rw, noexec, prefix_dst_env, file vs. directory targets, and comma-separated ro/rw/noexec/exec mount options tokens.
  • Failure policy: LANDLOCK_BEST_EFFORT logs a warning and continues if the kernel lacks Landlock or landlock_restrict_self() fails; LANDLOCK_REQUIRED fails closed.
  • Tests & Docs: Adds unit tests for ABI bitmask downgrade and mount-option access derivation (tests/landlock_test.cc), integration tests (tests/landlock.sh, wired into make test via test-landlock), cmdline checks (test-cmdline), and documentation in README.md / nsjail.1.

Verification

  • make -j$(nproc) nsjail tests/landlock_test && ./tests/landlock_test (passes; also verified with ASan+UBSan on landlock.cc and tests/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, noexec exec denial, --config LANDLOCK_REQUIRED)
  • clang-format --dry-run -Werror landlock.cc landlock.h tests/landlock_test.cc and git diff --check clean

Closes #375 (filesystem layer; network/scope rules can be added separately if desired).

8000

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.

Proposal: optional Landlock layer (derived from the mount list)

1 participant

0