Seccomp
Also called System call filter, seccomp-bpf
Seccomp, short for secure computing mode, is a Linux kernel feature that lets a process turn off the system calls it does not need. The kernel then refuses those calls for that process and everything it starts. A program usually turns calls off early, once it has finished setup steps that need more of the kernel. A runtime can also do this for a program just before starting it.
Each system call runs kernel code that an attacker might exploit. Most programs need only a fraction of the calls Linux offers, so turning the rest off shrinks the part of the kernel that untrusted code can reach. A bug in a call that no sandboxed program can make is harmless to that sandbox. Default filters have blocked several known kernel exploits for exactly this reason.
Seccomp is one layer of a sandbox rather than a sandbox on its own. It works beside namespaces and control groups, and it also guards the host processes that run virtual machines. On its own it leaves the whole file system and network in view, as long as the calls that reach them are allowed. Its job is narrower, cutting down the kernel code in reach rather than hiding resources.
Filters
Seccomp filters are small programs in the classic BPF format that a process installs and the kernel runs before every system call it makes. Each filter sees the call number and the argument values. It also sees the architecture, which matters because call numbers differ between instruction sets. A filter that skips this check can be bypassed by a process that switches to another calling convention.
The filter returns a verdict, such as allowing the call or failing it with an error. Filters see arguments only as numbers, so they can check a flag but not follow a pointer to inspect a file path. Reading memory behind a pointer would also be unsafe, since another thread could change it after the check. Rules about paths therefore belong to other tools, such as security modules or a supervising process.
Filters can only be added, never removed or loosened, and every child process inherits them. Once a sandbox has installed its filter, nothing running inside it can undo it. A process without privileges must first give up the ability to gain new ones. This stops a filtered program from running a setuid binary that the filter could confuse.
| Verdict | Description |
|---|---|
| Allow | The call runs as normal. |
| Error | The call fails with an error code that the filter chooses. |
| Kill | The kernel kills the thread or the process that made the call. |
| Trap | The kernel sends the process a signal. |
| Log | The call runs and the kernel logs it. |
| User notification | A supervising process in user space decides the outcome. |
Strict and filter modes
Strict mode and filter mode are the two modes of seccomp. Strict mode, the original, allows only a handful of calls, which is too few for most programs. A process that makes any other call is killed at once. The mode was designed for renting out spare processor time to code from strangers.
Filter mode, often called seccomp-bpf, lets each program write its own allowlist. It made seccomp practical for ordinary software, and it is the mode nearly all current users run. Writing a filter by hand is error-prone, so most programs build one with a library such as libseccomp. Web browsers and many system services install filters this way.
Strict mode still suits a process that only computes on data it was handed. Such a process needs no calls beyond reading its input and writing its result. It is simple to reason about, since there is no filter to get wrong. The program must open every file and socket it needs before it switches the mode on.
| Mode | Description |
|---|---|
| Strict mode | Strict mode arrived in Linux in 2005 and allows only the read, write, exit and sigreturn calls. |
| Filter mode | Filter mode arrived in Linux in 2012 and runs a custom filter before each call. |
Profiles
Profiles are ready-made filters that a runtime applies to the programs it starts. Container runtimes apply a default profile that blocks dozens of rarely needed and risky calls, such as loading kernel modules. A default profile is a compromise, loose enough for most images to run unchanged. Operators can supply a tighter one for a program whose needs they know.
Sandboxes built on virtual machines still use seccomp around the monitor process on the host. Firecracker gives each of its threads a tight filter, so a guest that escaped into the monitor would find little of the host kernel within reach. Each thread of the monitor does one job, so its filter can allow just the calls that job needs. The system calls of the guest never reach that filter, because they go to the guest kernel.
A tight profile is brittle, because a program that makes an unexpected call fails, often with a confusing error. Seccomp also cannot fix a bug in a call it allows, so it does not replace a stronger isolation boundary. Tools can build a profile by tracing which calls a program makes in testing, but rare code paths are easy to miss. A runtime can instead send calls the profile did not foresee to a supervising process, which decides each one.