Sub topic 6
How seccomp filters system calls
This chapter assumes you can run containers with docker run, read simple JSON, and know that a process asks the Linux kernel to do work through system calls. It covers how seccomp works. The next chapter covers choosing and writing profiles.
Why filter system calls
Containers share the host kernel. Every system call a contained process can make is a door into that kernel. Linux has several hundred system calls, and a typical web service uses a small fraction of them. A bug in a rarely used call, such as a flaw in how the kernel handles an obscure option, is only reachable if the process is allowed to make that call.
Seccomp (secure computing mode) is a kernel feature that lets you attach a filter to a process. The kernel checks each system call against the filter before running it. Capabilities limit what a privileged call may do. Seccomp limits which calls can be made at all.
How the filter works
Seccomp in filter mode uses a small program written in Berkeley Packet Filter (BPF) bytecode. The container runtime builds this program from a profile and loads it into the kernel before your application starts. After that, three rules apply:
- The filter runs on every system call the process makes.
- Child processes inherit the filter.
- The process cannot remove the filter or loosen it. It can only add stricter filters.
For each call, the filter returns an action. The ones you will meet most often are:
| Action | Effect |
|---|---|
| `SCMP_ACT_ALLOW` | The call runs normally. |
| `SCMP_ACT_ERRNO` | The call does not run. The process receives an error, usually `EPERM` (operation not permitted). |
| `SCMP_ACT_KILL` | The kernel terminates the process. |
| `SCMP_ACT_LOG` | The call runs and the kernel logs it. Useful when building a profile. |
A profile also sets a defaultAction, which applies to any call the profile does not list. An allow-list profile uses a default of SCMP_ACT_ERRNO and names the calls it permits. A deny-list profile uses a default of SCMP_ACT_ALLOW and names the calls it blocks.
Seeing the filter in action
Docker applies a default seccomp profile to every container unless you change it. You can see that a filter is active by reading the process status.
docker run --rm alpine grep Seccomp /proc/self/statusThe output includes Seccomp: 2. The value means:
0: seccomp is off for this process.1: strict mode, which allows only a handful of calls. Rarely used.2: filter mode. A BPF filter is loaded.
Now compare with a container that has the filter turned off:
docker run --rm --security-opt seccomp=unconfined alpine grep Seccomp /proc/self/statusThis prints Seccomp: 0. Use unconfined only to test whether seccomp is the cause of a failure. Do not leave it in place.
What a blocked call looks like
A blocked call does not produce a seccomp-specific message. The process just sees a failed call. With SCMP_ACT_ERRNO, a program typically reports Operation not permitted. This looks the same as a missing capability or a file permission problem, which makes seccomp failures easy to misdiagnose.
Some clues help you tell them apart:
- The same command works as root with all capabilities but still fails, or it works with
seccomp=unconfined. - The failing program reports
EPERMon a call that does not involve files or privileges, such as a newer call that the profile does not know about. - With
SCMP_ACT_KILL, the process dies with a signal (exit code 159 forSIGSYSin a shell) and no error message.
Seccomp is also separate from capabilities. A call can be blocked by seccomp even if the process holds every capability, and a call can be allowed by seccomp but still refused because a capability is missing. Both checks must pass.
What the default profile does
Docker's default profile is an allow-list that permits most common calls and blocks about 44 of the several hundred available, including calls for loading kernel modules, changing the system clock, and mounting filesystems. It is a compromise: broad enough that most applications run unchanged, narrow enough to remove well-known risky calls. Kubernetes calls the equivalent setting RuntimeDefault, which uses the container runtime's default profile.
Exercise
A container runs mkdir /data/new and fails with "Operation not permitted". Running the same container with --security-opt seccomp=unconfined makes the command work. What does this tell you, and why is unconfined a poor fix?
Show answer
It shows that the seccomp filter is blocking the system call behind mkdir, not file permissions or capabilities. Unconfined removes the filter for every call, which restores the full kernel attack surface. A better fix is a profile that allows only the call the application needs.