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 .\" 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
21 .TH UNSHARE 2 2008-11-20 "Linux" "Linux Programmer's Manual"
23 unshare \- disassociate parts of the process execution context
26 .B #define _GNU_SOURCE
27 .\" Actually _BSD_SOURCE || _SVID_SOURCE
28 .\" See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749
31 .BI "int unshare(int " flags );
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
42 while other parts, such as virtual memory, may be
43 shared by explicit request when creating a process using
48 is to allow a process to control its
49 shared execution context without creating a new process.
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:
59 Reverse the effect of the
63 Unshare the file descriptor table, so that the calling process
64 no longer shares its file descriptors with any other process.
67 Reverse the effect of the
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.
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.
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
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.
103 .\" FIXME . CLONE_VM is not (yet, as at 2.6.16) implemented.
106 .\" Reverse the effect of the
111 .\" is also implicitly set by
113 .\" and can be reversed using this
116 .\" Unshare virtual memory, so that the calling process no
117 .\" longer shares its virtual address space with any other process.
121 is specified as zero, then
124 no changes are made to the calling process's execution context.
126 On success, zero returned.
127 On failure, \-1 is returned and
129 is set to indicate the error.
133 An invalid bit was specified in
137 Cannot allocate sufficient memory to copy parts of caller's
138 context that need to be unshared.
144 but the calling process was not privileged (did not have the
150 system call was added to Linux in kernel 2.6.16.
154 system call is Linux-specific.
156 Not all of the process attributes that can be shared when
157 a new process is created using
159 can be unshared using
161 In particular, as at kernel 2.6.16,
163 does not implement flags that reverse the effects of
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
172 .\" FIXME . check future kernel versions (e.g., 2.6.17)
173 .\" to see if CLONE_VM gets implemented.
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.
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.
195 Documentation/unshare.txt