]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/unshare.2
clone.2, mount.2, unshare.2, proc.5, path_resolution.7: Global fix: s/mount-point...
[thirdparty/man-pages.git] / man2 / unshare.2
1 .\" Copyright (C) 2006, Janak Desai <janak@us.ibm.com>
2 .\" and Copyright (C) 2006, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Licensed under the GPL
4 .\"
5 .\" Patch Justification:
6 .\" unshare system call is needed to implement, using PAM,
7 .\" per-security_context and/or per-user namespace to provide
8 .\" polyinstantiated directories. Using unshare and bind mounts, a
9 .\" PAM module can create private namespace with appropriate
10 .\" directories(based on user's security context) bind mounted on
11 .\" public directories such as /tmp, thus providing an instance of
12 .\" /tmp that is based on user's security context. Without the
13 .\" unshare system call, namespace separation can only be achieved
14 .\" by clone, which would require porting and maintaining all commands
15 .\" such as login, and su, that establish a user session.
16 .\"
17 .\" FIXME Document CLONE_NEWIPC, which is new in 2.6.18
18 .\" FIXME Document CLONE_NEWUTS, which is new in 2.6.19
19 .\" FIXME Document CLONE_SYSVSEM, which is new in 2.6.26
20 .\"
21 .TH UNSHARE 2 2008-11-20 "Linux" "Linux Programmer's Manual"
22 .SH NAME
23 unshare \- disassociate parts of the process execution context
24 .SH SYNOPSIS
25 .nf
26 .B #define _GNU_SOURCE
27 .\" Actually _BSD_SOURCE || _SVID_SOURCE
28 .\" See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749
29 .B #include <sched.h>
30 .sp
31 .BI "int unshare(int " flags );
32 .fi
33 .SH DESCRIPTION
34 .BR unshare ()
35 allows a process to disassociate parts of its execution
36 context that are currently being shared with other processes.
37 Part of the execution context, such as the mount namespace, is shared
38 implicitly when a new process is created using
39 .BR fork (2)
40 or
41 .BR vfork (2),
42 while other parts, such as virtual memory, may be
43 shared by explicit request when creating a process using
44 .BR clone (2).
45
46 The main use of
47 .BR unshare ()
48 is to allow a process to control its
49 shared execution context without creating a new process.
50
51 The
52 .I flags
53 argument is a bit mask that specifies which parts of
54 the execution context should be unshared.
55 This argument is specified by ORing together zero or more
56 of the following constants:
57 .TP
58 .B CLONE_FILES
59 Reverse the effect of the
60 .BR clone (2)
61 .B CLONE_FILES
62 flag.
63 Unshare the file descriptor table, so that the calling process
64 no longer shares its file descriptors with any other process.
65 .TP
66 .B CLONE_FS
67 Reverse the effect of the
68 .BR clone (2)
69 .B CLONE_FS
70 flag.
71 Unshare file system attributes, so that the calling process
72 no longer shares its root directory, current directory,
73 or umask attributes with any other process.
74 .BR chroot (2),
75 .BR chdir (2),
76 or
77 .BR umask (2)
78 .TP
79 .B CLONE_NEWNS
80 .\" These flag name are inconsistent:
81 .\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM,
82 .\" CLONE_FS, and CLONE_FILES reverse the action of the clone()
83 .\" flags of the same name.
84 This flag has the
85 .I same
86 effect as the
87 .BR clone (2)
88 .B CLONE_NEWNS
89 flag.
90 Unshare the mount namespace,
91 so that the calling process has a private copy of
92 its namespace which is not shared with any other process.
93 Specifying this flag automatically implies
94 .B CLONE_FS
95 as well.
96 .\" As at 2.6.16, the following forced implications also apply,
97 .\" although the relevant flags are not yet implemented.
98 .\" If CLONE_THREAD is set force CLONE_VM.
99 .\" If CLONE_VM is set, force CLONE_SIGHAND.
100 .\" If CLONE_SIGHAND is set and signals are also being shared
101 .\" (i.e., current->signal->count > 1), force CLONE_THREAD.
102 .\"
103 .\" FIXME . CLONE_VM is not (yet, as at 2.6.16) implemented.
104 .\" .TP
105 .\" .B CLONE_VM
106 .\" Reverse the effect of the
107 .\" .BR clone (2)
108 .\" .B CLONE_VM
109 .\" flag.
110 .\" .RB ( CLONE_VM
111 .\" is also implicitly set by
112 .\" .BR vfork (2),
113 .\" and can be reversed using this
114 .\" .BR unshare ()
115 .\" flag.)
116 .\" Unshare virtual memory, so that the calling process no
117 .\" longer shares its virtual address space with any other process.
118 .PP
119 If
120 .I flags
121 is specified as zero, then
122 .BR unshare ()
123 is a no-op;
124 no changes are made to the calling process's execution context.
125 .SH RETURN VALUE
126 On success, zero returned.
127 On failure, \-1 is returned and
128 .I errno
129 is set to indicate the error.
130 .SH ERRORS
131 .TP
132 .B EINVAL
133 An invalid bit was specified in
134 .IR flags .
135 .TP
136 .B ENOMEM
137 Cannot allocate sufficient memory to copy parts of caller's
138 context that need to be unshared.
139 .TP
140 .B EPERM
141 .I flags
142 specified
143 .B CLONE_NEWNS
144 but the calling process was not privileged (did not have the
145 .B CAP_SYS_ADMIN
146 capability).
147 .SH VERSIONS
148 The
149 .BR unshare ()
150 system call was added to Linux in kernel 2.6.16.
151 .SH CONFORMING TO
152 The
153 .BR unshare ()
154 system call is Linux-specific.
155 .SH NOTES
156 Not all of the process attributes that can be shared when
157 a new process is created using
158 .BR clone (2)
159 can be unshared using
160 .BR unshare ().
161 In particular, as at kernel 2.6.16,
162 .BR unshare ()
163 does not implement flags that reverse the effects of
164 .BR CLONE_SIGHAND ,
165 .\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND
166 .\" was not specified when doing clone(); i.e., unsharing
167 .\" signal handlers is permitted if we are not actually
168 .\" sharing signal handlers. mtk
169 .BR CLONE_SYSVSEM ,
170 .BR CLONE_THREAD ,
171 or
172 .\" FIXME . check future kernel versions (e.g., 2.6.17)
173 .\" to see if CLONE_VM gets implemented.
174 .BR CLONE_VM .
175 .\" However, as at 2.6.16, we can do unshare(CLONE_VM) if CLONE_VM
176 .\" was not specified when doing clone(); i.e., unsharing
177 .\" virtual memory is permitted if we are not actually
178 .\" sharing virtual memory. mtk
179 Such functionality may be added in the future, if required.
180 .\"
181 .\"9) Future Work
182 .\"--------------
183 .\"The current implementation of unshare does not allow unsharing of
184 .\"signals and signal handlers. Signals are complex to begin with and
185 .\"to unshare signals and/or signal handlers of a currently running
186 .\"process is even more complex. If in the future there is a specific
187 .\"need to allow unsharing of signals and/or signal handlers, it can
188 .\"be incrementally added to unshare without affecting legacy
189 .\"applications using unshare.
190 .\"
191 .SH SEE ALSO
192 .BR clone (2),
193 .BR fork (2),
194 .BR vfork (2),
195 Documentation/unshare.txt