Linux Namespaces and Isolation
Linux Namespaces and Isolation
Isolation
Team Emertxe
Contents
Topics
1.Introduction to Linux Namespaces
2.Drawbacks and Security Issues of Set-UID Programs
3.Capabilities in C
4.Linux Capabilities Overview
5.Process Capabilities
6.File Capabilities
7.Viewing and Modifying Capabilities
8.Introduction to 8 Namespaces
9.Namespace Hierarchy
10.UTS Namespace Example
Topics
11.Symlink from /proc
12.Namespace APIs and Commands
13.Demo and Lab Examples
14.User Namespaces: UID and GID Mappings
15.User Namespaces and Capabilities
16.Security Issues with User Namespaces
17.Use Cases of Namespaces
18.Summary
19.Q&A
20.References
Introduction to Namespaces
• Linux namespaces provide process isolation
by partitioning kernel resources.
• Introduced in Linux kernel 2.4, expanded in
later versions.
• Enables containerization and lightweight
virtualization.
• Key Benefits: Process isolation, resource
control, security enhancement.
Traditional Set-UID Programs
Set-UID programs run with elevated privileges,
leading to security risks.
•Drawbacks:
• Privilege escalation attacks.
• Difficulty in fine-grained access control.
• Exploitation of vulnerabilities.
•Security Issues:
• Over-privileged execution.
• Complex debugging and auditing.
• Powerful, but dangerous
Traditional Set-UID Programs
Coarse granularity of traditional privilege model is a
problem:
• E.g, say we want to give a program the power to
change system time
• Must also give it power to do everything else
root can do
• No limit on possible damage if program is
compromised
Capabilities in Linux
Capabilities in Linux
• Capabilities provide fine-grained privilege
management in Linux.
• Breaks monolithic root privileges into smaller
sets.
• Implemented via libcap library in C.
• Allows for safe delegation of specific
privileges to processes or files
Rationale for capabilities
Capabilities divide power of superuser into
small pieces
• 41 capabilities, as at Linux 6.13
• Traditional superuser == process that has full set of
capabilities
Goal: replace set-UID-root programs with
programs that have capabilities
• Compromise in set-UID-root binary -> very dangerous
• Compromise in binary with file capabilities -> less
dangerous
Selection of Linux capabilities
CAP_CHOWN Make arbitrary changes to file UIDs and GIDs
CAP_DAC_OVERRIDE Bypass file RWX permission checks
CAP_DAC_READ_SEARCH Bypass file R and directory X permission checks
CAP_IPC_LOCK Lock memory
CAP_KILL Send signals to arbitrary processes
CAP_NET_ADMIN Various network-related operations
CAP_SETFCAP Set file capabilities
CAP_SETGID Make arbitrary changes to process’s (own) GIDs
CAP_SETPCAP Make changes to process’s (own) capabilities
CAP_SETUID Make arbitrary changes to process’s (own) UIDs
CAP_SYS_ADMIN Perform a wide range of system admin tasks
More details: capabilities(7) manual page
Process Capabilities
• Capabilities assigned to running processes.
• Processes have three sets: Effective,
Permitted, Inheritable.
• Example commands:
• capsh --print
• Modifying process capabilities using prctl()
and cap_set_proc().
File Capabilities
• Capabilities assigned to executables to run
with specific privileges.
• Useful for granting minimal privileges to non-
root processes.
• Example commands:
• getcap /path/to/binary
• setcap cap_net_bind_service+ep /path/to/binary
Summary
• Processes can have capabilities (subset of
power of root)
• Files can have attached capabilities, which
are given to process that executes program
• Privileged binaries/processes using
capabilities are less dangerous if
compromised
Namespaces
Namespaces
• A namespace (NS) “wraps” some global
system resource to provide resource isolation
• Linux supports multiple NS types
• 8 currently, and counting...
Types of namespaces
•Mount NS (CLONE_NEWNS;2.4.19, 2002)
• Isolates mount points, allowing different views of the
file system.
•UTS NS (CLONE_NEWUTS;2.6.19, 2006)
• Isolates hostname and domain name settings.
•IPC NS (CLONE_NEWIPC;2.6.19, 2006)
• Isolates inter-process communication mechanisms.
•PID NS (CLONE_NEWPID;2.6.24, 2008)
• Isolates process IDs, enabling separate process
trees.
Types of namespaces
•Network NS(CLONE_NEWNET;2.6.24, 2008)
• Isolates network devices and settings.
•User NS (CLONE_NEWUSER;3.8, 2013)
• Isolates user and group IDs, enabling privilege separation.
•Cgroup NS (CLONE_NEWCGROUP;4.6, 2016)
• Isolates control groups, allowing per-namespace resource
limits.
•Time NS (CLONE_NEWTIME;5.6, 2020)
• Isolates system time settings within the namespace.
Namespace Hierarchy
• Parent-child relationship between
namespaces.
• A user namespace can contain other
namespaces.
• PID namespaces are nested within parent
namespaces.
• Example:
• unshare --fork --pid --mount-proc bash
NS instances
• Multiple instances of NS may exist on a system
• At system boot, there is one instance of each NS
type–the initial namespace
• A process resides in one NS instance (of each of
NS types)
• To processes inside NS instance, it appears that
only they can see/modify corresponding global
resource
• They are unaware of other instances of resource
NS instances
When new (child) process is created (fork()), it
resides in same set of NSs as parent process
• There are system calls (and commands) for
creating new NSs and moving processes into NSs
UTS namespaces
• Isolate certain system identifiers, including
hostname
• hostname(1), uname(1)
• Running system may have multiple UTS NS
instances
• Processes in same NS instance access (get/set)
same hostname
• Each NS instance has its own hostname
• Changes to hostname in one NS instance are invisible
to other instances
UTS namespace instances