{"id":270,"date":"2026-10-18T08:03:00","date_gmt":"2026-10-18T15:03:00","guid":{"rendered":"https:\/\/blog.canutethegreat.com\/?p=270"},"modified":"2026-10-08T21:44:28","modified_gmt":"2026-10-09T04:44:28","slug":"container-escape-vectors","status":"publish","type":"post","link":"https:\/\/blog.canutethegreat.com\/index.php\/2026\/10\/18\/container-escape-vectors\/","title":{"rendered":"Container Escape Vectors: A Practical Walkthrough of Namespace and Cgroup Weaknesses"},"content":{"rendered":"<p>Containers aren&#8217;t a security boundary. They&#8217;re a convenient packaging of several Linux kernel primitives that happen to produce process isolation as a side effect. Treat a container like a VM and you&#8217;ll get burned eventually. This post covers what actually enforces container isolation, two escape techniques that have shown up in production, and the mitigations worth bothering with.<\/p>\n<h2>What&#8217;s actually isolating the container<\/h2>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/10\/container-layers.png\" alt=\"Layered diagram of container isolation: namespaces, cgroups, capabilities, seccomp\" \/><\/figure>\n<p>There&#8217;s no single &#8220;container&#8221; kernel object. Docker, containerd, and friends compose four separate mechanisms.<\/p>\n<p>Namespaces partition what a process can see: pid (process tree), net (network stack), mnt (filesystem mounts), uts (hostname), ipc, and user (UID\/GID mapping). A process in a new PID namespace sees itself as PID 1 and can&#8217;t see host processes, but it&#8217;s still the same kernel, same syscall table, same vulnerabilities.<\/p>\n<p>Cgroups (v1 or v2) limit and account for resource usage: CPU, memory, I\/O, PIDs. They control resources, not confidentiality or integrity. Cgroup v1&#8217;s release_agent mechanism in particular is a privileged hook that has nothing to do with isolation and everything to do with host compromise, as we&#8217;ll see below.<\/p>\n<p>Capabilities split root&#8217;s omnipotence into roughly 40 discrete privileges (CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_SYS_PTRACE, and so on). A container running as UID 0 with a reduced capability set isn&#8217;t the same as host root, but Docker&#8217;s default set is still broad, and CAP_SYS_ADMIN alone gets you close to full root for a lot of practical purposes: mount manipulation, cgroup control, some device operations.<\/p>\n<p>Seccomp filters which syscalls a process can invoke at all, independent of capabilities. Docker ships a default profile blocking around 44 syscalls (keyctl, add_key, mount, umount2 in some paths, ptrace variants, kernel module loading, etc). Disabling it with &#8211;security-opt seccomp=unconfined is one of the most common ways people remove a real security control while chasing a build error they don&#8217;t fully understand.<\/p>\n<p>None of these four mechanisms were designed together as a sandbox. Each one closes off a slice of the host kernel&#8217;s attack surface, and the escapes live in the gaps between them.<\/p>\n<h2>Escape 1: privileged containers and \/dev access<\/h2>\n<p>docker run &#8211;privileged disables almost everything above: full capability set, no seccomp, no AppArmor or SELinux confinement, and access to host devices. If the container can see host block devices under \/dev, it can mount the host root filesystem directly:<\/p>\n<pre class=\"wp-block-code\"><code># inside a --privileged container\nmkdir \/mnt\/hostfs\nmount \/dev\/sda1 \/mnt\/hostfs\nchroot \/mnt\/hostfs \/bin\/bash\n# now you are root on the host filesystem<\/code><\/pre>\n<p>This isn&#8217;t a bug. It&#8217;s documented behavior of &#8211;privileged. But it shows up constantly anyway: CI runners, &#8220;just make it work&#8221; Kubernetes manifests, Docker-in-Docker setups that grab &#8211;privileged to avoid debugging a permissions error. The fix is never &#8220;use &#8211;privileged.&#8221; It&#8217;s finding the one or two specific capabilities or device mounts the workload actually needs (&#8211;cap-add SYS_PTRACE, &#8211;device=\/dev\/foo), which is almost always possible once you bother to check.<\/p>\n<h2>Escape 2: CVE-2019-5736, runc file descriptor overwrite<\/h2>\n<p>This one&#8217;s a genuine kernel\/runtime race, not a misconfiguration. runc versions before 1.0-rc7 (used under the hood by Docker, containerd, Kubernetes) were vulnerable to an attack where a malicious container could overwrite the host runc binary itself.<\/p>\n<p>Here&#8217;s the mechanism: when runc exec enters a running container, it briefly opens its own binary via \/proc\/self\/exe inside the container&#8217;s mount namespace, to re-exec itself with dropped privileges. A container process controls its own \/proc\/self\/exe target. Replace your own binary with a malicious ELF that, when run as the container&#8217;s entrypoint, opens \/proc\/self\/exe for writing and holds the fd open, and you can race runc into writing to that fd instead of a temp file. Since the host runc binary is mapped in during this handoff, the attacker overwrites the actual runc executable on the host with their own payload. The next container started or exec&#8217;d into on that host runs the attacker&#8217;s code as root.<\/p>\n<p>What makes this one sting is that it broke the assumption that &#8220;non-privileged container, default config&#8221; was safe against a malicious image or a compromised process. The fix was having runc copy itself to a memfd (memfd_create) and exec from there instead of touching a path on disk, which kills the overwritable target entirely. Patch your container runtime, runc, containerd, crun, on the same schedule as your kernel. Don&#8217;t treat it as an afterthought.<\/p>\n<h2>Escape 3: cgroup v1 release_agent abuse<\/h2>\n<p>Cgroup v1 supports a release_agent file: a host-side executable path the kernel invokes, as root, on the host, whenever a cgroup becomes empty. Give a container CAP_SYS_ADMIN and write access to a cgroup hierarchy&#8217;s release_agent, which happens with &#8211;privileged or with mounted cgroupfs and relaxed capabilities, and it can point that path at a script of its choosing and trigger it:<\/p>\n<pre class=\"wp-block-code\"><code>mkdir \/tmp\/cgrp &amp;&amp; mount -t cgroup -o memory cgroup \/tmp\/cgrp\nmkdir \/tmp\/cgrp\/x\necho 1 &gt; \/tmp\/cgrp\/x\/notify_on_release\nhost_path=$(sed -n 's\/.*\\perdir:\\([^,]*\\).*\/\\1\/p' \/proc\/self\/cgroup)\necho \"$host_path\/cmd\" &gt; \/tmp\/cgrp\/release_agent\necho '#!\/bin\/sh' &gt; \/cmd\necho 'ps aux &gt; \/output' &gt;&gt; \/cmd   # runs as host root\nchmod +x \/cmd\nsh -c \"echo \\$\\$ &gt; \/tmp\/cgrp\/x\/cgroup.procs\"<\/code><\/pre>\n<p>Researchers including Felix Wilhelm have written this one up extensively, and it works for a simple reason: cgroups were never an isolation mechanism. release_agent is a host-wide control hook, and a sufficiently privileged container process can just reach out and grab it. Cgroup v2&#8217;s unified hierarchy scopes release_agent differently and closes off this specific path, one of several reasons to be on v2 by now.<\/p>\n<h2>Mitigations that actually reduce risk<\/h2>\n<p>Drop capabilities aggressively. Start from &#8211;cap-drop=ALL and add back only what you&#8217;ve actually measured as needed. CAP_SYS_ADMIN, CAP_SYS_PTRACE, and CAP_SYS_MODULE have no business being default-on.<\/p>\n<p>Don&#8217;t use &#8211;privileged in production, period. A workload that &#8220;needs&#8221; it almost always needs one specific capability or device, not the entire host.<\/p>\n<p>Run containers rootless (Podman rootless, or Docker&#8217;s rootless mode). User namespace remapping maps &#8220;root&#8221; inside the container to an unprivileged UID on the host, so a full in-container compromise doesn&#8217;t hand over host root.<\/p>\n<p>Keep the runtime patched. CVE-2019-5736-class bugs live in runc, containerd, crun, not in your application code. Track your container runtime&#8217;s CVEs with the same priority you give kernel CVEs.<\/p>\n<p>Use seccomp, and don&#8217;t disable it just to make an error go away. If a syscall is genuinely blocked and genuinely needed, add it explicitly to a custom profile instead of going unconfined.<\/p>\n<p>Prefer cgroup v2, where the release_agent host-hook vector doesn&#8217;t apply the same way.<\/p>\n<p>For genuinely untrusted workloads, reach for a sandboxing runtime. gVisor (runsc) intercepts syscalls in userspace and reimplements the kernel surface; Kata Containers runs each container in a lightweight VM with its own kernel. Both add real isolation boundaries that namespaces and cgroups alone can&#8217;t provide, and the performance hit is usually worth it for multi-tenant or untrusted-input workloads.<\/p>\n<p>Every technique above has been public for years, and every mitigation here is a config change, not a research project. In my experience the gap between &#8220;container&#8221; and &#8220;isolated&#8221; is almost always one of three things: a missing &#8211;cap-drop, an unpatched runc, or a &#8211;privileged flag somebody added to make an error go away. Check those three first.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Containers aren&#8217;t a security boundary. They&#8217;re a convenient packaging of several Linux kernel primitives that happen to produce process isolation as a side effect. Treat a container like a VM and you&#8217;ll get burned eventually. This post covers what actually enforces container isolation, two escape techniques that have shown up in production, and the mitigations [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":294,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,21,7],"tags":[33],"class_list":["post-270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-security","category-technology","tag-cybersecurity"],"_links":{"self":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/comments?post=270"}],"version-history":[{"count":1,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":277,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/270\/revisions\/277"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/media\/294"}],"wp:attachment":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/media?parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/categories?post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/tags?post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}