How does membership in the docker group allow privilege escalation to root via a bind-mounted volume and a setuid binary?
A docker-group user can start a container that bind-mounts a host directory; because container processes run as root and the mount keeps host ownership, a setuid(0) binary written there becomes a root-owned setuid file the user can execute on the host.
The chain uses two facts established earlier: a docker group member can drive the root daemon without sudo, and container processes run as root by default.
- A small C program calls
setuid(0)and thensystem(…), so running it gives a root shell. It is compiled on the host. - The user starts a container that bind-mounts a host folder (
--mount type=bind,src=$HOME/…/shared,dst=/shared). A bind mount shares the same files between host and container, keeping host ownership. - Inside the container (running as root) a script copies the binary into the shared folder and sets its setuid bit. Because the container is root, the file ends up owned by root with setuid set — and because it is a bind mount, that is true on the host too.
- Back on the host, the ordinary user runs the setuid-root binary and gets a root shell — no
sudoneeded, able to read/etc/shadow.
The root cause: "docker group = root", plus containers defaulting to root, plus a bind mount that carries root ownership onto the host filesystem. Defences: don't put untrusted users in the docker group, run containers as a non-root user, and enable user namespaces so container-root maps to a harmless host UID.
* The bind mount carries root ownership back to the host. *
Go deeper:
Wikipedia: setuid — how the setuid bit runs a binary with the owner's privileges.
Docker Docs: Docker Engine security — why the docker group is equivalent to root.