Skip to content

Lesson 6 of 14 · 11m

--privileged Means Host

Privileged mode disables capabilities, seccomp, MAC, and the device filter all at once, making escape a menu instead of an exploit.

What --privileged actually flips

docker run --privileged is not a stronger container. It is the isolation switches turned off in one flag:

  • All capabilities added. The bounding set goes from fourteen to everything — CAP_SYS_ADMIN, CAP_SYS_MODULE, CAP_SYS_PTRACE, CAP_DAC_READ_SEARCH, CAP_SYS_RAWIO, CAP_NET_ADMIN, CAP_SYS_BOOT.
  • Seccomp off. The syscall allowlist is replaced with unconfined. mount, bpf, init_module, keyctl — all reachable.
  • AppArmor and SELinux off. Docker's docker-default AppArmor profile and any SELinux confinement drop away.
  • All host devices. The cgroup device filter opens wide — every device node the host knows can be created and opened. /dev inside the container can be populated with real nodes for the host's block devices, kvm, /dev/mem where it exists.
  • Writable /sys and /proc/sys. Sysctl knobs and kernel filesystems become writable.

The mental model to attack is "privileged is like sudo inside the container." Sudo changes who the process is. --privileged changes what the kernel enforces. A privileged container is host code with extra bookkeeping.

Three exits, pick one

Given a privileged container, the escapes are a menu:

Mount the host. The device filter is open, so the host's disks exist:

mknod /dev/sda b 8 0 && mount /dev/sda /mnt

The release_agent trick. CAP_SYS_ADMIN mounts cgroupfs; on a cgroup v1 host, write a path to release_agent, set notify_on_release on a cgroup you made, run a task, let it exit — the kernel executes your binary on the host. This is the CVE-2022-0492 primitive and the core of Azurescape, where Unit 42 crossed from a customer container to the shared ACI node in September 2021. The kernel fix (writing release_agent requires CAP_SYS_ADMIN in the init user namespace) closes the user-namespace route — it does nothing for a privileged container, which holds real CAP_SYS_ADMIN.

A kernel module or BPF program. CAP_SYS_MODULE + init_module, or bpf(2) with the syscall unblocked. Either is arbitrary host code in ring 0.

Notice the shape: none of these are clever. Privileged mode is not an escape that requires finding; it is a container that was never closed.

Why the flag exists at all

The honest reasons are narrow. Docker-in-Docker CI builders needed to mount overlay filesystems and manage inner cgroupfs — the classic DinD justification. GPU and device workloads want specific /dev nodes. Some storage daemons genuinely mount filesystems. Kubernetes carries the same flag as securityContext.privileged: true, and plenty of daemonset YAML in the wild sets it because an author didn't want to enumerate capabilities.

The wrong reasons dominate: "the app needed to bind a port" (that's NET_BIND_SERVICE), "it needed to write somewhere" (a volume), "it wouldn't start otherwise" (find the denied syscall or missing cap, don't remove all of them).

The debugging recipe for "won't start unprivileged" is short: run it with seccomp logging or strace, look at the EPERM/EACCES, identify the one syscall or capability, and grant that. A storage daemon wanting mount needs SYS_ADMIN alone — still dangerous, but one dangerous bit with a reason attached beats forty bits with none. If the workload's requirement list grows past two or three capabilities, that is the workload telling you it isn't a container workload — it wants a host agent, a VM, or sysbox.

What to actually do

Never run untrusted code privileged — under that constraint the flag is just remote code execution on your node with extra YAML. When a workload legitimately needs a slice, grant the slice: --cap-add=SYS_ADMIN, --device=/dev/kvm, a specific bind mount. Audit what exists with docker inspect --format '{{.HostConfig.Privileged}}' across running containers, and grep manifests for privileged: true. If you find one, the follow-up question is not "is this safe" but "which capability did they actually need."

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.