]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/unshare.2
unshare.2: Dcoument CLONE_SYSVSEM
[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 .TH UNSHARE 2 2010-10-24 "Linux" "Linux Programmer's Manual"
18 .SH NAME
19 unshare \- disassociate parts of the process execution context
20 .SH SYNOPSIS
21 .nf
22 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
23 .\" Actually _BSD_SOURCE || _SVID_SOURCE
24 .\" See http://sources.redhat.com/bugzilla/show_bug.cgi?id=4749
25 .B #include <sched.h>
26 .sp
27 .BI "int unshare(int " flags );
28 .fi
29 .SH DESCRIPTION
30 .BR unshare ()
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
35 .BR fork (2)
36 or
37 .BR vfork (2),
38 while other parts, such as virtual memory, may be
39 shared by explicit request when creating a process using
40 .BR clone (2).
41
42 The main use of
43 .BR unshare ()
44 is to allow a process to control its
45 shared execution context without creating a new process.
46
47 The
48 .I flags
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:
53 .TP
54 .B CLONE_FILES
55 Reverse the effect of the
56 .BR clone (2)
57 .B CLONE_FILES
58 flag.
59 Unshare the file descriptor table, so that the calling process
60 no longer shares its file descriptors with any other process.
61 .TP
62 .B CLONE_FS
63 Reverse the effect of the
64 .BR clone (2)
65 .B CLONE_FS
66 flag.
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.
70 .BR chroot (2),
71 .BR chdir (2),
72 or
73 .BR umask (2)
74 .TP
75 .BR CLONE_NEWIPC " (since Linux 2.6.19)
76 This flag has the same effect as the
77 .BR clone (2)
78 .B CLONE_NEWIPC
79 flag.
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
84 .BR CLONE_SYSVSEM
85 as well.
86 Use of
87 .BR CLONE_NEWIPC
88 requires the
89 .BR CAP_SYS_ADMIN
90 capability.
91 .TP
92 .B CLONE_NEWNS
93 .\" These flag name are inconsistent:
94 .\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM,
95 .\" CLONE_FS, and CLONE_FILES reverse the action of the clone()
96 .\" flags of the same name.
97 This flag has the same effect as the
98 .BR clone (2)
99 .B CLONE_NEWNS
100 flag.
101 Unshare the mount namespace,
102 so that the calling process has a private copy of
103 its namespace which is not shared with any other process.
104 Specifying this flag automatically implies
105 .B CLONE_FS
106 as well.
107 Use of
108 .BR CLONE_NEWNS
109 requires the
110 .BR CAP_SYS_ADMIN
111 capability.
112 .TP
113 .BR CLONE_SYSVSEM " (since Linux 2.6.26)
114 This flag reverses the effect of the
115 .BR clone (2)
116 .B CLONE_SYSVSEM
117 flag.
118 Unshare System V semaphore undo values,
119 so that the calling process has a private copy
120 which is not shared with any other process.
121 Use of
122 .BR CLONE_SYSVSEM
123 requires the
124 .BR CAP_SYS_ADMIN
125 capability.
126 .\" As at 2.6.16, the following forced implications also apply,
127 .\" although the relevant flags are not yet implemented.
128 .\" If CLONE_THREAD is set force CLONE_VM.
129 .\" If CLONE_VM is set, force CLONE_SIGHAND.
130 .\" CLONE_NEWNSIf CLONE_SIGHAND is set and signals are also being shared
131 .\" (i.e., current->signal->count > 1), force CLONE_THREAD.
132 .\"
133 .\" FIXME . CLONE_VM is not (yet, as at 2.6.16) implemented.
134 .\" .TP
135 .\" .B CLONE_VM
136 .\" Reverse the effect of the
137 .\" .BR clone (2)
138 .\" .B CLONE_VM
139 .\" flag.
140 .\" .RB ( CLONE_VM
141 .\" is also implicitly set by
142 .\" .BR vfork (2),
143 .\" and can be reversed using this
144 .\" .BR unshare ()
145 .\" flag.)
146 .\" Unshare virtual memory, so that the calling process no
147 .\" longer shares its virtual address space with any other process.
148 .PP
149 If
150 .I flags
151 is specified as zero, then
152 .BR unshare ()
153 is a no-op;
154 no changes are made to the calling process's execution context.
155 .SH RETURN VALUE
156 On success, zero returned.
157 On failure, \-1 is returned and
158 .I errno
159 is set to indicate the error.
160 .SH ERRORS
161 .TP
162 .B EINVAL
163 An invalid bit was specified in
164 .IR flags .
165 .TP
166 .B ENOMEM
167 Cannot allocate sufficient memory to copy parts of caller's
168 context that need to be unshared.
169 .TP
170 .B EPERM
171 The calling process did not have the required privileges for this operation.
172 .SH VERSIONS
173 The
174 .BR unshare ()
175 system call was added to Linux in kernel 2.6.16.
176 .SH CONFORMING TO
177 The
178 .BR unshare ()
179 system call is Linux-specific.
180 .SH NOTES
181 Not all of the process attributes that can be shared when
182 a new process is created using
183 .BR clone (2)
184 can be unshared using
185 .BR unshare ().
186 In particular, as at kernel 2.6.16,
187 .BR unshare ()
188 does not implement flags that reverse the effects of
189 .BR CLONE_SIGHAND ,
190 .\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND
191 .\" was not specified when doing clone(); i.e., unsharing
192 .\" signal handlers is permitted if we are not actually
193 .\" sharing signal handlers. mtk
194 .BR CLONE_SYSVSEM ,
195 .BR CLONE_THREAD ,
196 or
197 .\" FIXME . check future kernel versions (e.g., 2.6.17)
198 .\" to see if CLONE_VM gets implemented.
199 .BR CLONE_VM .
200 .\" However, as at 2.6.16, we can do unshare(CLONE_VM) if CLONE_VM
201 .\" was not specified when doing clone(); i.e., unsharing
202 .\" virtual memory is permitted if we are not actually
203 .\" sharing virtual memory. mtk
204 Such functionality may be added in the future, if required.
205 .\"
206 .\"9) Future Work
207 .\"--------------
208 .\"The current implementation of unshare does not allow unsharing of
209 .\"signals and signal handlers. Signals are complex to begin with and
210 .\"to unshare signals and/or signal handlers of a currently running
211 .\"process is even more complex. If in the future there is a specific
212 .\"need to allow unsharing of signals and/or signal handlers, it can
213 .\"be incrementally added to unshare without affecting legacy
214 .\"applications using unshare.
215 .\"
216 .SH SEE ALSO
217 .BR clone (2),
218 .BR fork (2),
219 .BR vfork (2),
220 Documentation/unshare.txt