Skip to content

Lesson 1 of 14 · 12m

A Container Is a Process With a Broken View

Docker containers are ordinary processes lying about their view via clone() namespace flags, and /proc/<pid>/ns/ inodes prove which walls exist.

What runc actually does

When you type docker run nginx, nobody boots anything. There is no second kernel, no hypervisor, no bootloader. The daemon hands the image layers and your flags to containerd, which hands them to runc, and runc calls clone(2) — the same syscall fork() is built on — with a set of flags: CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWNET, CLONE_NEWIPC, CLONE_NEWUTS, and usually CLONE_NEWCGROUP. A container is a process the kernel is lying to.

Each flag creates one lie. CLONE_NEWPID gives the process a fresh process-number table where it is PID 1. CLONE_NEWNS gives it a private copy of the mount table, so mount and umount inside it stay invisible outside. CLONE_NEWNET gives it a network stack with nothing but lo. CLONE_NEWIPC walls off SysV shared memory and message queues. CLONE_NEWUTS lets it set its own hostname. CLONE_NEWUSER — the interesting one — remaps UIDs, so root inside can be an unprivileged user outside.

You can create all of this without Docker:

unshare --pid --fork --mount-proc bash
echo $$   # prints 1

unshare is the same clone flags behind a CLI. nsenter goes the other direction: it opens a PID's namespace file descriptors under /proc/<pid>/ns/ and calls setns(2) to join them — which is exactly what docker exec does when it slides a second process into a running container.

Every namespace a process lives in is a symlink under /proc/<pid>/ns/ named by inode:

$ readlink /proc/1/ns/net /proc/1/ns/mnt
net:[4026532008]
mnt:[4026532009]

Two processes in the same namespace share the inode number. lsns renders the whole table. This is the audit trick that matters: compare a container's /proc/<pid>/ns/* links against PID 1's on the host. Same number means same namespace, which means no wall.

The wrong model

The mental model to discard is "lightweight VM." A VM isolates by hardware virtualization: a second kernel, a second syscall table, everything mediated by a hypervisor. A container isolates by bookkeeping. The same kernel keeps a table of which process may see which mounts, PIDs, and interfaces — and the syscall surface, including every bug in it, is shared.

That inverts where the danger sits. Escaping a VM means breaking the hypervisor, which is rare and hard. Escaping a container means convincing one kernel to stop lying: either a kernel bug that does not care about namespaces, or a configuration that shares the wrong namespace or hands over the wrong capability. The configuration kind is far more common, which is why most of this course is about flags.

The namespace inventory

Linux has eight namespace types. Seven matter:

FlagNamespaceWhat it privatizes
CLONE_NEWNSmountthe mount/unmount table
CLONE_NEWPIDPIDprocess numbering and visibility
CLONE_NEWNETnetworkinterfaces, routes, firewall rules
CLONE_NEWIPCIPCSysV shared memory, semaphores, queues
CLONE_NEWUTSUTShostname and domain name
CLONE_NEWUSERuserUID/GID mappings
CLONE_NEWCGROUPcgroupview of the cgroup filesystem

CLONE_NEWTIME exists too — it virtualizes CLOCK_BOOTTIME so containers can report their own uptime — and it matters for correctness, not isolation.

chroot is notably absent. It repoints /, but the process keeps the host's mount table, PID table, and network stack. People call chrooted trees "jails." They jail almost nothing. Docker's root filesystem is a pivot_root inside a mount namespace — a real wall, not a repointed pointer.

What to actually do

Learn the three tools before you need them: unshare to create, nsenter to enter, lsns and readlink /proc/<pid>/ns/* to inspect. When you audit a workload, check the namespace links first. If a container shares the host's net, pid, or ipc inode, every escape technique in the next module applies to it before you look at anything else.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.