Support per-rule actions and SECCOMP_FILTER_FLAG_NEW_LISTENER loading - #99
Support per-rule actions and SECCOMP_FILTER_FLAG_NEW_LISTENER loading#99lu-zero wants to merge 2 commits into
Conversation
|
I like the idea of being able to specify specific actions for different rules but I think this commit is overloaded with too many disparate changes. Please split the work. |
SeccompRule gains an optional per-rule action overriding the filter's match_action (None preserves existing behavior). Adds new_with_action and always constructors; append_syscall_chain emits the rule's own RET. validate() is relaxed: a condition-less rule is valid iff it carries an action. This is the core feature split out of the combined per-rule-actions + NEW_LISTENER change; the UserNotif-specific loader follows separately. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
|
Please make the CI pass. |
Installs a filter with NEW_LISTENER (Linux 5.0+) and returns the listener fd as an OwnedFd, making SeccompAction::UserNotif usable. Separate from apply_filter_with_flags because the seccomp(2) rc contract differs: a positive rc is the listener fd, not a TSYNC-offending tid. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
|
It should be fine now |
|
Is there anything needed to change? |
|
Seems sensible but I wouldn't bundle it with the changes for supporting Also, I'd like to see some integration tests as well for the per-rule actions |
|
Do you prefer a PR per-commit? I'll prepare them and add some more tests. |
not neccessarily one commit per PR but I'd rather have them bundled only if they are related in some way. These are completely different features |
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.