1 .\" Copyright (C) 2006, Janak Desai <janak@us.ibm.com>
2 .\" and Copyright (C) 2006, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
5 .\" Licensed under the GPL
8 .\" Patch Justification:
9 .\" unshare system call is needed to implement, using PAM,
10 .\" per-security_context and/or per-user namespace to provide
11 .\" polyinstantiated directories. Using unshare and bind mounts, a
12 .\" PAM module can create private namespace with appropriate
13 .\" directories(based on user's security context) bind mounted on
14 .\" public directories such as /tmp, thus providing an instance of
15 .\" /tmp that is based on user's security context. Without the
16 .\" unshare system call, namespace separation can only be achieved
17 .\" by clone, which would require porting and maintaining all commands
18 .\" such as login, and su, that establish a user session.
20 .TH UNSHARE 2 2012-12-31 "Linux" "Linux Programmer's Manual"
22 unshare \- disassociate parts of the process execution context
27 .BI "int unshare(int " flags );
31 Feature Test Macro Requirements for glibc (see
32 .BR feature_test_macros (7)):
43 .\" FIXME See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749
45 _BSD_SOURCE || _SVID_SOURCE
46 /* _GNU_SOURCE also suffices */
52 allows a process to disassociate parts of its execution
53 context that are currently being shared with other processes.
54 Part of the execution context, such as the mount namespace, is shared
55 implicitly when a new process is created using
59 while other parts, such as virtual memory, may be
60 shared by explicit request when creating a process using
65 is to allow a process to control its
66 shared execution context without creating a new process.
70 argument is a bit mask that specifies which parts of
71 the execution context should be unshared.
72 This argument is specified by ORing together zero or more
73 of the following constants:
76 Reverse the effect of the
80 Unshare the file descriptor table, so that the calling process
81 no longer shares its file descriptors with any other process.
84 Reverse the effect of the
88 Unshare file system attributes, so that the calling process
89 no longer shares its root directory
95 attributes with any other process.
97 .BR CLONE_NEWIPC " (since Linux 2.6.19)
98 This flag has the same effect as the
102 Unshare the System V IPC namespace,
103 so that the calling process has a private copy of the
104 System V IPC namespace which is not shared with any other process.
105 Specifying this flag automatically implies
114 .BR CLONE_NEWNET " (since Linux 2.6.24)
115 This flag has the same effect as the
119 Unshare the network namespace,
120 so that the calling process is moved into a
121 new network namespace which is not shared
122 with any previously existing process.
130 .\" These flag name are inconsistent:
131 .\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM,
132 .\" CLONE_FS, and CLONE_FILES reverse the action of the clone()
133 .\" flags of the same name.
134 This flag has the same effect as the
138 Unshare the mount namespace,
139 so that the calling process has a private copy of
140 its namespace which is not shared with any other process.
141 Specifying this flag automatically implies
150 .BR CLONE_NEWUTS " (since Linux 2.6.19)
151 This flag has the same effect as the
155 Unshare the UTS IPC namespace,
156 so that the calling process has a private copy of the
157 UTS namespace which is not shared with any other process.
164 .BR CLONE_SYSVSEM " (since Linux 2.6.26)
165 .\" commit 9edff4ab1f8d82675277a04e359d0ed8bf14a7b7
166 This flag reverses the effect of the
170 Unshare System V semaphore undo values,
171 so that the calling process has a private copy
172 which is not shared with any other process.
178 .\" As at 2.6.16, the following forced implications also apply,
179 .\" although the relevant flags are not yet implemented.
180 .\" If CLONE_THREAD is set force CLONE_VM.
181 .\" If CLONE_VM is set, force CLONE_SIGHAND.
182 .\" CLONE_NEWNSIf CLONE_SIGHAND is set and signals are also being shared
183 .\" (i.e., current->signal->count > 1), force CLONE_THREAD.
185 .\" FIXME . CLONE_VM is not (yet, as at 2.6.16) implemented.
188 .\" Reverse the effect of the
193 .\" is also implicitly set by
195 .\" and can be reversed using this
198 .\" Unshare virtual memory, so that the calling process no
199 .\" longer shares its virtual address space with any other process.
203 is specified as zero, then
206 no changes are made to the calling process's execution context.
208 On success, zero returned.
209 On failure, \-1 is returned and
211 is set to indicate the error.
215 An invalid bit was specified in
219 Cannot allocate sufficient memory to copy parts of caller's
220 context that need to be unshared.
223 The calling process did not have the required privileges for this operation.
227 system call was added to Linux in kernel 2.6.16.
231 system call is Linux-specific.
233 Not all of the process attributes that can be shared when
234 a new process is created using
236 can be unshared using
238 In particular, as at kernel 3.8,
239 .\" FIXME all of the following needs to be reviewed for the current kernel
241 does not implement flags that reverse the effects of
243 .\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND
244 .\" was not specified when doing clone(); i.e., unsharing
245 .\" signal handlers is permitted if we are not actually
246 .\" sharing signal handlers. mtk
250 .\" However, we can do unshare(CLONE_VM) if CLONE_VM
251 .\" was not specified when doing clone(); i.e., unsharing
252 .\" virtual memory is permitted if we are not actually
253 .\" sharing virtual memory. mtk
254 Such functionality may be added in the future, if required.
258 .\"The current implementation of unshare does not allow unsharing of
259 .\"signals and signal handlers. Signals are complex to begin with and
260 .\"to unshare signals and/or signal handlers of a currently running
261 .\"process is even more complex. If in the future there is a specific
262 .\"need to allow unsharing of signals and/or signal handlers, it can
263 .\"be incrementally added to unshare without affecting legacy
264 .\"applications using unshare.
273 .I Documentation/unshare.txt
274 in the Linux kernel source tree