fix(landlock): tolerate missing read/exec grant paths instead of aborting#146
Closed
congwang-mk wants to merge 1 commit into
Closed
fix(landlock): tolerate missing read/exec grant paths instead of aborting#146congwang-mk wants to merge 1 commit into
congwang-mk wants to merge 1 commit into
Conversation
…ting A Landlock read/exec grant that names a path absent on the host (e.g. /lib64 on RISC-V glibc or musl, where the loader lives under /lib) made add_path_rule hard-fail the O_PATH open, which aborted confinement and took the whole sandbox launch down with it. One base policy therefore could not portably list the standard library dirs across distros and arches, and the CLI tests that grant /lib64 all failed on RISC-V. Skip such a grant with a warning rather than failing. This is security-neutral: Landlock is default-deny with allow-only rules, so an absent subtree grants nothing and skipping it leaves confinement at least as strict (a path that appears later, or a dangling symlink, resolves in the deny direction). Scope the tolerance to ENOENT on read/exec grants only: other open errors (EACCES, ...) and missing WRITE targets stay hard errors, since a caller naming a write path means it to exist. Add a unit test pinning the contract: a read grant for a missing path is skipped, a write grant for a missing path still errors.
Contributor
Author
|
Actually we have |
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
A Landlock read/exec grant that names a path absent on the host made
add_path_rulehard-fail theO_PATHopen, which aborted confinement and took the whole sandbox launch down with it:/lib64is an x86-64 glibc multilib convention. On RISC-V glibc (loader at/lib/ld-linux-riscv64-lp64d.so.1) and on musl there is no/lib64at all, so a base policy that lists the standard library dirs cannot be portable across distros/arches. Concretely, everysandlock-clitest that grants-r /lib64fails on RISC-V (11 failures), and this is the same/lib64sharp edge previously worked around in the alpine/musl policy.Fix
add_path_rulenow skips a read/exec grant whose path does not exist, with a warning, instead of failing. One base policy can then list/lib,/lib64,/usr/lib,/usr/lib64, ... and each host takes whatever subset it actually has.Scoped narrowly:
EACCES, ...) still hard-fails.(access & !READ_ACCESS) == 0). A missing write target stays a hard error, since a caller naming a write path means it to exist.Why it is security-neutral
Landlock is default-deny with allow-only rules; there are no deny rules to weaken.
add_path_ruleonly ever widens access, so skipping a grant only ever narrows it. For a nonexistent path there is nothing beneath it to grant, so the reachable-file set is identical. Adversarial cases resolve in the safe (deny) direction:O_PATHfollows to a missing target -> ENOENT -> skipped; the grant would have been for the missing target anyway.The only behavioral change is launch-time: a missing grant no longer aborts the launch; the process runs confined by a strict subset of the intended grants. It can only do less, never more.
Tests
add_path_rule_skips_missing_read_but_fails_missing_writepins the contract (both branches return before the ruleset fd is touched, so it needs no Landlock kernel support).cli_testcases and all landlock unit tests pass (/lib64exists there, so the skip branch is not even exercised). On RISC-V the previously-failing tests now pass.