Support per-rule actions and SECCOMP_FILTER_FLAG_NEW_LISTENER loading#99
Draft
lu-zero wants to merge 1 commit into
Draft
Support per-rule actions and SECCOMP_FILTER_FLAG_NEW_LISTENER loading#99lu-zero wants to merge 1 commit into
lu-zero wants to merge 1 commit into
Conversation
SeccompRule gains an optional per-rule action overriding the filter's match_action (None preserves existing behavior). Adds new_with_action and always constructors, and apply_filter_with_listener to install a filter with NEW_LISTENER and return the listener fd. Together these make SeccompAction::UserNotif usable in hybrid filters. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
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
Make
SeccompAction::UserNotif(added in #95) usable in hybrid filters,where different syscalls take different actions in one filter.
SeccompFilterapplies a single
match_actionto every rule today; this adds per-rule actionsand a loader for
SECCOMP_FILTER_FLAG_NEW_LISTENER.Motivated by fakeroost#7,
which routes
statthrough aUSER_NOTIFpool while keeping writes onTRACE—previously requiring hand-rolled BPF. Reference port:
fakeroost#8.
Relationship to #75
#75 (colinmarc, stalled since Apr 2025) adds a
Notifyvariant + a loader butnot per-rule actions — it can't express "syscall A → Notify, syscall B → Trace"
in one filter, which is the gap this PR fills. #95 already merged
UserNotifunconditionally, superseding #75's feature-gated
Notify. Our loader(
apply_filter_with_listener) overlaps #75'sapply_filter_with_notify_fd; happyto adopt that name if preferred.
Changes
SeccompRulegainsaction: Option<SeccompAction>;Nonefalls back to thefilter's
match_action(existing usage unchanged). New constructorsnew_with_action(conditions + action) andalways(unconditional). Firstmatching rule wins;
append_syscall_chainemits the rule's ownRET.validate()relaxed: a condition-less rule is valid iff it carries an action.apply_filter_with_listener() -> Result<OwnedFd>installs withNEW_LISTENER(Linux 5.0+) and returns the listener fd. Separate from
apply_filter_with_flags(rc contract differs: positive rc = fd, not TSYNC).new_with_action(vec![], ..)now returnsErr(EmptyRule)— previously itsilently behaved like
always.SeccompAction::UserNotifis intentionally unit: the kernel ignores thereturn-data bits for
SECCOMP_RET_USER_NOTIF, so au32would be a tag itdiscards (unlike
Errno/Trace). Seedocs/design-per-rule-actions.md.Testing
New unit + integration tests for the above; 36 tests / 5 suites pass,
clippy -D warningsclean,fmtclean. fakeroost's integration suite passeson this branch (#8).
Open questions (none block this draft)
IdenticalActionsis over-strict when every rule overrides.actionfield yet (non-breaking).libc(#5224); a high-level
supervisor API would be a separate crate.
Draft to gather feedback — especially on reconciling with #75 — before
finalizing.