Two services each report PID 1 and each sees / as its own image root. One service forks until the host cannot create another process. Another triggers a vulnerability in the filesystem parser and executes in kernel context. The first failure is a missing resource limit; the second crosses every container boundary that relies on that kernel.
Names and resource accounting create convincing private views, but they do not create another kernel. A Linux container is a set of ordinary host tasks whose namespace memberships, cgroup memberships, credentials, filesystem view, and security policy are configured to constrain what those tasks can name and consume.
The boundary stack
The runtime creates and joins kernel objects; it is not on the path of every later system call. Enforcement resides primarily in the host kernel and configured security modules. The image supplies user-space bytes. It does not supply a guest kernel.
Contrast a virtual machine:
container: application -> shared host kernel -> hardware
VM: application -> guest kernel -> VMM/hypervisor -> hardware
A VM’s guest kernel is inside the VM boundary, but the VMM and hardware remain trusted dependencies. A container’s kernel is the host kernel itself.
Namespaces, cgroups, and container boundaries
Evaluate each statement regarding Linux namespaces, cgroups v2, and container isolation models:
Classify each option as correct or incorrect, or leave uncertain options unanswered (“I don't know”) and verify at any time.
Namespaces alter views and identities
A namespace wraps a class of global resources so member tasks observe a namespace-specific instance or mapping. It does not grant arbitrary permission over the underlying host resource.
| namespace | selected virtualized view | important boundary |
|---|---|---|
| PID | process identifiers and visible process hierarchy | host still schedules the same tasks; namespace PID 1 has special lifecycle duties |
| mount | mount table and resulting filesystem tree | filesystem implementations execute in the shared kernel |
| network | interfaces, routes, ports, protocol-stack view | packets and drivers still cross host-kernel code |
| IPC | System V IPC and POSIX message-queue namespace | does not isolate every file-descriptor IPC channel |
| UTS | hostname and domain name | presentation identity, not authority boundary by itself |
| user | UID/GID mappings and namespaced capabilities | UID 0 inside may map to an unprivileged host UID |
| cgroup | visible cgroup root | resource enforcement comes from controller state, not this view alone |
| time | selected boot/monotonic clock offsets | not a separate scheduler or hardware clock |
A task is a member of one namespace of each type. Namespace lifetimes can outlive their last member when file descriptors or bind-mounted namespace handles retain references.
Worked trace: one task, two PID and UID views
Host state:
host PID: 4242
host UID: 100000
child user namespace mapping: inside UIDs 0..65535 -> host UIDs 100000..165535
child PID namespace: task is namespace init
Inside the container, the task sees PID 1 and UID 0. From the initial host namespaces, an administrator sees PID 4242 and UID 100000. A file created with inside UID 0 is owned by host UID 100000 under this mapping.
“Root in the container” therefore describes authority evaluated in a user-namespace context. Operations reserved to the initial user namespace—such as loading arbitrary host kernel modules under the relevant Linux policy—do not become permitted merely because the task’s inside UID is zero. Conversely, namespaced root can still exercise substantial authority over objects owned by that user namespace and can reach host-kernel attack surface through allowed system calls.
Application checkpoint: /proc shows the wrong tasks
A process creates a PID namespace but reuses a /proc mount created in the parent namespace. Inside, ps lists host-visible PIDs rather than the intended child view. Explain the mismatch and repair.
Reveal the namespace/mount couplingExpandCollapse
The process joined a new PID-numbering domain, but the mounted procfs instance reflects the PID namespace of the process that mounted it. Create or use an appropriate mount namespace and mount a fresh procfs from the child PID namespace. A PID namespace alone does not rewrite bytes supplied by an already mounted procfs view.
Predict the blast radius before moving the control
A hostile process has already obtained arbitrary code execution in the host kernel through an allowed filesystem system call. Predict which container namespace, cgroup, or seccomp rule can still mediate that code as an untrusted user process.
Move a compromise across an isolation boundary
Select a process, container, or virtual-machine boundary, then move the deepest compromised trusted layer. The model distinguishes a tenant failure from compromise of the mechanism shared by sibling tenants.
Boundary location: between each container view and the shared kernel. Namespaces change what a workload can see and cgroups account for resources. They do not place a separate kernel beneath each container.
Modeled blast radius: Container A.
Scope: a logical trust boundary, not an exploitability score. Sandboxes, seccomp filters, mandatory access control, nested virtualization, device assignment, firmware, denial of service, and side channels alter the real boundary and require separate evidence.
Boundary location: between each container view and the shared kernel. Namespaces change what a workload can see and cgroups account for resources. They do not place a separate kernel beneath each container.
Modeled blast radius: Container A, Container B, Shared host kernel.
Static state: a host-kernel compromise crosses every container boundary because containers share that kernel. Namespace and cgroup isolation cannot contain failure of their own implementation.
For the stated compromise, none of those user-process controls remains a sound boundary: the code executes inside the mechanism that implements them. This shared-kernel failure mode is a concrete counterexample to treating a container as a hardware-isolated virtual machine. The interaction is a trust-dependency model, not an exploitability score. Its four boxes represent the selected tenant, a peer tenant, their shared implementation, and hardware/firmware; red should be read as “this selected layer or a relied-on lower layer is no longer trustworthy,” not as a measured probability or a complete attack graph.
Transfer after changing the boundary
Place the workload in a VM. A guest-kernel compromise occurs, while the VMM, its device models, second-stage translation, IOMMU configuration, firmware, and hardware remain correct under the threat model. What changes? Then move the compromise into the VMM.
Reveal both containment claimsExpandCollapse
The guest-kernel compromise controls that guest and its applications, but second-stage translation and the VMM can contain architectural access to host and other-VM memory under the assumptions. If the VMM is compromised, the layer responsible for VM isolation is lost; guest boundaries cannot constrain it. The stronger first result depends on the VMM/hardware assumptions and does not prove absence of side channels or resource denial.
Cgroups control resources, not names
Cgroup v2 organizes tasks in a hierarchy. Controllers distribute or limit resources among children. Namespace membership answers “what identifiers and objects can this task name?” Cgroup membership answers “how is this task’s resource use accounted and constrained?” A secure deployment usually needs both.
CPU weights are work-conserving shares
Assume two sibling cgroups A and B are continuously runnable under one parent and no other constraints apply. With cpu.weight values 100 and 300, the idealized share is
If the parent receives four cores for a 100 ms interval, its capacity is 400 core-ms. The model allocates about 100 core-ms to A and 300 to B while both can use them. If A is idle, a work-conserving scheduler may let B consume the available capacity rather than reserve 25% unused.
This is a policy model, not an exact short-window deadline guarantee. Runnable patterns, CPU affinity, per-CPU queues, priorities, bandwidth limits, topology, throttling, and measurement windows affect observed service. A weight does not promise a maximum latency.
Memory and process limits define overload states
For a batch worker cgroup:
memory.high = 384 MiB
memory.max = 512 MiB
pids.max = 128
memory.high is a pressure boundary that drives reclaim/throttling behavior rather than an immediate hard allocation failure in the ordinary model. memory.max is the hard containment boundary; if usage cannot be reduced, the kernel invokes cgroup-scoped out-of-memory handling according to controller policy. pids.max rejects creation when the task count would exceed the configured limit.
Limits interact. Reclaim can consume CPU and produce I/O; a process unable to fork may fail a supervisor protocol; killing one task may leave shared state inconsistent. Resource isolation needs an application failure contract, not only numeric files.
Worked overload trace: decompression service
Container A expands an adversarial archive. Container B serves latency-sensitive requests.
| time | A state | kernel/controller action | impact to test |
|---|---|---|---|
| 300 MiB, 20 tasks | below configured boundaries | baseline throughput and B latency | |
| crosses 384 MiB | A experiences reclaim/throttling pressure | A throughput falls; host I/O may rise | |
| approaches 512 MiB with unreclaimable pages | allocations stall/fail or cgroup OOM policy acts | verify victim scope and supervisor response | |
| tries task 129 | creation rejected by pids.max | verify bounded error, no host-wide PID exhaustion |
The target claim is not “B is unaffected.” Shared last-level cache, memory bandwidth, storage, kernel locks, and unaccounted resources can still interfere. Measure B’s tail latency and host pressure, then add controls or admission policy for observed channels.
Quantitative checkpoint: idle sibling
A and B have equal CPU weights. A is runnable for only 20 ms of a 100 ms interval; B is runnable throughout. Under an ideal work-conserving model on one core, how much CPU can B receive? Why is “exactly 50 ms” wrong?
Reveal the service boundExpandCollapse
During the 20 ms overlap, equal weights suggest roughly 10 ms each. During the remaining 80 ms, B can use the idle capacity. B therefore can receive about 90 ms, not a fixed 50 ms reservation. Exact short-window service depends on scheduler details and workload timing; the calculation states the simplified model. A hard bandwidth cap would be a different controller mechanism.
Layer the security policy
No single switch defines a container sandbox. A defensible policy composes:
- user namespace and credentials — map container identities to least host authority;
- mount namespace and root filesystem — expose required paths, make immutable inputs read-only, avoid unnecessary host mounts;
- capability sets — remove broad Linux privilege units, especially from the bounding and ambient paths where applicable;
- no-new-privileges and exec policy — prevent unexpected privilege gain across execution;
- seccomp filtering — reduce reachable syscall surface for the actual architecture and workload;
- LSM/mandatory policy — constrain object operations beyond discretionary mode bits where required;
- device policy — do not expose host devices whose
ioctlor DMA authority exceeds the task; - cgroup limits — bound CPU, memory, process, and I/O failure domains; and
- runtime/supervisor policy — validate configuration, retain minimal authority, and handle abnormal exit.
Seccomp filters inspect syscall number, architecture, and argument words under defined constraints. They cannot dereference arbitrary user pointers in the in-kernel filter. They reduce exposed kernel entry points; they do not validate application-level information flow, remove inherited descriptors, or repair a vulnerable allowed syscall.
Worked threat trace: inherited host descriptor
A runtime opens /var/run/admin.sock, then starts a container without closing or marking the descriptor close-on-exec. The container has a private mount namespace and cannot name that path. It nevertheless inherits the connected descriptor.
The mount namespace removed a pathname, not the open-reference edge. If send is allowed, the process may use the descriptor. Repair requires an explicit descriptor allowlist/close sweep at process creation and least-authority supervisor design. Adding another bind-mount rule cannot revoke an inherited object reference.
Boundary checkpoint: seccomp-only sandbox
A parser receives untrusted images. Its filter allows read, mmap, munmap, futex, close, and exit; it shares the host kernel and has a writable descriptor to a tenant directory. State one property the filter supports and three it does not establish.
Reveal the scoped claimExpandCollapse
It reduces the parser’s reachable syscall interface to the allowed set under the filter’s architecture and argument rules. It does not establish memory safety in the parser, remove write authority carried by the directory descriptor, prevent exploitation of a vulnerability in an allowed syscall, or isolate the host from a compromised kernel. It also does not impose CPU/memory limits. Those require separate mechanisms and evidence.
Containers are not resource guarantees by default
Failure modes of orthogonal container mechanisms:
| Mechanism | What it isolates | What it leaves unisolated (failure mode) |
|---|---|---|
chroot | Pathname lookup root directory | Supplies no PID, IPC, network, or resource isolation; root processes can escape via file-descriptor fchdir |
| Namespaces alone | Identifier views (PIDs, mounts, net interfaces) | Provides zero resource bounds; an unconstrained fork bomb or anonymous allocation exhausts the host |
| Cgroups v2 alone | Resource consumption (CPU shares, memory bytes) | Provides zero naming isolation; processes see and signal arbitrary host PIDs and mounts |
| User namespaces alone | Maps container UID 0 to unprivileged host UID | Container processes still possess namespaced capabilities and expose reachable kernel attack surfaces |
| Seccomp BPF alone | Restricts permitted syscall numbers and registers | Cannot validate deep pointer payloads, unmediated open descriptors, or CPU/memory quotas |
Deep Practice
Solve these problems to test and consolidate your understanding. Complete worked solutions and diagnostic hints are available for each problem.
Exercise 7.3.1: Process Namespace Hierarchies and PID 1 Orphan Reaping
In a Linux container created with CLONE_NEWPID, the entrypoint process is assigned virtual PID 1 inside the namespace while holding PID 14,200 on the host.
- Explain the special lifecycle responsibilities of PID 1 inside a PID namespace regarding orphaned child processes.
- What occurs if PID 1 inside the container exits or is terminated by
SIGKILL?
HintExpandCollapse
PID 1 must reap orphaned children; terminating PID 1 destroys all namespace members.
Worked solutionExpandCollapse
- Orphan reaping duties:
In Unix systems, when a parent process terminates before its children, those children are automatically reparented to PID 1 (
init) of the containing PID namespace. PID 1 must continuously callwaitpid()in a loop to reap zombies and collect their exit status codes. If PID 1 does not implement orphan reaping (e.g., if a naive application binary runs directly as container PID 1), zombie processes accumulate in the host kernel’s process table, eventually exhausting host process slots (pids.max). - Termination cascade:
POSIX and Linux specify that if PID 1 in a PID namespace terminates for any reason, the kernel automatically sends
SIGKILLto all remaining processes belonging to that PID namespace. The entire container process tree is dismantled, and the PID namespace is destroyed.
Exercise 7.3.2: Sizing cgroup v2 Memory and CPU Controller Quotas
A container group is configured under /sys/fs/cgroup/build_worker:
- Hard memory limit: 2 GiB
- Soft throttle threshold: 1.8 GiB
- CPU bandwidth: capped at 2.5 CPU cores per scheduling period.
- State the exact cgroup v2 controller filenames and parameter values required to enforce these three constraints.
- Contrast the kernel reaction when consumption crosses the soft throttle threshold versus the hard limit.
HintExpandCollapse
Use memory.high for throttle, memory.max for OOM kill, and cpu.max for quota and period.
Worked solutionExpandCollapse
- Cgroup v2 configuration files:
- Soft memory threshold:
echo 1932735283 > /sys/fs/cgroup/build_worker/memory.high - Hard memory ceiling:
echo 2147483648 > /sys/fs/cgroup/build_worker/memory.max - CPU bandwidth quota per period):
echo "250000 100000" > /sys/fs/cgroup/build_worker/cpu.max
- Soft memory threshold:
- Enforcement behavior:
- Crossing
memory.high: The kernel does not kill the process. Instead, it throttles the container’s threads (delaying syscall return) and activates asynchronous direct page reclaim to force memory usage back below 1.8 GiB without abrupt process termination. - Crossing
memory.max: The kernel executes synchronous reclaim. If reclaim fails to free memory below 2 GiB, the kernel invokes the cgroup-scoped Out-Of-Memory (OOM) killer to terminate one or more container processes (oom_score).
- Crossing
Exercise 7.3.3: Mapping Container Root to Unprivileged Host UIDs
A container uses user namespaces (CLONE_NEWUSER). The container runtime configures /proc/[pid]/uid_map with:
0 100000 65536
- Explain the meaning of the three numbers in this UID mapping entry.
- What host UID owns a file created inside the container by
root(UID 0)? - If container root executes
mknod /dev/sda1 b 8 1, explain why the host kernel rejects the system call even though the process has effectiveUID 0andCAP_MKNODin its namespace.
HintExpandCollapse
The mapping format is: container_start host_start length. Device node creation requires global root authority.
Worked solutionExpandCollapse
- Mapping specification:
0: The starting UID inside the container namespace.100000: The starting host UID on the underlying system.65536: The contiguous range of mapped UIDs. Container UID maps to host UID
- File creation ownership:
When container
root(UID 0) creates a file, the host kernel stores the physical on-disk inode owner as host UID 100,000. On the host, the file is owned by unprivileged user 100,000, possessing zero superuser access to host resources. - Rejection of
mknod: In Linux user namespaces, capabilities are namespaced. The container process possessesCAP_MKNODonly within its private user namespace. Creating real block device nodes exposes raw host disk storage; therefore, the kernel’s VFS explicitly requiresCAP_MKNODin the initial root namespace (host namespace). Since host UID 100,000 lacks global superuser capabilities,mknod()returns-EPERM.
Exercise 7.3.4: Proving Confinement Failure Under Inherited Host File Descriptors
A container is confined using a strict seccomp-BPF filter that allows only read(), write(), close(), and exit(). A bug in the container launcher leaves host file descriptor 3 open, connected to /etc/shadow with read permissions.
- Prove that seccomp-BPF cannot prevent the sandboxed container process from reading password hashes through descriptor 3.
- Specify the process creation invariant required to prevent descriptor leakage into containers.
HintExpandCollapse
Seccomp checks syscall numbers and register arguments, not whether an open descriptor refers to a sensitive file.
Worked solutionExpandCollapse
- Proof of confinement failure:
- Seccomp-BPF operates as an instruction filter on system call invocation: it inspects the system call number (
__NR_read), architecture, and scalar register values (file descriptor integer3, user buffer pointerbuf, lengthcount). - Seccomp cannot inspect the underlying kernel object to which descriptor 3 points; it only observes the integer
3. - Because
read()is explicitly allowed by the policy filter, the seccomp filter returnsSECCOMP_RET_ALLOW. - The kernel VFS executes
vfs_read(file_table[3], buf, count). Because the descriptor was opened on/etc/shadowbefore container creation, the read succeeds, disclosing confidential password hashes. Seccomp restricts syscall APIs, not ambient object capabilities carried by open descriptors.
- Seccomp-BPF operates as an instruction filter on system call invocation: it inspects the system call number (
- Process creation invariant:
The container runtime must enforce:
prior to invoking
execve(), ensuring that only explicitly whitelisted standard I/O descriptors (0, 1, 2) cross the containment boundary.
References & Further Reading
- Linux man-pages,
namespaces(7)— namespace types, APIs, handles, and lifetimes. - Linux man-pages,
pid_namespaces(7)— PID visibility, namespace init, and procfs coupling. - Linux man-pages,
mount_namespaces(7)— mount-table views and propagation restrictions. - Linux man-pages,
user_namespaces(7)— UID/GID mappings and namespaced capability scope. - Linux kernel documentation, Control Group v2 — hierarchy, controllers, weights, limits, and resource-distribution models.
- Linux kernel documentation, Seccomp BPF — syscall-filter mechanism, requirements, and sandbox boundary.
- Open Container Initiative, Runtime Specification: Linux — runtime mapping for namespaces, cgroups, devices, and process configuration.
- Linux kernel documentation, Credentials in Linux — task credentials and Linux capability sets.