What does the --privileged flag give a container, and why is CAP_SYS_MODULE in particular so dangerous?
--privileged grants a container almost all capabilities and broad device access. CAP_SYS_MODULE lets it load kernel modules — i.e. run arbitrary code in the host kernel, escaping any container boundary.
A normal container runs with a restricted set of Linux capabilities. Starting it with --privileged removes nearly all of those restrictions — it is close to running directly on the host. Among the capabilities it gains is CAP_SYS_MODULE, the right to insert and remove kernel modules (insmod / rmmod).
Why that is catastrophic: a kernel module runs in kernel space, with full power over the machine. An attacker who already has a foothold in a --privileged container can:
- Compile a kernel module on (or copy one to) the container.
insmodit — the module loads into the host kernel (observable in the host'sjournalctl -k).- From inside that module do anything the host kernel can: every door to the host is open.
So --privileged + CAP_SYS_MODULE turns a container foothold into total host compromise. The principle to take away is least privilege: a container should hold only the exact capabilities it needs. Later sections (capabilities, seccomp) show how to drop the rest — and you should essentially never run untrusted workloads with --privileged.
Go deeper:
man7.org: capabilities(7) — every capability, including CAP_SYS_MODULE, defined precisely.
Docker Docs: docker container run — the --privileged, --cap-add and --cap-drop flags.