Skip to content

Lesson 3 of 14 · 10m

cgroups Are a Meter, Not a Wall

cgroups count and throttle resources; they never isolated anything except device access — and their release_agent feature became an escape.

What a cgroup does

docker run --memory=512m --cpus=1.5 nginx does not build a smaller room for nginx. It enrolls the container's processes in a cgroup — a kernel accounting structure — and writes numbers into files. Under cgroup v2 the files live in the unified tree at /sys/fs/cgroup: memory.max, cpu.max, io.max, pids.max. Exceed memory.max and the OOM killer fires inside that cgroup only, which is exactly the blast radius you want.

Notice what just happened: the kernel started counting. Nothing about cgroups prevents a process from making a syscall, opening a file it has permission to open, or touching a device it has been granted. A container pinned to 512 MB and one CPU can reach every syscall the kernel exposes, because limits say nothing about reachability. Resource controls are meters and throttles. They are not walls.

This distinction matters because people routinely file cgroups under "isolation" in their heads. The one counterexample was cgroup v1's devices controller, which maintained per-cgroup allow/deny lists for device nodes — devices.allow and devices.deny in /sys/fs/cgroup/devices. That controller did gate something real: Docker's default device list is why mknod inside a container creates a node you still cannot open. In cgroup v2 the mechanism moved to eBPF — a BPF_PROG_TYPE_CGROUP_DEVICE program attached to the cgroup — but the idea is the same: the only cgroup that ever enforced security was the one that wasn't about resources at all.

v1 vs v2

Cgroup v1 shipped as a pile of separate hierarchies — /sys/fs/cgroup/memory, /sys/fs/cgroup/cpu, /sys/fs/cgroup/devices, each mounted independently. Cgroup v2 replaced it with one unified tree where controllers attach to the same hierarchy via cgroup.controllers and cgroup.subtree_control. Hosts have been migrating for years; Docker, containerd, and Kubernetes all speak v2 now. You will still meet v1 on older kernels and in old documentation, and one specific v1 feature matters for escapes — keep reading.

The cgroup that was a door

Cgroup v1 had a feature called notify_on_release. Set it on a cgroup, write a path into the hierarchy's release_agent file, and when the last task exits that cgroup the kernel runs the named binary — as root, on the host, in the host's namespaces. It was designed so a cgroup manager could clean up after dead tasks.

The bug — CVE-2022-0492, disclosed February 2022 — was that a process able to mount cgroupfs could create a cgroup, mark it notify_on_release, write release_agent, spawn a task, let it exit, and collect host code execution. Inside an unprivileged container you can't mount cgroupfs. Inside a privileged one — or any container with CAP_SYS_ADMIN, or any container where /sys/fs/cgroup got bind-mounted writable — you could, and did.

Unit 42 used exactly this primitive for Azurescape in September 2021: Azure Container Instances scheduled customer containers onto shared Kubernetes nodes with the host's cgroup v1 filesystem reachable and writable, so a customer container emptied a cgroup and had the kernel execute its release_agent on the node. Cross-tenant, first of its kind on a public cloud. Microsoft rearchitected ACI onto per-tenant isolation afterward. The kernel fix for CVE-2022-0492 landed in the 5.17 era: writing release_agent now requires CAP_SYS_ADMIN in the initial user namespace (cgroup_release_agent_write), which closes the userns-flavored variant of the same trick.

What to actually do

Set memory.max-equivalent limits (--memory, --cpus) because resource starvation is a real DoS path — an unlimited container that eats all RAM drags the host's OOM killer into host processes, not just its own. But write it down correctly in your threat model: limits buy you availability, not isolation. And treat any writable cgroupfs mount, any CAP_SYS_ADMIN grant, and anything --privileged as "can execute code on the host," because release_agent already proved that exact chain in production.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.