policy_fn: drop path strings, keep argv via sibling-thread freeze (#27)#29
Merged
congwang-mk merged 3 commits intomainfrom May 1, 2026
Merged
policy_fn: drop path strings, keep argv via sibling-thread freeze (#27)#29congwang-mk merged 3 commits intomainfrom
congwang-mk merged 3 commits intomainfrom
Conversation
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
d8bb3f2 to
0b412ed
Compare
Signed-off-by: Cong Wang <cwang@multikernel.io>
This was referenced May 1, 2026
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.
Summary
Closes the dynamic-policy half of #27 —
policy_fndecisions on user-memory strings were racy because the kernel re-reads after the supervisor'sContinue. This PR makes the supported subset ofpolicy_fnsafe by construction.Two changes to the event surface:
event.pathandpath_contains()fromSyscallEvent, the FFI struct, and the Python dataclass. Path-based access control belongs in static Landlock rules (fs_read/fs_write/fs_deny), which are kernel-enforced and TOCTOU-immune.ctx.deny_path()stays for runtime additions.event.argv, but make it TOCTOU-safe. Before the supervisor sendsContinuefor anexecve/execveat, itPTRACE_SEIZE+PTRACE_INTERRUPTs every sibling thread of the calling tid (newsibling_freezemodule). The kernel's post-Continue re-read happens with no other writer running, binding the kernel's view of argv to exactly what the supervisor inspected.The freeze has effectively zero observable cost:
execve'sde_threadstep kills sibling threads anyway. Single-threaded callers (typical case) freeze nothing. On ptrace failure (e.g. YAMA blocking), the supervisor falls back to the prior Landlock-bounded behavior rather than refusing the syscall.Why ptrace is the right answer here
Considered alternatives: BPF
CLONE_THREADdeny (rejected — breaks multi-threaded users), thread-count gate (Threads==1⇒ safe ⇒ expose argv, else None — rejected as a leaky API), pure drop of argv (loses the feature). ptrace is the only option that keeps a cleanargv: Option<Vec<String>>always-populated-for-execve API. sandlock already uses ptrace incheckpoint.rs, so this isn't a new dependency; ~120 LOC in a self-contained module.Test plan
cargo test --workspace— 182 tests pass, including restoredtest_policy_fn_execve_argvandtest_policy_fn_deny_by_argvpython3 -m pytest python/tests/test_policy_fn.py— 17 tests passsibling_freezeunit testsFiles
crates/sandlock-core/src/sibling_freeze.rs(new) — freeze helpercrates/sandlock-core/src/policy_fn.rs— droppath, droppath_contains, keepargv/argv_containscrates/sandlock-core/src/seccomp/notif.rs— stop reading path; freeze siblings before Continue on execvecrates/sandlock-ffi/src/lib.rs— droppathfield fromsandlock_event_tpython/src/sandlock/_sdk.py— mirror dataclass + ctypes changes🤖 Generated with Claude Code