Search Knowledge

© 2026 LIBREUNI PROJECT

Operating Systems Engineering/Protection, isolation, and synthesis
Page 25 of 29

Containers and Resource Control

Linux namespaces, cgroup v2, credentials, syscall filtering, shared-kernel threat boundaries, and overload behavior.

Lesson briefProtection, isolation, and synthesis · 5 h 30 min · 4 outcomes

Required knowledge

  • Processes, scheduling, virtual memory, filesystems, and kernel protection
  • Principals, credentials, capabilities, least authority, and reference monitors
  • Virtual-machine guest, VMM, and hardware boundaries

Learning outcomes

  • Explain a container as constrained host processes rather than as a small virtual machine.
  • Trace PID, mount, network, user-identity, and cgroup state from container view to host enforcement.
  • Derive CPU, memory, and process-count behavior under explicit cgroup v2 assumptions and overload.
  • Construct a layered container threat model that identifies the shared host kernel and avoids treating seccomp or namespaces as complete sandboxes.

Assessment target

Given an unfamiliar multi-tenant workload, derive namespace views and cgroup behavior, identify the first shared trusted layer under compromise or overload, and defend a layered containment policy with testable failure states.

Scope boundary

  • Image distribution, registry protocols, cluster orchestration, service meshes, and supply-chain signing belong to deployment and security material.
  • Kernel-version-specific controller edge cases and every namespace type are bounded to the mechanisms needed for the traces.

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

Code
top to bottom direction
rectangle "container A user space\nPID 1, rootfs A, netns A" as A
rectangle "container B user space\nPID 1, rootfs B, netns B" as B
rectangle "host user space\nruntime, supervisor, services" as HOST
rectangle "one shared host kernel\nscheduler, VFS, network, drivers, cgroups" as K
rectangle "hardware\nCPU, RAM, devices" as HW
A --> K : system calls under A namespaces + credentials
B --> K : system calls under B namespaces + credentials
HOST --> K : host system calls
K --> HW : privileged control
note right of K
A host-kernel defect is inside
every container's trusted base.
end note
container A user spacePID 1, rootfs A, netns Acontainer B user spacePID 1, rootfs B, netns Bhost user spaceruntime, supervisor, servicesone shared host kernelscheduler, VFS, network, drivers,cgroupshardwareCPU, RAM, devicesA host-kernel defect is insideevery container's trusted base.system calls under Anamespaces +credentialssystem calls under Bnamespaces +credentialshost system callsprivileged control

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

0 / 4 answered

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.

1
In cgroups v2, memory.high acts as a throttle triggering background reclaim before hard memory.max termination.
2
Running a process inside a classic chroot jail provides comprehensive network and inter-process isolation.
3
User namespaces isolate container root users into a distinct guest kernel with an independent memory map.
4
Without cgroup process limits, a fork bomb in a private PID namespace can exhaust host kernel task capacity.

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.

namespaceselected virtualized viewimportant boundary
PIDprocess identifiers and visible process hierarchyhost still schedules the same tasks; namespace PID 1 has special lifecycle duties
mountmount table and resulting filesystem treefilesystem implementations execute in the shared kernel
networkinterfaces, routes, ports, protocol-stack viewpackets and drivers still cross host-kernel code
IPCSystem V IPC and POSIX message-queue namespacedoes not isolate every file-descriptor IPC channel
UTShostname and domain namepresentation identity, not authority boundary by itself
userUID/GID mappings and namespaced capabilitiesUID 0 inside may map to an unprivileged host UID
cgroupvisible cgroup rootresource enforcement comes from controller state, not this view alone
timeselected boot/monotonic clock offsetsnot 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 couplingExpand

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.

Interactive exploration

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.

Container A boundary compromised · Container
Deepest compromised layer = Container A boundary
tenant
Container A
selected isolation domain
compromise starts here
tenant
Container B
sibling tenant
outside modeled blast radius
boundary
shared trust
Shared host kernel
boundary implementation
outside modeled blast radius
substrate
Hardware + firmware
lowest trusted substrate
outside modeled blast radius

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.

Move a compromise across an isolation boundary
tenant
Container A
selected isolation domain
inside blast radius
tenant
Container B
sibling tenant
inside blast radius
boundary
shared trust
Shared host kernel
boundary implementation
compromise starts here
substrate
Hardware + firmware
lowest trusted substrate
outside modeled blast radius

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 claimsExpand

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

shareA=100100+300=0.25,shareB=0.75.share_A=\frac{100}{100+300}=0.25, \qquad share_B=0.75.

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.

timeA statekernel/controller actionimpact to test
t0t_0300 MiB, 20 tasksbelow configured boundariesbaseline throughput and B latency
t1t_1crosses 384 MiBA experiences reclaim/throttling pressureA throughput falls; host I/O may rise
t2t_2approaches 512 MiB with unreclaimable pagesallocations stall/fail or cgroup OOM policy actsverify victim scope and supervisor response
t3t_3tries task 129creation rejected by pids.maxverify 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 boundExpand

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:

  1. user namespace and credentials — map container identities to least host authority;
  2. mount namespace and root filesystem — expose required paths, make immutable inputs read-only, avoid unnecessary host mounts;
  3. capability sets — remove broad Linux privilege units, especially from the bounding and ambient paths where applicable;
  4. no-new-privileges and exec policy — prevent unexpected privilege gain across execution;
  5. seccomp filtering — reduce reachable syscall surface for the actual architecture and workload;
  6. LSM/mandatory policy — constrain object operations beyond discretionary mode bits where required;
  7. device policy — do not expose host devices whose ioctl or DMA authority exceeds the task;
  8. cgroup limits — bound CPU, memory, process, and I/O failure domains; and
  9. 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 claimExpand

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:

MechanismWhat it isolatesWhat it leaves unisolated (failure mode)
chrootPathname lookup root directorySupplies no PID, IPC, network, or resource isolation; root processes can escape via file-descriptor fchdir
Namespaces aloneIdentifier views (PIDs, mounts, net interfaces)Provides zero resource bounds; an unconstrained fork bomb or anonymous allocation exhausts the host
Cgroups v2 aloneResource consumption (CPU shares, memory bytes)Provides zero naming isolation; processes see and signal arbitrary host PIDs and mounts
User namespaces aloneMaps container UID 0 to unprivileged host UIDContainer processes still possess namespaced capabilities and expose reachable kernel attack surfaces
Seccomp BPF aloneRestricts permitted syscall numbers and registersCannot validate deep pointer payloads, unmediated open descriptors, or CPU/memory quotas
Section Exercises

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

Verificationapplication

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.

  1. Explain the special lifecycle responsibilities of PID 1 inside a PID namespace regarding orphaned child processes.
  2. What occurs if PID 1 inside the container exits or is terminated by SIGKILL?
HintExpand

PID 1 must reap orphaned children; terminating PID 1 destroys all namespace members.

Worked solutionExpand
  1. 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 call waitpid() 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).
  2. Termination cascade: POSIX and Linux specify that if PID 1 in a PID namespace terminates for any reason, the kernel automatically sends SIGKILL to 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

Constructionapplication

A container group is configured under /sys/fs/cgroup/build_worker:

  • Hard memory limit: 2 GiB 2,147,483,648 bytes2{,}147{,}483{,}648\text{ bytes}
  • Soft throttle threshold: 1.8 GiB 1,932,735,283 bytes1{,}932{,}735{,}283\text{ bytes}
  • CPU bandwidth: capped at 2.5 CPU cores per 100 ms100\text{ ms} scheduling period.
  1. State the exact cgroup v2 controller filenames and parameter values required to enforce these three constraints.
  2. Contrast the kernel reaction when consumption crosses the soft throttle threshold versus the hard limit.
HintExpand

Use memory.high for throttle, memory.max for OOM kill, and cpu.max for quota and period.

Worked solutionExpand
  1. 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 2.5×100,000 μs=250,000 μs2.5 \times 100{,}000\ \mu\text{s} = 250{,}000\ \mu\text{s} per 100,000 μs100{,}000\ \mu\text{s} period): echo "250000 100000" > /sys/fs/cgroup/build_worker/cpu.max
  2. 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).

Exercise 7.3.3: Mapping Container Root to Unprivileged Host UIDs

Constructiontransfer

A container uses user namespaces (CLONE_NEWUSER). The container runtime configures /proc/[pid]/uid_map with: 0 100000 65536

  1. Explain the meaning of the three numbers in this UID mapping entry.
  2. What host UID owns a file created inside the container by root (UID 0)?
  3. If container root executes mknod /dev/sda1 b 8 1, explain why the host kernel rejects the system call even though the process has effective UID 0 and CAP_MKNOD in its namespace.
HintExpand

The mapping format is: container_start host_start length. Device node creation requires global root authority.

Worked solutionExpand
  1. 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 k∈[0,65535]k \in [0, 65535] maps to host UID 100000+k100000 + k
  2. 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.
  3. Rejection of mknod: In Linux user namespaces, capabilities are namespaced. The container process possesses CAP_MKNOD only within its private user namespace. Creating real block device nodes exposes raw host disk storage; therefore, the kernel’s VFS explicitly requires CAP_MKNOD in 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

Proofsynthesis

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.

  1. Prove that seccomp-BPF cannot prevent the sandboxed container process from reading password hashes through descriptor 3.
  2. Specify the process creation invariant required to prevent descriptor leakage into containers.
HintExpand

Seccomp checks syscall numbers and register arguments, not whether an open descriptor refers to a sensitive file.

Worked solutionExpand
  1. 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 integer 3, user buffer pointer buf, length count).
    • 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 returns SECCOMP_RET_ALLOW.
    • The kernel VFS executes vfs_read(file_table[3], buf, count). Because the descriptor was opened on /etc/shadow before container creation, the read succeeds, disclosing confidential password hashes. Seccomp restricts syscall APIs, not ambient object capabilities carried by open descriptors.
  2. Process creation invariant: The container runtime must enforce: ∀fd>2,close(fd)∨fcntl(fd,F_SETFD,FD_CLOEXEC)\forall \text{fd} > 2, \quad \text{close}(\text{fd}) \lor \text{fcntl}(\text{fd}, \text{F\_SETFD}, \text{FD\_CLOEXEC}) prior to invoking execve(), ensuring that only explicitly whitelisted standard I/O descriptors (0, 1, 2) cross the containment boundary.

Exercise 7.3.5: Evaluating the Shared-Kernel Threat Boundary in Multi-Tenant Containers

Descriptionsynthesis

Compare the isolation boundary of multi-tenant containers with hardware-isolated virtual machines. Explain why a single local kernel privilege escalation exploit (e.g., a vulnerability in an allowed ioctl, socket protocol, or eBPF verifier) breaks all co-tenant containers on the host.

HintExpand

Containers share a single kernel address space and monolithic execution path.

Worked solutionExpand
  • The shared-kernel vulnerability: In containerized environments, every container executes system calls directly against the same running host kernel. There is only one kernel text, one page table mapping supervisor memory, and one set of kernel locks. If an attacker in Container AA triggers an unpatched kernel bug (such as a use-after-free in netfilter, a race condition in io_uring, or an integer overflow in a filesystem driver):
    1. The exploit executes arbitrary shellcode in CPU supervisor/kernel mode.
    2. Once in supervisor mode, the exploit completely overrides all namespace data structures, cgroup accounting limits, and seccomp filters.
    3. The attacker can read and write all host physical memory, inspect processes in Container BB access host disks, and achieve full system takeover.
  • Contrast with Virtual Machines: In virtual machines, the guest operating system kernel runs in a separate hardware virtualization mode (Guest Supervisor) below the hypervisor (Host Root). A guest kernel vulnerability gives the attacker control over only that guest’s virtual machine. Escaping to the host requires finding and chaining a secondary hypervisor breakout exploit (e.g., in QEMU device emulation or KVM exit handling). VMs provide two independent layers of defense-in-depth.

References & Further Reading