Lesson 10 of 19 · 20m
The Kernel Is Shared: Namespaces, --privileged, and Escape Bugs
A container is six namespace filters on a shared kernel — --privileged removes most of them, and runc, containerd, and kernel CVEs have already walked through the rest.
A container is not a small VM. It is a process running on the same kernel as everything else on the host, behind a set of namespace filters that control what it can see. When the filter has a gap — or you open one with a flag — there is no hypervisor to catch you. There is only the kernel, and the kernel is shared.
What the boundary actually is
Linux has eight namespace types. A default Docker container gets six of its own: mount, PID, network, UTS (hostname), IPC, and cgroup. What it does not get is a user namespace — container uid 0 is host uid 0 unless you remap it — or a time namespace. Layered on top of the namespaces are the other half of the boundary you met in the capabilities lesson: the capability set, the default seccomp profile, and AppArmor/SELinux. Every syscall your container makes is serviced by the host's one kernel. That is the whole mechanism. The isolation is a view, not a wall.
--privileged is not a dial
People reach for --privileged as if it were a performance mode. It grants all capabilities — including CAP_SYS_ADMIN, the capability mount() lives behind — opens every host device through the cgroup device controller, and turns off the default seccomp profile and AppArmor confinement. What remains is the mount namespace and the PID namespace, and with all devices plus CAP_SYS_ADMIN those are bookkeeping. A privileged container can mount the host filesystem, poke at host disks, and load kernel modules. Call it what it is: host root with extra steps.
Two flags open similar holes quietly: --pid=host shares the host PID namespace, so the container sees and signals every process on the host; --network=host shares the host network namespace, which is how you reach sockets that never appear in /proc/net — including the containerd shim's abstract Unix sockets.
The escapes that already shipped
- CVE-2019-5736 (runc): an attacker-controlled container overwrote the host's
runcbinary through/proc/self/exeduringdocker exec— run a command inside a hostile container, and runc ran attacker code as host root. Fixed in runc 1.0.0-rc7 and Docker 18.09.2, February 2019. - CVE-2024-21626 (runc): a leaked file descriptor let a container whose
WORKDIRpointed at the inherited fd walk into the host filesystem. Fixed in runc 1.1.12, January 2024. The same bug family reached BuildKit builds. - CVE-2020-15257 (containerd): the shim listened on an abstract Unix socket — no filesystem path, no netns boundary — so any container on
--network=hostcould drive the shim and escape. Fixed in containerd 1.3.9 and 1.4.3. - CVE-2022-0847 (Dirty Pipe): a kernel bug, not a container bug — any process that could
splice()a readable file could overwrite its page cache, including read-only files. Every container on the host shared that kernel, which is the point of this lesson.
Read the pattern: none of these were misconfigurations. They were daemon and kernel bugs, and the mitigation was apt upgrade runc, not a flag. Keeping the daemon current is a security control.
The boundary Docker does not use by default
--userns-remap maps the container's root to an unprivileged high uid on the host — container root becomes, say, host uid 165536. A breakout lands as nobody. The reason it is not default is cost, not ideology: bind-mounted volumes arrive with host ownership, so your app files are suddenly owned by a uid your container root cannot read until you chown the outside. Rootless Docker and podman go further and run the daemon itself unprivileged — socket compromise is no longer host compromise — at the price of some networking and cgroup features that assume a root daemon.
Try this
docker run --rm --privileged debian:12 bash -c 'ls /dev | head; capsh --print | grep Current' — then read the capability list against the default set. For the user-namespace gap: docker run --rm alpine id -u says 0, and so does ps -o uid= for the host process Docker spawned. Same number. Same kernel.
Field notes
- Audit a running fleet with
docker inspect --format '{{.HostConfig.Privileged}} {{.HostConfig.PidMode}} {{.HostConfig.NetworkMode}}'—Privileged: true,PidMode: host, orNetworkMode: hosteach deserve a written justification. CAP_SYS_ADMINalone is most of the escape surface; never--cap-add SYS_ADMINwithout the same scrutiny you would give--privileged.- Kubernetes
privileged: trueis this same flag wearing YAML. - User namespaces are also what rootless runtimes rely on —
/etc/subuidand/etc/subgidhold the host-side mapping ranges. - The kernel bug class does not care about your Dockerfile.
unattended-upgradeson the host is container security work.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.
PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...
Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works
Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.
What is Kubernetes? Container Orchestration at Scale
Kubernetes runs your Docker containers across a cluster of machines, handles scheduling, health checking, rolling deployments, auto-scaling, and self-healing. When your application outgrows a single server, Kubernetes is how it runs on ten.
What is Docker? Containers, Images, and Why Every Developer Needs to Know This
Docker packages your application and everything it needs to run into a container that behaves identically on your laptop, your teammate's machine, and the production server. "It works on my machine" stops being a problem. Here is how it actually works and what production usage looks like.