1 .\" (C) 2006, Janak Desai <janak@us.ibm.com>
2 .\" (C) 2006, Michael Kerrisk <mtk-manpages@gmx.ne>
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
20 .TH UNSHARE 2 2007-07-26 "Linux" "Linux Programmer's Manual"
22 unshare \- disassociate parts of the process execution context
25 .B #define _GNU_SOURCE
26 .\" Actually _BSD_SOURCE || _SVID_SOURCE
27 .\" See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749
30 .BI "int unshare(int " flags );
34 allows a process to disassociate parts of its execution
35 context that are currently being shared with other processes.
36 Part of the execution context, such as the namespace, is shared
37 implicitly when a new process is created using
41 while other parts, such as virtual memory, may be
42 shared by explicit request when creating a process using
47 is to allow a process to control its
48 shared execution context without creating a new process.
52 argument is a bit mask that specifies which parts of
53 the execution context should be unshared.
54 This argument is specified by ORing together zero or more
55 of the following constants:
58 Reverse the effect of the
62 Unshare the file descriptor table, so that the calling process
63 no longer shares its file descriptors with any other process.
66 Reverse the effect of the
70 Unshare file system attributes, so that the calling process
71 no longer shares its root directory, current directory,
72 or umask attributes with any other process.
79 .\" These flag name are inconsistent:
80 .\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM,
81 .\" CLONE_FS, and CLONE_FILES reverse the action of the clone()
82 .\" flags of the same name.
89 Unshare the namespace, so that the calling process has a private copy of
90 its namespace which is not shared with any other process.
91 Specifying this flag automatically implies
94 .\" As at 2.6.16, the following forced implications also apply,
95 .\" although the relevant flags are not yet implemented.
96 .\" If CLONE_THREAD is set force CLONE_VM.
97 .\" If CLONE_VM is set, force CLONE_SIGHAND.
98 .\" If CLONE_SIGHAND is set and signals are also being shared
99 .\" (i.e., current->signal->count > 1), force CLONE_THREAD.
101 .\" FIXME . CLONE_VM is not (yet, as at 2.6.16) implemented.
104 .\" Reverse the effect of the
109 .\" is also implicitly set by
111 .\" and can be reversed using this
114 .\" Unshare virtual memory, so that the calling process no
115 .\" longer shares its virtual address space with any other process.
119 is specified as zero, then
122 no changes are made to the calling process's execution context.
124 On success, zero returned.
125 On failure, \-1 is returned and
127 is set to indicate the error.
134 but the calling process was not privileged (did not have the
139 Cannot allocate sufficient memory to copy parts of caller's
140 context that need to be unshared.
143 An invalid bit was specified in
148 system call was added to Linux in kernel 2.6.16.
152 system call is Linux specific.
154 Not all of the process attributes that can be shared when
155 a new process is created using
157 can be unshared using
159 In particular, as at kernel 2.6.16,
161 does not implement flags that reverse the effects of
163 .\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND
164 .\" was not specified when doing clone(); i.e., unsharing
165 .\" signal handlers is permitted if we are not actually
166 .\" sharing signal handlers. mtk
170 .\" FIXME . check future kernel versions (e.g., 2.6.17)
171 .\" to see if CLONE_VM gets implemented.
173 .\" However, as at 2.6.16, we can do unshare(CLONE_VM) if CLONE_VM
174 .\" was not specified when doing clone(); i.e., unsharing
175 .\" virtual memory is permitted if we are not actually
176 .\" sharing virtual memory. mtk
177 Such functionality may be added in the future, if required.
181 .\"The current implementation of unshare does not allow unsharing of
182 .\"signals and signal handlers. Signals are complex to begin with and
183 .\"to unshare signals and/or signal handlers of a currently running
184 .\"process is even more complex. If in the future there is a specific
185 .\"need to allow unsharing of signals and/or signal handlers, it can
186 .\"be incrementally added to unshare without affecting legacy
187 .\"applications using unshare.
193 Documentation/unshare.txt