Only the system calls on the list
Seccomp, short for secure computing, is a Linux feature that filters the system calls a process may make. A system call is how a program asks the kernel for anything: to open a file, start a process or open a network connection.
That matters because most of a kernel's attack surface sits behind calls an ordinary program never needs. A filter that allows only the calls on a short list shuts the rest.
By the end of this lesson
Note
I can run a program under a seccomp allow-list and with its capabilities dropped.
Key words
| Word | What it means | Example |
|---|---|---|
| System call | a request from a program to the kernel | openat |
| Seccomp filter | a kernel rule deciding each system call | |
| Allow-list | only what is named is permitted | |
| EPERM | the error Operation not permitted | |
| Bounding set | the capabilities a process may ever hold | |
| no_new_privs | a flag that stops a process gaining powers |
The cells students fill in are left blank in this preview.
An allow-list refuses everything else
A filter can name the calls to refuse, a deny-list, or the calls to allow, an allow-list. An allow-list is safer: a call nobody thought of is refused by default.
The lab's profiles/python.allow names about seventy calls that python3, cat and grep need. It has no socket, so no program under it can open a network connection. sbx seccomp loads the list, refuses every other call with EPERM, then starts the command.
Go to the lab folder
cd ~/labShown here, not run. Press Start lab to type it into your own lab’s terminal.
Read the top of the allow-list
head -n 8 profiles/python.allowShown here, not run. Press Start lab to type it into your own lab’s terminal.
Read the key under the filter
sbx seccomp profiles/python.allow -- python3 agent/agent.py secretShown here, not run. Press Start lab to type it into your own lab’s terminal.
Call out under the filter
sbx seccomp profiles/python.allow -- python3 agent/agent.py callShown here, not run. Press Start lab to type it into your own lab’s terminal.
Ask the process for its seccomp mode
sbx seccomp profiles/python.allow -- grep Seccomp /proc/self/statusShown here, not run. Press Start lab to type it into your own lab’s terminal.
Try it: decide calls against a list
# A tiny model of an allow-list filter: every call not on the list is refused.
allow = ["read", "write", "openat", "close", "exit_group"]
def outcome(call):
if call in allow:
return "allowed"
return "refused with EPERM"
for call in ["openat", "read", "socket", "connect", "write", "exit_group"]:
print(call, "->", outcome(call))
# Add "socket" to allow. Which call is still refused?
A common mistake
Warning
Many people think a seccomp filter decides which files a program may read. It cannot. It sees the call and its numbers, not the text of a path behind a pointer. So the filter let the key be read: hiding files is the mount namespace's job.
Root is a bundle of capabilities
Root's power is split into about forty capabilities, such as cap_chown to change any file's owner and cap_sys_admin for mounts. The bounding set is the most a process may ever hold.
setpriv --bounding-set=-all empties it before starting a command, so even root then holds nothing. And no_new_privs stops a process gaining powers later, through sudo or a setuid program. A seccomp filter needs it, which is why sbx seccomp works without sudo.
Read root's capabilities
sudo grep CapEff /proc/self/statusShown here, not run. Press Start lab to type it into your own lab’s terminal.
Read them with the bounding set dropped
sudo setpriv --bounding-set=-all grep CapEff /proc/self/statusShown here, not run. Press Start lab to type it into your own lab’s terminal.
Make a file owned by root
sudo touch /tmp/owned-by-rootShown here, not run. Press Start lab to type it into your own lab’s terminal.
Try to give it away without capabilities
sudo setpriv --bounding-set=-all chown nobody /tmp/owned-by-rootShown here, not run. Press Start lab to type it into your own lab’s terminal.
Try sudo with no_new_privs set
setpriv --no-new-privs sudo trueShown here, not run. Press Start lab to type it into your own lab’s terminal.