Processes, namespaces and cgroups
What a process exposes through /proc, how namespaces, cgroups, seccomp and capabilities combine into a container, and why a shared kernel means container isolation is weaker than a VM.
01Processes and what /proc reveals
- Explain what a process exposes to other users through
/procandps - Name the eight namespace types and what each isolates
- Explain what cgroups v2 and seccomp add to isolation
- Describe how containers are built from these parts and the usual container escape routes
A process is a running program with an address space, open file descriptors, credentials and a parent. The kernel publishes a great deal about each one under /proc/<pid>. Some of it is readable by every local user, which matters on shared hosts and in incident response alike.
| Path | Contents | Who can read it by default |
|---|---|---|
/proc/<pid>/cmdline | Full command line | Every user, so passwords passed as arguments leak through ps |
/proc/<pid>/environ | Environment variables at start | Owner and root only |
/proc/<pid>/status | UIDs, GIDs, capability sets, seccomp mode | Every user |
/proc/<pid>/maps, mem | Memory layout and contents | Owner and root, further limited by ptrace rules |
/proc/<pid>/exe, fd/ | Binary and open files | Owner and root; useful for finding deleted malware still running |
- Never put secrets on the command line. Pass them in a file with tight permissions, through stdin or from a secrets agent.
- `hidepid=invisible` (older name
hidepid=2) as a mount option on/prochides other users' processes entirely on multi-user systems. - Forensics: a binary deleted after launch still runs, and
/proc/<pid>/exestill points at it.ls -l /proc/*/exe 2>/dev/null | grep deletedis a classic triage check.
02Namespaces: giving a process its own view
A namespace wraps a global resource so that processes inside see their own instance of it. Namespaces do not add permission checks; they change what a process can name. A process in a new PID namespace cannot signal host processes because it cannot see them at all.
| Namespace | Isolates | Added |
|---|---|---|
| mount | Mount table: what the filesystem looks like | 2.4.19 (2002), the first |
| UTS | Host name and domain name | 2.6.19 |
| IPC | System V IPC and POSIX message queues | 2.6.19 |
| PID | Process ID numbers; the first process is PID 1 inside | 2.6.24 |
| network | Interfaces, routes, firewall rules, sockets | 2.6.29 |
| user | UID and GID mappings, and capabilities relative to the namespace | 3.8 |
| cgroup | View of the cgroup hierarchy | 4.6 |
| time | Boot and monotonic clock offsets | 5.6 |
# As an ordinary user: new user, PID and mount namespaces
$ unshare --user --map-root-user --pid --fork --mount-proc bash
# id
uid=0(root) gid=0(root) groups=0(root) # root inside the namespace...
# ps -e
PID TTY TIME CMD
1 pts/0 00:00:00 bash # ...and only its own processes are visible
# cat /etc/shadow
cat: /etc/shadow: Permission denied # ...but still uid 1000 to the host's filesUser namespaces are the clever and the risky part. They let an unprivileged user be root inside a namespace, with capabilities that apply only to resources that namespace owns. That enables rootless containers. It also exposes kernel code paths that used to need real root (mounting certain filesystems, creating network devices) to every local user, and a stream of kernel privilege escalations has gone through exactly that door. Several distributions now restrict unprivileged user namespace creation by default, for example Ubuntu through AppArmor since 23.10.
03cgroups, seccomp and the other layers
Control groups (cgroups) limit and account for resources: CPU, memory, I/O and the number of processes. Modern distributions use the unified cgroups v2 hierarchy. A cgroup is not an access-control boundary, but it stops one workload from starving the host: pids.max defeats fork bombs and memory.max keeps a leak from triggering the host's OOM killer on something important.
seccomp (secure computing mode) filters system calls. A seccomp-BPF filter inspects each syscall number and its arguments and allows, denies or kills. Because most kernel exploits need an unusual syscall somewhere (keyctl, bpf, userfaultfd, unshare), a tight filter removes large parts of the kernel's attack surface. Docker's default profile blocks around 44 syscalls; Kubernetes applies the runtime default only when you set seccompProfile: RuntimeDefault.
# Kubernetes: the baseline every workload should start from
securityContext:
runAsNonRoot: true
runAsUser: 10001
allowPrivilegeEscalation: false # sets no_new_privs
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault04Why containers are weaker than VMs, and how escapes happen
Every container on a host shares one kernel. A virtual machine has its own kernel behind a hypervisor with a much smaller interface. So a kernel bug reachable from inside a container, such as Dirty Pipe (CVE-2022-0847, which let unprivileged processes overwrite read-only files), is a host compromise. Most real escapes, though, are configuration rather than zero-days.
| Escape route | Why it works | Fix |
|---|---|---|
--privileged | All capabilities, all devices, no seccomp: mount the host disk | Never in production; grant the one capability needed |
| Docker socket mounted in | /var/run/docker.sock lets the container ask the daemon for a new privileged container | Do not mount it; use a narrow API or rootless builders |
hostPath: / or hostPID | Direct access to host files or processes | Pod Security Admission restricted profile |
CAP_SYS_ADMIN or CAP_SYS_PTRACE | Mount tricks, cgroup release agents, process injection | Drop ALL, add back only what is justified |
| Runtime bugs | runc CVE-2019-5736 (overwrite host runc), CVE-2024-21626 (leaked directory descriptor) | Patch the runtime and the kernel promptly |
Without a user namespace, UID 0 in a container is UID 0 to the host kernel, held back only by capabilities, seccomp and the LSM. If any layer is turned off, root in the container is very close to root on the host. Run as non-root, or use user namespace remapping.
For untrusted code, add a boundary that does not share the host kernel: gVisor intercepts syscalls in a user-space kernel, and Kata Containers or Firecracker run each workload in a lightweight VM.
05Putting it together
"What is a container, really?" separates people who have used Docker from people who understand it. Name the parts (namespaces, cgroups, capabilities, seccomp, LSM), say they share a kernel, and give one concrete escape such as a mounted Docker socket. Mentioning user namespaces as both the fix for container root and a source of kernel attack surface is a strong signal.
"A container is an ordinary process with namespaces for what it can see, cgroups for what it can use, a reduced capability set, a seccomp filter and an AppArmor or SELinux profile. All containers share the host kernel, so a kernel bug or a misconfiguration like a mounted Docker socket or --privileged is a host compromise. I'd run as non-root with all capabilities dropped, allowPrivilegeEscalation: false, RuntimeDefault seccomp and a read-only root filesystem, and use gVisor or microVMs for code we do not trust."
A CI job runs in a container with `/var/run/docker.sock` mounted so it can build images. What can a malicious build step do?
Q1Is a PID namespace a security boundary on its own?+
Not really. It hides other processes, but without capability, seccomp and filesystem restrictions a root process inside can still reach the host through mounts, devices or kernel interfaces.
Q2Why do some distributions restrict unprivileged user namespaces?+
They expose kernel features that previously required real root to every local user. Many recent kernel privilege escalations needed a user namespace to reach the vulnerable code.
Q3What does `allowPrivilegeEscalation: false` actually do?+
It sets the no_new_privs flag on the container process, so setuid binaries and file capabilities inside the image cannot raise privileges.