CSE Roadmap

Common tier · about 3 hours · 7 parts

Part 4 of 7 · 2 min read

seccomp

Think of a switchboard operator who connects only calls to approved numbers. A call to a forbidden number gets a busy signal, and the caller learns nothing more. The analogy stops in one place: the operator reads one number at a time, while a filter also reads the arguments of the call that the program makes.

In plain words: seccomp (secure computing mode) lets a process install a small filter program into the kernel. After that, every system call of the process, and of its children, first runs through the filter, which answers with an action: allow the call, fail it with a chosen error number, or kill the process. The filter is written in a restricted language called BPF. It sees the system call number and its arguments. Once installed, the filter cannot be removed, and with no_new_privs set (page 4) an unprivileged process may install one. This shrinks the part of the kernel that an attacker can reach, since a system call that is blocked cannot be used.

A worked example. The second half of the program in section 2 installs a filter with four instructions: load the system call number; if it equals SYS_openat, return the error EPERM; otherwise allow. The result:

seccomp filter     open: Operation not permitted
write still works

open now fails with Operation not permitted for a process that is root and could open the file a moment before. write still works, because the filter allowed it. The kernel never ran the real openat. A stricter sandbox would list the few calls that are allowed and kill the process on any other.

The key lines. A filter reduces the attack surface: the set of kernel entry points that a taken-over process can try. Docker, web browsers and system services use seccomp filters by default.

seccomp

seccomp (secure computing mode) is a Linux facility that lets a process install a filter that decides, for each system call it makes, whether to allow it, return an error, or kill the process. A filter, once installed, cannot be removed.

Example: a filter that returns EPERM for openat and allows all other calls.

Common mistake

A filter that blocks open but not openat blocks nothing, because libraries call openat. Block the whole family of calls, or use an allow list.

Check yourself: 1. What three kinds of answer can a seccomp filter give? 2. Why can an unprivileged process install a filter only after no_new_privs? 3. What is an attack surface?