KERNELSECCOMPoffcat.pngalice: rw-/etc/shadowothers: ---.ssh/id_rsaalice: rw-KERNEL ONLYKERNEL ONLY1fd = open("cat.png", O_RDONLY);2open("/etc/shadow", O_RDONLY);3prctl(PR_SET_SECCOMP, 1);4read(fd, buf, 64);5open(".ssh/id_rsa", O_RDONLY);UID · alice10003-164
Back: the kernel's side (kernel, seccomp filter, files with owners and bits)Front: the user's side (your program and its credentials)Tokens: system calls crossing the gate, the kernel's answers, a call stopped at the filterThe kernel's side at the back: the kernel, the seccomp filter right behind the gate, and three files with their owners and permission bits. The user's side in front: the program and its credentials, user ID 1000 (alice). Line 1 opens cat.png and gets fd 3; line 2 is refused /etc/shadow; line 3 turns the filter to strict; line 4's read passes; line 5's open is stopped at the filter and the kernel ends the program with SIGKILL. Strict mode is the oldest and bluntest seccomp mode. Real sandboxes (browsers, container runtimes, systemd services) use filter mode: a small BPF program that can allow, refuse with an error code, or kill, call by call. Its filters are inherited by child processes and survive execve.

The kernel checks

  1. Protection means each program may touch only what it is allowed to. Every request a program makes enters the kernel through the system call gate, so the kernel can check each one. Our program opens an image, cat.png, and reads it.

Least privilege

Breaking out

What happens

;; step 1/10 · isolation
protection    each program touches only what it may
the gate      every request is a system call
the kernel    checks every request, every time
              ("complete mediation", OSTEP ch. 53)

the program (C99, Linux):

#include <fcntl.h>
#include <sys/prctl.h>
#include <unistd.h>

int main(void) {
    char buf[64];
    int fd;
    fd = open("cat.png", O_RDONLY);
    open("/etc/shadow", O_RDONLY);
    prctl(PR_SET_SECCOMP, 1);
    read(fd, buf, 64);
    open(".ssh/id_rsa", O_RDONLY);
    return 0;
}

The card shows the five lines of main() that matter; the whole program is real C99 for Linux. The 1 in prctl() is SECCOMP_MODE_STRICT from <linux/seccomp.h>. Line 5 stands for code an attacker slipped in through a bug; it is written plainly so the example runs. Strict mode is the oldest and bluntest seccomp mode. Real sandboxes (browsers, container runtimes, systemd services) use filter mode: a small BPF program that can allow, refuse with an error code, or kill, call by call. Its filters are inherited by child processes and survive execve.