Skip to content

RFE: tool to precompile filters #342

@vapier

Description

@vapier

one downside to libseccomp is that you have to link it into every project that wants to use it, and then generate the bpf program on the fly before it can be loaded. this is useful in some scenarios (where the filter needs are dynamic), but a common situation (in my experience in Chrome OS) is that the filter is always the same on every run. it would be nice if we could compile the filter at build time and have the runtime just load the program into the kernel and not have any libseccomp dependency at runtime at all.

i've actually built a limited proof of concept in Gentoo's pax-utils. i'll link to them here, but it's more as an FYI rather than an immediate discussion point, so please don't look too hard at them.

  • seccomp-bpf.c links against libseccomp at build time to generate the filter programs for all possible architectures.
  • seccomp-bpf.h is the generated header that is included in the program itself -- this is checked in so even people building the project don't need libseccomp, only when updating the filter.
  • security.c includes seccomp-bpf.h and calls PR_SET_SECCOMP at runtime to install the filter.

now i'm wondering if we can generalize this in libseccomp itself. while eBPF has the luxury of an LLVM backend, plain BPF does not. so i think we'd have to:

  • design a DSL for what BPF can actually support
  • add a tool to ship with libseccomp that'd parse the DSL and produce the BPF
  • the BPF can either be raw binary file, or it can generate source code ready to be included directly in projects
  • for example, as seen above, you can see seccomp-bpf.h produces a simple C header that is ready to be included, and the project only needs to make a single prctl() to load it

WDYT ? is this something we can do as part of libseccomp ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions