feat(seccomp): ExtraHandler — user-supplied syscall handlers#20
Open
dzerik wants to merge 1 commit intomultikernel:mainfrom
Open
feat(seccomp): ExtraHandler — user-supplied syscall handlers#20dzerik wants to merge 1 commit intomultikernel:mainfrom
dzerik wants to merge 1 commit intomultikernel:mainfrom
Conversation
Adds a public extension point for downstream crates that need to
register their own seccomp-notification handlers alongside sandlock's
builtin chroot/cow/procfs/network/port_remap logic.
Motivation: downstream crates that want to intercept additional
syscalls in the same supervisor task as sandlock's builtins have no
clean way to do it today — one SECCOMP_FILTER_FLAG_NEW_LISTENER per
process means a single listener, so a second supervisor cannot run
alongside. The only alternative is forking sandlock or patching
notif::supervisor wholesale.
API:
- New type dispatch::ExtraHandler { syscall_nr, handler }.
- New entry Sandbox::run_with_extra_handlers(policy, cmd, extras).
- Existing Sandbox::run() delegates to it with empty extras — zero
behaviour change for current callers.
Ordering contract (documented + tested):
- Builtins register first (chroot path normalization, COW, procfs, …).
- Extras appended last, in the Vec order.
- Chain stops at first non-Continue — user handlers cannot subvert
builtin confinement.
Internals:
- build_dispatch_table now takes Vec<ExtraHandler> and drains it into
register() calls after builtins.
- notif::supervisor signature extended to accept extras and pass them
through. sandbox.rs moves self.extra_handlers via std::mem::take
on spawn (HandlerFn is Box<dyn Fn> — not Clone).
Docs:
- docs/extension-handlers.md: design rationale, security boundary,
panics policy, non-goals, downstream sketch.
- crates/sandlock-core/examples/openat_audit.rs: runnable example.
Tests:
- 4 unit tests on dispatch::extra_handler_tests (ctor, insertion
order, append-after-builtin, empty-extras nop). All 215 unit
tests pass.
Minor bump 0.6 → 0.7 suggested.
Signed-off-by: dzerik <dzerik@gmail.com>
5f2b730 to
71c5724
Compare
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
Adds a public extension point for downstream crates that need to register their own seccomp-notification handlers alongside sandlock's builtin chroot/cow/procfs/network/port_remap logic.
Motivation. Downstream crates that want to intercept additional syscalls in the same supervisor task as sandlock's builtins have no clean way to do it today — one
SECCOMP_FILTER_FLAG_NEW_LISTENERper process means a single listener, so a second supervisor cannot run alongside. The only alternative is forking sandlock or patchingnotif::supervisorwholesale.API.
dispatch::ExtraHandler { syscall_nr, handler }.Sandbox::run_with_extra_handlers(policy, cmd, extras).Sandbox::run()delegates to it with empty extras — zero behaviour change for current callers.Ordering contract (documented + tested).
Vecorder.Continue— user handlers cannot subvert builtin confinement.Docs.
docs/extension-handlers.md: design rationale, security boundary, panics policy, non-goals, downstream sketch.crates/sandlock-core/examples/openat_audit.rs: runnable example.Minor bump
0.6 → 0.7suggested.Test plan
dispatch::extra_handler_tests(ctor, insertion order, append-after-builtin, empty-extras nop) — passingopenat_audit.rsruns against apython3 -cguest