Fix Landlock path rules on non-directory paths (files, devices, FIFOs)#57
Merged
Conversation
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
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
Any Landlock path rule targeting a non-directory crashed child setup.
-r <regular file>and-w /dev/nullboth failed withadd path rule ...: Invalid argument (os error 22)(EINVAL), and the child died before exec.Two distinct root causes in
add_path_rule(crates/sandlock-core/src/landlock.rs):READ_ACCESScarriesREAD_DIR;write_accessalso carriesMAKE_*,REMOVE_*,REFER). The kernel rejects any access bit outside itsACCESS_FILEset (EXECUTE | WRITE_FILE | READ_FILE | TRUNCATE | IOCTL_DEV) on a non-directory with EINVAL.open()with EACCES.This also affected the GPU device rules (
/dev/nvidia*), which were silently failing because their EINVAL was swallowed bylet _ =.Fix
ACCESS_FILE. Directories are unaffected, and ABI-gated bits (TRUNCATE v3+, IOCTL_DEV v5+) are kept only if already requested.O_PATH | O_CLOEXECinstead ofO_RDONLY. O_PATH does not block on FIFOs, needs no read permission on the target, and still supportsfstat(the file-type check) and serves as a validparent_fdforlandlock_add_rule.Tests
New regression tests in
tests/integration/test_landlock.rs:test_path_rule_on_regular_file: read rule on a regular filetest_path_rule_on_device_node: write rule on/dev/null, and confirms the write actually workstest_path_rule_on_fifo_does_not_block: read rule on a FIFO, timeout-guarded so a regression fails instead of hangingAll suites pass with no regressions: 216 integration, 275 core lib, 48 FFI smoke. CLI reproduction of all four cases (regular file, device, FIFO, write-only file) now exits 0.
🤖 Generated with Claude Code