The kernel checks
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.
Each process carries credentials: here user ID 1000, alice. Each file records an owner and permission bits that say who may read or write it. The kernel compares the two on every open.
open() traps into the kernel. alice owns cat.png and the owner may read it, so the kernel opens it and hands back file descriptor 3, a small number that now stands for this open file.
/etc/shadow holds password hashes. It belongs to root, and other users get no read bit. alice is neither, so the kernel refuses: open() returns -1 with the error EACCES. The program is told no and carries on.
Least privilege
cat.png came from the internet. If a bug in the image code lets crafted bytes take over the program, the attacker runs as alice, with every right alice has, including her private key. Least privilege says: keep only the rights you need.
prctl() turns on seccomp strict mode, a filter the kernel runs on every system call this thread makes from now on. Only four calls pass: read, write, _exit and sigreturn. Any other call, even one to undo it, is fatal.
read is on the list, so the call passes the filter. Then the usual checks run: fd 3 is open for reading. The kernel copies the first 64 bytes of cat.png into buf. Honest work still works.
Breaking out
Now suppose the attacker's code runs and asks for alice's private key. open() becomes the openat system call, which is not on the list. The filter stops it at the door, before any file lookup or permission check.
In strict mode the penalty for a call off the list is death: the kernel sends SIGKILL and the process ends. The key was never opened, even though alice's own permission bits would have allowed it.
Protection comes in layers. The CPU's modes guard the kernel, credentials guard each user's files, and a sandbox shrinks one program's rights further. Containers and virtual machines add bigger walls around whole groups of programs.
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.