]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man7/namespaces.7
pldd.1, bpf.2, chdir.2, clone.2, fanotify_init.2, fanotify_mark.2, intro.2, ipc.2...
[thirdparty/man-pages.git] / man7 / namespaces.7
index e055e1d7458201e7f6b18f18773ffbbedf2a5eea..bf0ad8279ceaf96cf38cac53a02051c505c8c50c 100644 (file)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2013 by Michael Kerrisk <mtk.manpages@gmail.com>
+.\" Copyright (c) 2013, 2016, 2017 by Michael Kerrisk <mtk.manpages@gmail.com>
 .\" and Copyright (c) 2012 by Eric W. Biederman <ebiederm@xmission.com>
 .\"
 .\" %%%LICENSE_START(VERBATIM)
@@ -24,7 +24,7 @@
 .\" %%%LICENSE_END
 .\"
 .\"
-.TH NAMESPACES 7 2016-03-15 "Linux" "Linux Programmer's Manual"
+.TH NAMESPACES 7 2019-08-02 "Linux" "Linux Programmer's Manual"
 .SH NAME
 namespaces \- overview of Linux namespaces
 .SH DESCRIPTION
@@ -34,7 +34,7 @@ have their own isolated instance of the global resource.
 Changes to the global resource are visible to other processes
 that are members of the namespace, but are invisible to other processes.
 One use of namespaces is to implement containers.
-
+.PP
 Linux provides the following namespaces:
 .TS
 lB lB lB
@@ -48,7 +48,7 @@ PID   CLONE_NEWPID    Process IDs
 User   CLONE_NEWUSER   User and group IDs
 UTS    CLONE_NEWUTS    Hostname and NIS domain name
 .TE
-
+.PP
 This page describes the various namespaces and the associated
 .I /proc
 files, and summarizes the APIs for working with namespaces.
@@ -95,6 +95,13 @@ flags listed below, then new namespaces are created for each flag,
 and the calling process is made a member of those namespaces.
 (This system call also implements a number of features
 unrelated to namespaces.)
+.TP
+.BR ioctl (2)
+Various
+.BR ioctl (2)
+operations can be used to discover information about namespaces.
+These operations are described in
+.BR ioctl_ns (2).
 .PP
 Creation of new namespaces using
 .BR clone (2)
@@ -102,7 +109,10 @@ and
 .BR unshare (2)
 in most cases requires the
 .BR CAP_SYS_ADMIN
-capability.
+capability, since, in the new namespace,
+the creator will have the power to change global resources
+that are visible to other processes that are subsequently created in,
+or join the namespace.
 User namespaces are the exception: since Linux 3.8,
 no privilege is required to create a user namespace.
 .\"
@@ -115,21 +125,22 @@ Each process has a
 subdirectory containing one entry for each namespace that
 supports being manipulated by
 .BR setns (2):
-
+.PP
 .in +4n
-.nf
-$ \fBls -l /proc/$$/ns\fP
+.EX
+$ \fBls \-l /proc/$$/ns\fP
 total 0
-lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 cgroup -> cgroup:[4026531835]
-lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 ipc -> ipc:[4026531839]
-lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 mnt -> mnt:[4026531840]
-lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 net -> net:[4026531969]
-lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid -> pid:[4026531836]
-lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 user -> user:[4026531837]
-lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 uts -> uts:[4026531838]
-.fi
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 cgroup \-> cgroup:[4026531835]
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 ipc \-> ipc:[4026531839]
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 mnt \-> mnt:[4026531840]
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 net \-> net:[4026531969]
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid \-> pid:[4026531836]
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 pid_for_children \-> pid:[4026531834]
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 user \-> user:[4026531837]
+lrwxrwxrwx. 1 mtk mtk 0 Apr 28 12:46 uts \-> uts:[4026531838]
+.EE
 .in
-
+.PP
 Bind mounting (see
 .BR mount (2))
 one of the files in this directory
@@ -137,7 +148,7 @@ to somewhere else in the filesystem keeps
 the corresponding namespace of the process specified by
 .I pid
 alive even if all processes currently in the namespace terminate.
-
+.PP
 Opening one of the files in this directory
 (or a file that is bind mounted to one of these files)
 returns a file handle for
@@ -148,25 +159,30 @@ the namespace will remain alive,
 even if all processes in the namespace terminate.
 The file descriptor can be passed to
 .BR setns (2).
-
+.PP
 In Linux 3.7 and earlier, these files were visible as hard links.
-Since Linux 3.8, they appear as symbolic links.
-If two processes are in the same namespace, then the inode numbers of their
+Since Linux 3.8,
+.\" commit bf056bfa80596a5d14b26b17276a56a0dcb080e5
+they appear as symbolic links.
+If two processes are in the same namespace,
+then the device IDs and inode numbers of their
 .IR /proc/[pid]/ns/xxx
 symbolic links will be the same; an application can check this using the
+.I stat.st_dev
+and
 .I stat.st_ino
-field returned by
+fields returned by
 .BR stat (2).
 The content of this symbolic link is a string containing
 the namespace type and inode number as in the following example:
-
+.PP
 .in +4n
-.nf
+.EX
 $ \fBreadlink /proc/$$/ns/uts\fP
 uts:[4026531838]
-.fi
+.EE
 .in
-
+.PP
 The symbolic links in this subdirectory are as follows:
 .TP
 .IR /proc/[pid]/ns/cgroup " (since Linux 4.6)"
@@ -185,6 +201,26 @@ This file is a handle for the network namespace of the process.
 .IR /proc/[pid]/ns/pid " (since Linux 3.8)"
 .\" commit 57e8391d327609cbf12d843259c968b9e5c1838f
 This file is a handle for the PID namespace of the process.
+This handle is permanent for the lifetime of the process
+(i.e., a process's PID namespace membership never changes).
+.TP
+.IR /proc/[pid]/ns/pid_for_children " (since Linux 4.12)"
+.\" commit eaa0d190bfe1ed891b814a52712dcd852554cb08
+This file is a handle for the PID namespace of
+child processes created by this process.
+This can change as a consequence of calls to
+.BR unshare (2)
+and
+.BR setns (2)
+(see
+.BR pid_namespaces (7)),
+so the file may differ from
+.IR /proc/[pid]/ns/pid .
+The symbolic link gains a value only after the first child process
+is created in the namespace.
+(Beforehand,
+.BR readlink (2)
+of the symbolic link will return an empty buffer.)
 .TP
 .IR /proc/[pid]/ns/user " (since Linux 3.8)"
 .\" commit cde1975bc242f3e1072bde623ef378e547b73f91
@@ -200,6 +236,91 @@ these symbolic links is governed by a ptrace access mode
 check; see
 .BR ptrace (2).
 .\"
+.\" ==================== The /proc/sys/user directory ====================
+.\"
+.SS The /proc/sys/user directory
+The files in the
+.I /proc/sys/user
+directory (which is present since Linux 4.9) expose limits
+on the number of namespaces of various types that can be created.
+The files are as follows:
+.TP
+.IR max_cgroup_namespaces
+The value in this file defines a per-user limit on the number of
+cgroup namespaces that may be created in the user namespace.
+.TP
+.IR max_ipc_namespaces
+The value in this file defines a per-user limit on the number of
+ipc namespaces that may be created in the user namespace.
+.TP
+.IR max_mnt_namespaces
+The value in this file defines a per-user limit on the number of
+mount namespaces that may be created in the user namespace.
+.TP
+.IR max_net_namespaces
+The value in this file defines a per-user limit on the number of
+network namespaces that may be created in the user namespace.
+.TP
+.IR max_pid_namespaces
+The value in this file defines a per-user limit on the number of
+pid namespaces that may be created in the user namespace.
+.TP
+.IR max_user_namespaces
+The value in this file defines a per-user limit on the number of
+user namespaces that may be created in the user namespace.
+.TP
+.IR max_uts_namespaces
+The value in this file defines a per-user limit on the number of
+uts namespaces that may be created in the user namespace.
+.PP
+Note the following details about these files:
+.IP * 3
+The values in these files are modifiable by privileged processes.
+.IP *
+The values exposed by these files are the limits for the user namespace
+in which the opening process resides.
+.IP *
+The limits are per-user.
+Each user in the same user namespace
+can create namespaces up to the defined limit.
+.IP *
+The limits apply to all users, including UID 0.
+.IP *
+These limits apply in addition to any other per-namespace
+limits (such as those for PID and user namespaces) that may be enforced.
+.IP *
+Upon encountering these limits,
+.BR clone (2)
+and
+.BR unshare (2)
+fail with the error
+.BR ENOSPC .
+.IP *
+For the initial user namespace,
+the default value in each of these files is half the limit on the number
+of threads that may be created
+.RI ( /proc/sys/kernel/threads-max ).
+In all descendant user namespaces, the default value in each file is
+.BR MAXINT .
+.IP *
+When a namespace is created, the object is also accounted
+against ancestor namespaces.
+More precisely:
+.RS
+.IP + 3
+Each user namespace has a creator UID.
+.IP +
+When a namespace is created,
+it is accounted against the creator UIDs in each of the
+ancestor user namespaces,
+and the kernel ensures that the corresponding namespace limit
+for the creator UID in the ancestor namespace is not exceeded.
+.IP +
+The aforementioned point ensures that creating a new user namespace
+cannot be used as a means to escape the limits in force
+in the current user namespace.
+.RE
+.\"
 .\" ==================== Cgroup namespaces ====================
 .\"
 .SS Cgroup namespaces (CLONE_NEWCGROUP)
@@ -211,7 +332,7 @@ See
 .SS IPC namespaces (CLONE_NEWIPC)
 IPC namespaces isolate certain IPC resources,
 namely, System V IPC objects (see
-.BR svipc (7))
+.BR sysvipc (7))
 and (since Linux 2.6.30)
 .\" commit 7eafd7c74c3f2e67c27621b987b28397110d643f
 .\" https://lwn.net/Articles/312232/
@@ -220,13 +341,13 @@ POSIX message queues (see
 The common characteristic of these IPC mechanisms is that IPC
 objects are identified by mechanisms other than filesystem
 pathnames.
-
+.PP
 Each IPC namespace has its own set of System V IPC identifiers and
 its own POSIX message queue filesystem.
 Objects created in an IPC namespace are visible to all other processes
 that are members of that namespace,
 but are not visible to processes in other IPC namespaces.
-
+.PP
 The following
 .I /proc
 interfaces are distinct in each IPC namespace:
@@ -253,7 +374,7 @@ The System V IPC interfaces in
 When an IPC namespace is destroyed
 (i.e., when the last process that is a member of the namespace terminates),
 all IPC objects in the namespace are automatically destroyed.
-
+.PP
 Use of IPC namespaces requires a kernel that is configured with the
 .B CONFIG_IPC_NS
 option.
@@ -261,29 +382,8 @@ option.
 .\" ==================== Network namespaces ====================
 .\"
 .SS Network namespaces (CLONE_NEWNET)
-Network namespaces provide isolation of the system resources associated
-with networking: network devices, IPv4 and IPv6 protocol stacks,
-IP routing tables, firewalls, the
-.I /proc/net
-directory, the
-.I /sys/class/net
-directory, port numbers (sockets), and so on.
-A physical network device can live in exactly one
-network namespace.
-A virtual network device ("veth") pair provides a pipe-like abstraction
-.\" FIXME Add pointer to veth(4) page when it is eventually completed
-that can be used to create tunnels between network namespaces,
-and can be used to create a bridge to a physical network device
-in another namespace.
-
-When a network namespace is freed
-(i.e., when the last process in the namespace terminates),
-its physical network devices are moved back to the
-initial network namespace (not to the parent of the process).
-
-Use of network namespaces requires a kernel that is configured with the
-.B CONFIG_NET_NS
-option.
+See
+.BR network_namespaces (7).
 .\"
 .\" ==================== Mount namespaces ====================
 .\"
@@ -317,21 +417,63 @@ and can be retrieved using
 .BR gethostname (2),
 and
 .BR getdomainname (2).
-
+.PP
+.PP
+When a process creates a new UTS namespace using
+.BR clone (2)
+or
+.BR unshare (2)
+with the
+.BR CLONE_NEWUTS
+flag, the hostname and domain of the new UTS namespace are copied
+from the corresponding values in the caller's UTS namespace.
+.PP
 Use of UTS namespaces requires a kernel that is configured with the
 .B CONFIG_UTS_NS
 option.
-.SH CONFORMING TO
-Namespaces are a Linux-specific feature.
+.\"
+.SS Namespace lifetime
+Absent any other factors,
+a namespace is automatically torn down when the last process in
+the namespace terminates or leaves the namespace.
+However, there are a number of other factors that may pin
+a namespace into existence even though it has no member processes.
+These factors include the following:
+.IP * 3
+An open file descriptor or a bind mount exists for the corresponding
+.IR /proc/[pid]/ns/*
+file.
+.IP *
+The namespace is hierarchical (i.e., a PID or user namespace),
+and has a child namespace.
+.IP *
+It is a user namespace that owns one or more nonuser namespaces.
+.IP *
+It is a PID namespace,
+and there is a process that refers to the namespace via a
+.IR /proc/[pid]/ns/pid_for_children
+symbolic link.
+.IP *
+It is an IPC namespace, and a corresponding mount of an
+.I mqueue
+filesystem (see
+.BR mq_overview (7))
+refers to this namespace.
+.IP *
+It is a PID namespace, and a corresponding mount of a
+.BR proc (5)
+filesystem refers to this namespace.
 .SH EXAMPLE
 See
+.BR clone (2)
+and
 .BR user_namespaces (7).
 .SH SEE ALSO
-.BR lsns (1),
 .BR nsenter (1),
 .BR readlink (1),
 .BR unshare (1),
 .BR clone (2),
+.BR ioctl_ns (2),
 .BR setns (2),
 .BR unshare (2),
 .BR proc (5),
@@ -339,6 +481,9 @@ See
 .BR cgroup_namespaces (7),
 .BR cgroups (7),
 .BR credentials (7),
+.BR network_namespaces (7),
 .BR pid_namespaces (7),
 .BR user_namespaces (7),
+.BR lsns (8),
+.BR pam_namespace (8),
 .BR switch_root (8)