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.

FREEBy ·Lesson·10 min read·Beginner → Intermediate
Linux namespacescgroups v2seccompuser namespacescontainer escape/proc

01Processes and what /proc reveals

✓What you will learn
  • Explain what a process exposes to other users through /proc and ps
  • 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.

PathContentsWho can read it by default
/proc/<pid>/cmdlineFull command lineEvery user, so passwords passed as arguments leak through ps
/proc/<pid>/environEnvironment variables at startOwner and root only
/proc/<pid>/statusUIDs, GIDs, capability sets, seccomp modeEvery user
/proc/<pid>/maps, memMemory layout and contentsOwner and root, further limited by ptrace rules
/proc/<pid>/exe, fd/Binary and open filesOwner 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 /proc hides other users' processes entirely on multi-user systems.
  • Forensics: a binary deleted after launch still runs, and /proc/<pid>/exe still points at it. ls -l /proc/*/exe 2>/dev/null | grep deleted is 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.

NamespaceIsolatesAdded
mountMount table: what the filesystem looks like2.4.19 (2002), the first
UTSHost name and domain name2.6.19
IPCSystem V IPC and POSIX message queues2.6.19
PIDProcess ID numbers; the first process is PID 1 inside2.6.24
networkInterfaces, routes, firewall rules, sockets2.6.29
userUID and GID mappings, and capabilities relative to the namespace3.8
cgroupView of the cgroup hierarchy4.6
timeBoot and monotonic clock offsets5.6
Root inside, nobody outsidebash
# 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 files

User 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.

▭On the whiteboard · A container is not one feature4 points
01
namespaces
what it can see: own PIDs, mounts, network, hostname
02
cgroups
how much it can use: CPU, memory, pids
03
capabilities
what privileged operations it may attempt: a reduced default set
04
seccomp + LSM
which syscalls it may make, and which files and operations AppArmor or SELinux allow
Turning the layers onyaml
# 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: RuntimeDefault

04Why 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 routeWhy it worksFix
--privilegedAll capabilities, all devices, no seccomp: mount the host diskNever 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 containerDo not mount it; use a narrow API or rootless builders
hostPath: / or hostPIDDirect access to host files or processesPod Security Admission restricted profile
CAP_SYS_ADMIN or CAP_SYS_PTRACEMount tricks, cgroup release agents, process injectionDrop ALL, add back only what is justified
Runtime bugsrunc CVE-2019-5736 (overwrite host runc), CVE-2024-21626 (leaked directory descriptor)Patch the runtime and the kernel promptly
!Root in a container is still root on the kernel

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.

iStronger isolation when you need it

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

◎Interview radar

"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.

“How to say it in the room

"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."

Test yourself

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.

Finished this one?
Tick it and it shows as done on the roadmap and the course.