Skip to content

seccomp: FilterSpec type and one shared SandboxFeatures - #365

Open
congwang-mk wants to merge 2 commits into
mainfrom
seccomp-filter-spec
Open

congwang-mk wants to merge 2 commits into
mainfrom
seccomp-filter-spec

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Two refactors of the seccomp setup data structures. No behavior change intended.

Share one SandboxFeatures between the filter and the supervisor

The feature gates lived in three places: SandboxFeatures behind a one-field ResolvedSandbox wrapper, and a renamed copy of each flag on NotifPolicy. The child derived its own copy after fork to build the BPF filter while the parent derived another for the supervisor.

  • resolved.rs becomes features.rs; ResolvedSandbox is removed.
  • NotifPolicy holds one features field in place of eleven copied flags (has_memory_limit, cow_enabled, ...).
  • The features are derived once before fork and passed to the child through ChildSpawnArgs, which no longer needs sandbox_name.

Replace seccomp_plan with a FilterSpec type

seccomp_plan was a set of free functions returning a notif list, a blocklist and an argument block, which each caller stitched together by hand, and context.rs re-exported them as public wrappers.

  • seccomp_plan.rs moves to seccomp/filter.rs. FilterSpec owns the three parts and assemble() is the only way to encode them.
  • Three constructors name the filters sandlock installs: supervised, deny_only, no_supervisor.
  • The public context::notif_syscalls, blocklist_syscall_numbers, no_supervisor_blocklist_syscall_numbers and arg_filters wrappers are removed.
  • The sysinfo check moves next to the deny list it depends on, so SandboxFeatures no longer calls into the filter code and virtual_sysinfo is gone.

Tests

  • Filter unit tests move from context/tests.rs to seccomp/filter/tests.rs.
  • The two integration tests that used the removed public wrappers become unit tests there.
  • New: handler syscalls are notified exactly once; deny-only filters notify nothing.

Independent of #364 (different files).

🤖 Generated with Claude Code

The feature gates lived in three places: SandboxFeatures behind a
one-field ResolvedSandbox wrapper, and a renamed copy of each flag on
NotifPolicy. The child derived its own copy after fork to build the BPF
filter while the parent derived another for the supervisor, so nothing
tied the trapped syscalls to the handlers gated on the same facts.

Derive SandboxFeatures once before fork, hand it to the child, and embed
it in NotifPolicy in place of the copied flags.

Signed-off-by: Cong Wang <cwang@multikernel.io>
seccomp_plan was a bag of free functions returning a notif list, a
blocklist and an argument block, which every caller stitched together by
hand, and context.rs re-exported them as public wrappers. The feature
view also called back into it to learn whether sysinfo was denied.

FilterSpec in seccomp/filter.rs owns the three parts and is the only way
to assemble them. Its constructors name the three filters sandlock
installs: supervised, deny_only and no_supervisor. The sysinfo check
moves next to the deny list it depends on, so SandboxFeatures no longer
needs the blocklist.

Signed-off-by: Cong Wang <cwang@multikernel.io>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant