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
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.
17 .TH UNSHARE 2 2010-10-30 "Linux" "Linux Programmer's Manual"
19 unshare \- disassociate parts of the process execution context
22 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
23 .\" Actually _BSD_SOURCE || _SVID_SOURCE
24 .\" FIXME See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749
27 .BI "int unshare(int " flags );
31 allows a process to disassociate parts of its execution
32 context that are currently being shared with other processes.
33 Part of the execution context, such as the mount namespace, is shared
34 implicitly when a new process is created using
38 while other parts, such as virtual memory, may be
39 shared by explicit request when creating a process using
44 is to allow a process to control its
45 shared execution context without creating a new process.
49 argument is a bit mask that specifies which parts of
50 the execution context should be unshared.
51 This argument is specified by ORing together zero or more
52 of the following constants:
55 Reverse the effect of the
59 Unshare the file descriptor table, so that the calling process
60 no longer shares its file descriptors with any other process.
63 Reverse the effect of the
67 Unshare file system attributes, so that the calling process
68 no longer shares its root directory, current directory,
69 or umask attributes with any other process.
75 .BR CLONE_NEWIPC " (since Linux 2.6.19)
76 This flag has the same effect as the
80 Unshare the System V IPC namespace,
81 so that the calling process has a private copy of the
82 System V IPC namespace which is not shared with any other process.
83 Specifying this flag automatically implies
92 .BR CLONE_NEWNET " (since Linux 2.6.24)
93 This flag has the same effect as the
97 Unshare the network namespace,
98 so that the calling process is moved into a
99 new network namespace which is not shared
100 with any previously existing process.
107 .\" These flag name are inconsistent:
108 .\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM,
109 .\" CLONE_FS, and CLONE_FILES reverse the action of the clone()
110 .\" flags of the same name.
111 This flag has the same effect as the
115 Unshare the mount namespace,
116 so that the calling process has a private copy of
117 its namespace which is not shared with any other process.
118 Specifying this flag automatically implies
127 .BR CLONE_SYSVSEM " (since Linux 2.6.26)
128 .\" commit 9edff4ab1f8d82675277a04e359d0ed8bf14a7b7
129 This flag reverses the effect of the
133 Unshare System V semaphore undo values,
134 so that the calling process has a private copy
135 which is not shared with any other process.
142 .BR CLONE_NEWUTS " (since Linux 2.6.19)
143 This flag has the same effect as the
147 Unshare the UTS IPC namespace,
148 so that the calling process has a private copy of the
149 UTS namespace which is not shared with any other process.
155 .\" As at 2.6.16, the following forced implications also apply,
156 .\" although the relevant flags are not yet implemented.
157 .\" If CLONE_THREAD is set force CLONE_VM.
158 .\" If CLONE_VM is set, force CLONE_SIGHAND.
159 .\" CLONE_NEWNSIf CLONE_SIGHAND is set and signals are also being shared
160 .\" (i.e., current->signal->count > 1), force CLONE_THREAD.
162 .\" FIXME . CLONE_VM is not (yet, as at 2.6.16) implemented.
165 .\" Reverse the effect of the
170 .\" is also implicitly set by
172 .\" and can be reversed using this
175 .\" Unshare virtual memory, so that the calling process no
176 .\" longer shares its virtual address space with any other process.
180 is specified as zero, then
183 no changes are made to the calling process's execution context.
185 On success, zero returned.
186 On failure, \-1 is returned and
188 is set to indicate the error.
192 An invalid bit was specified in
196 Cannot allocate sufficient memory to copy parts of caller's
197 context that need to be unshared.
200 The calling process did not have the required privileges for this operation.
204 system call was added to Linux in kernel 2.6.16.
208 system call is Linux-specific.
210 Not all of the process attributes that can be shared when
211 a new process is created using
213 can be unshared using
215 In particular, as at kernel 2.6.16,
216 .\" FIXME all of the following needs to be reviewed for the current kernel
218 does not implement flags that reverse the effects of
220 .\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND
221 .\" was not specified when doing clone(); i.e., unsharing
222 .\" signal handlers is permitted if we are not actually
223 .\" sharing signal handlers. mtk
227 .\" FIXME . check future kernel versions (e.g., 2.6.17)
228 .\" to see if CLONE_VM gets implemented.
230 .\" However, as at 2.6.16, we can do unshare(CLONE_VM) if CLONE_VM
231 .\" was not specified when doing clone(); i.e., unsharing
232 .\" virtual memory is permitted if we are not actually
233 .\" sharing virtual memory. mtk
234 Such functionality may be added in the future, if required.
238 .\"The current implementation of unshare does not allow unsharing of
239 .\"signals and signal handlers. Signals are complex to begin with and
240 .\"to unshare signals and/or signal handlers of a currently running
241 .\"process is even more complex. If in the future there is a specific
242 .\"need to allow unsharing of signals and/or signal handlers, it can
243 .\"be incrementally added to unshare without affecting legacy
244 .\"applications using unshare.
253 .I Documentation/unshare.txt
254 in the Linux kernel source tree