Debian Codegraph @

templates/man2/seccomp_unotify.2.pot

raw
1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5 #
6 #, fuzzy
7 msgid ""
8 msgstr ""
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2026-06-05 06:42+0200\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <[email protected]>\n"
14 "Language: \n"
15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n"
17 "Content-Transfer-Encoding: 8bit\n"
18
19 #. type: TH
20 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
21 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
22 #, no-wrap
23 msgid "seccomp_unotify"
24 msgstr ""
25
26 #. type: TH
27 #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed
28 #, no-wrap
29 msgid "2026-02-22"
30 msgstr ""
31
32 #. type: TH
33 #: archlinux debian-unstable
34 #, no-wrap
35 msgid "Linux man-pages 6.18"
36 msgstr ""
37
38 #. type: SH
39 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
40 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
41 #, no-wrap
42 msgid "NAME"
43 msgstr ""
44
45 #. type: Plain text
46 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
47 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
48 msgid "seccomp_unotify - Seccomp user-space notification mechanism"
49 msgstr ""
50
51 #. type: SH
52 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
53 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
54 #, no-wrap
55 msgid "LIBRARY"
56 msgstr ""
57
58 #. type: Plain text
59 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
60 #: opensuse-leap-16-1 opensuse-tumbleweed
61 msgid "Standard C library (I<libc>,\\ I<-lc>)"
62 msgstr ""
63
64 #. type: SH
65 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
66 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
67 #, no-wrap
68 msgid "SYNOPSIS"
69 msgstr ""
70
71 #. type: Plain text
72 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
73 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
74 #, no-wrap
75 msgid ""
76 "B<#include E<lt>linux/seccomp.hE<gt>>\n"
77 "B<#include E<lt>linux/filter.hE<gt>>\n"
78 "B<#include E<lt>linux/audit.hE<gt>>\n"
79 msgstr ""
80
81 #. type: Plain text
82 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
83 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
84 #, no-wrap
85 msgid "B<int seccomp(unsigned int >I<operation>B<, unsigned int >I<flags>B<, void *>I<args>B<);>\n"
86 msgstr ""
87
88 #. type: Plain text
89 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
90 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
91 #, no-wrap
92 msgid "B<#include E<lt>sys/ioctl.hE<gt>>\n"
93 msgstr ""
94
95 #. type: Plain text
96 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
97 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
98 #, no-wrap
99 msgid ""
100 "B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_RECV,>\n"
101 "B< struct seccomp_notif *>I<req>B<);>\n"
102 "B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_SEND,>\n"
103 "B< struct seccomp_notif_resp *>I<resp>B<);>\n"
104 "B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_ID_VALID, __u64 *>I<id>B<);>\n"
105 "B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_ADDFD,>\n"
106 "B< struct seccomp_notif_addfd *>I<addfd>B<);>\n"
107 msgstr ""
108
109 #. type: SH
110 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
111 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
112 #, no-wrap
113 msgid "DESCRIPTION"
114 msgstr ""
115
116 #. type: Plain text
117 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
118 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
119 msgid ""
120 "This page describes the user-space notification mechanism provided by the "
121 "Secure Computing (seccomp) facility. As well as the use of the "
122 "B<SECCOMP_FILTER_FLAG_NEW_LISTENER> flag, the B<SECCOMP_RET_USER_NOTIF> "
123 "action value, and the B<SECCOMP_GET_NOTIF_SIZES> operation described in "
124 "B<seccomp>(2), this mechanism involves the use of a number of related "
125 "B<ioctl>(2) operations (described below)."
126 msgstr ""
127
128 #. type: SS
129 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
130 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
131 #, no-wrap
132 msgid "Overview"
133 msgstr ""
134
135 #. type: Plain text
136 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
137 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
138 msgid ""
139 "In conventional usage of a seccomp filter, the decision about how to treat a "
140 "system call is made by the filter itself. By contrast, the user-space "
141 "notification mechanism allows the seccomp filter to delegate the handling of "
142 "the system call to another user-space process. Note that this mechanism is "
143 "explicitly B<not> intended as a method implementing security policy; see "
144 "NOTES."
145 msgstr ""
146
147 #. type: Plain text
148 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
149 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
150 msgid ""
151 "In the discussion that follows, the thread(s) on which the seccomp filter is "
152 "installed is (are) referred to as the I<target>, and the process that is "
153 "notified by the user-space notification mechanism is referred to as the "
154 "I<supervisor>."
155 msgstr ""
156
157 #. type: Plain text
158 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
159 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
160 msgid ""
161 "A suitably privileged supervisor can use the user-space notification "
162 "mechanism to perform actions on behalf of the target. The advantage of the "
163 "user-space notification mechanism is that the supervisor will usually be "
164 "able to retrieve information about the target and the performed system call "
165 "that the seccomp filter itself cannot. (A seccomp filter is limited in the "
166 "information it can obtain and the actions that it can perform because it is "
167 "running on a virtual machine inside the kernel.)"
168 msgstr ""
169
170 #. -------------------------------------
171 #. type: Plain text
172 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
173 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
174 msgid ""
175 "An overview of the steps performed by the target and the supervisor is as "
176 "follows:"
177 msgstr ""
178
179 #. type: IP
180 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
181 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
182 #, no-wrap
183 msgid "(1)"
184 msgstr ""
185
186 #. type: Plain text
187 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
188 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
189 msgid ""
190 "The target establishes a seccomp filter in the usual manner, but with two "
191 "differences:"
192 msgstr ""
193
194 #. type: IP
195 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
196 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
197 #, no-wrap
198 msgid "\\[bu]"
199 msgstr ""
200
201 #
202 #
203 #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
204 #. FIXME
205 #. Is the last sentence above correct?
206 #. Kees Cook (25 Oct 2020) notes:
207 #. I like this limitation, but I expect that it'll need to change in the
208 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
209 #. idea of there being only 1 supervisor will eventually break down. Right
210 #. now there is only 1 because only container managers are using this
211 #. feature. But if some daemon starts using it to isolate some thread,
212 #. suddenly it might break if a container manager is trying to listen to it
213 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
214 #. type: Plain text
215 #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
216 #. FIXME
217 #. Is the last sentence above correct?
218 #. Kees Cook (25 Oct 2020) notes:
219 #. I like this limitation, but I expect that it'll need to change in the
220 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
221 #. idea of there being only 1 supervisor will eventually break down. Right
222 #. now there is only 1 because only container managers are using this
223 #. feature. But if some daemon starts using it to isolate some thread,
224 #. suddenly it might break if a container manager is trying to listen to it
225 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
226 #. type: Plain text
227 #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
228 #. FIXME
229 #. Is the last sentence above correct?
230 #. Kees Cook (25 Oct 2020) notes:
231 #. I like this limitation, but I expect that it'll need to change in the
232 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
233 #. idea of there being only 1 supervisor will eventually break down. Right
234 #. now there is only 1 because only container managers are using this
235 #. feature. But if some daemon starts using it to isolate some thread,
236 #. suddenly it might break if a container manager is trying to listen to it
237 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
238 #. type: Plain text
239 #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
240 #. FIXME
241 #. Is the last sentence above correct?
242 #. Kees Cook (25 Oct 2020) notes:
243 #. I like this limitation, but I expect that it'll need to change in the
244 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
245 #. idea of there being only 1 supervisor will eventually break down. Right
246 #. now there is only 1 because only container managers are using this
247 #. feature. But if some daemon starts using it to isolate some thread,
248 #. suddenly it might break if a container manager is trying to listen to it
249 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
250 #. type: Plain text
251 #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
252 #. FIXME
253 #. Is the last sentence above correct?
254 #. Kees Cook (25 Oct 2020) notes:
255 #. I like this limitation, but I expect that it'll need to change in the
256 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
257 #. idea of there being only 1 supervisor will eventually break down. Right
258 #. now there is only 1 because only container managers are using this
259 #. feature. But if some daemon starts using it to isolate some thread,
260 #. suddenly it might break if a container manager is trying to listen to it
261 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
262 #. type: Plain text
263 #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
264 #. FIXME
265 #. Is the last sentence above correct?
266 #. Kees Cook (25 Oct 2020) notes:
267 #. I like this limitation, but I expect that it'll need to change in the
268 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
269 #. idea of there being only 1 supervisor will eventually break down. Right
270 #. now there is only 1 because only container managers are using this
271 #. feature. But if some daemon starts using it to isolate some thread,
272 #. suddenly it might break if a container manager is trying to listen to it
273 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
274 #. type: Plain text
275 #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
276 #. FIXME
277 #. Is the last sentence above correct?
278 #. Kees Cook (25 Oct 2020) notes:
279 #. I like this limitation, but I expect that it'll need to change in the
280 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
281 #. idea of there being only 1 supervisor will eventually break down. Right
282 #. now there is only 1 because only container managers are using this
283 #. feature. But if some daemon starts using it to isolate some thread,
284 #. suddenly it might break if a container manager is trying to listen to it
285 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
286 #. type: Plain text
287 #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
288 #. FIXME
289 #. Is the last sentence above correct?
290 #. Kees Cook (25 Oct 2020) notes:
291 #. I like this limitation, but I expect that it'll need to change in the
292 #. future. Even with LSMs, we see the need for arbitrary stacking, and the
293 #. idea of there being only 1 supervisor will eventually break down. Right
294 #. now there is only 1 because only container managers are using this
295 #. feature. But if some daemon starts using it to isolate some thread,
296 #. suddenly it might break if a container manager is trying to listen to it
297 #. too, etc. I expect it won't be needed soon, but I do think it'll change.
298 #. type: Plain text
299 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
300 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
301 msgid ""
302 "The B<seccomp>(2) I<flags> argument includes the flag "
303 "B<SECCOMP_FILTER_FLAG_NEW_LISTENER>. Consequently, the return value of the "
304 "(successful) B<seccomp>(2) call is a new \"listening\" file descriptor "
305 "that can be used to receive notifications. Only one \"listening\" seccomp "
306 "filter can be installed for a thread."
307 msgstr ""
308
309 #. type: Plain text
310 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
311 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
312 msgid ""
313 "In cases where it is appropriate, the seccomp filter returns the action "
314 "value B<SECCOMP_RET_USER_NOTIF>. This return value will trigger a "
315 "notification event."
316 msgstr ""
317
318 #. type: IP
319 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
320 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
321 #, no-wrap
322 msgid "(2)"
323 msgstr ""
324
325 #. Jann Horn:
326 #. Instead of using unix domain sockets to send the fd to the
327 #. parent, I think you could also use clone3() with
328 #. flags==CLONE_FILES|SIGCHLD, dup2() the seccomp fd to an fd
329 #. that was reserved in the parent, call unshare(CLONE_FILES)
330 #. in the child after setting up the seccomp fd, and wake
331 #. up the parent with something like pthread_cond_signal()?
332 #. I'm not sure whether that'd look better or worse in the
333 #. end though, so maybe just ignore this comment.
334 #. -------------------------------------
335 #. type: Plain text
336 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
337 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
338 msgid ""
339 "In order that the supervisor can obtain notifications using the listening "
340 "file descriptor, (a duplicate of) that file descriptor must be passed from "
341 "the target to the supervisor. One way in which this could be done is by "
342 "passing the file descriptor over a UNIX domain socket connection between the "
343 "target and the supervisor (using the B<SCM_RIGHTS> ancillary message type "
344 "described in B<unix>(7)). Another way to do this is through the use of "
345 "B<pidfd_getfd>(2)."
346 msgstr ""
347
348 #. type: IP
349 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
350 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
351 #, no-wrap
352 msgid "(3)"
353 msgstr ""
354
355 #. -------------------------------------
356 #. type: Plain text
357 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
358 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
359 msgid ""
360 "The supervisor will receive notification events on the listening file "
361 "descriptor. These events are returned as structures of type "
362 "I<seccomp_notif>. Because this structure and its size may evolve over "
363 "kernel versions, the supervisor must first determine the size of this "
364 "structure using the B<seccomp>(2) B<SECCOMP_GET_NOTIF_SIZES> operation, "
365 "which returns a structure of type I<seccomp_notif_sizes>. The supervisor "
366 "allocates a buffer of size I<seccomp_notif_sizes.seccomp_notif> bytes to "
367 "receive notification events. In addition,the supervisor allocates another "
368 "buffer of size I<seccomp_notif_sizes.seccomp_notif_resp> bytes for the "
369 "response (a I<struct seccomp_notif_resp> structure) that it will provide to "
370 "the kernel (and thus the target)."
371 msgstr ""
372
373 #. type: IP
374 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
375 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
376 #, no-wrap
377 msgid "(4)"
378 msgstr ""
379
380 #. -------------------------------------
381 #. type: Plain text
382 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
383 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
384 msgid ""
385 "The target then performs its workload, which includes system calls that will "
386 "be controlled by the seccomp filter. Whenever one of these system calls "
387 "causes the filter to return the B<SECCOMP_RET_USER_NOTIF> action value, the "
388 "kernel does I<not> (yet) execute the system call; instead, execution of the "
389 "target is temporarily blocked inside the kernel (in a sleep state that is "
390 "interruptible by signals) and a notification event is generated on the "
391 "listening file descriptor."
392 msgstr ""
393
394 #. type: IP
395 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
396 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
397 #, no-wrap
398 msgid "(5)"
399 msgstr ""
400
401 #
402 #
403 #
404 #. FIXME
405 #. Christian Brauner:
406 #. Do we support O_NONBLOCK with SECCOMP_IOCTL_NOTIF_RECV and if
407 #. not should we?
408 #. Michael Kerrisk:
409 #. A quick test suggests that O_NONBLOCK has no effect on the blocking
410 #. behavior of SECCOMP_IOCTL_NOTIF_RECV.
411 #. type: Plain text
412 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
413 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
414 msgid ""
415 "The supervisor can now repeatedly monitor the listening file descriptor for "
416 "B<SECCOMP_RET_USER_NOTIF>-triggered events. To do this, the supervisor uses "
417 "the B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) operation to read information "
418 "about a notification event; this operation blocks until an event is "
419 "available. The operation returns a I<seccomp_notif> structure containing "
420 "information about the system call that is being attempted by the target. "
421 "(As described in NOTES, the file descriptor can also be monitored with "
422 "B<select>(2), B<poll>(2), or B<epoll>(7).)"
423 msgstr ""
424
425 #. type: IP
426 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
427 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
428 #, no-wrap
429 msgid "(6)"
430 msgstr ""
431
432 #. type: Plain text
433 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
434 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
435 msgid ""
436 "The I<seccomp_notif> structure returned by the B<SECCOMP_IOCTL_NOTIF_RECV> "
437 "operation includes the same information (a I<seccomp_data> structure) that "
438 "was passed to the seccomp filter. This information allows the supervisor to "
439 "discover the system call number and the arguments for the target's system "
440 "call. In addition, the notification event contains the ID of the thread "
441 "that triggered the notification and a unique cookie value that is used in "
442 "subsequent B<SECCOMP_IOCTL_NOTIF_ID_VALID> and B<SECCOMP_IOCTL_NOTIF_SEND> "
443 "operations."
444 msgstr ""
445
446 #. Tycho Andersen mentioned that there are alternatives to /proc/PID/mem,
447 #. such as ptrace() and /proc/PID/map_files
448 #. -------------------------------------
449 #. type: Plain text
450 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
451 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
452 msgid ""
453 "The information in the notification can be used to discover the values of "
454 "pointer arguments for the target's system call. (This is something that "
455 "can't be done from within a seccomp filter.) One way in which the "
456 "supervisor can do this is to open the corresponding I</proc/>tidI</mem> file "
457 "(see B<proc>(5)) and read bytes from the location that corresponds to one "
458 "of the pointer arguments whose value is supplied in the notification event. "
459 "(The supervisor must be careful to avoid a race condition that can occur "
460 "when doing this; see the description of the B<SECCOMP_IOCTL_NOTIF_ID_VALID> "
461 "B<ioctl>(2) operation below.) In addition, the supervisor can access other "
462 "system information that is visible in user space but which is not accessible "
463 "from a seccomp filter."
464 msgstr ""
465
466 #. type: IP
467 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
468 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
469 #, no-wrap
470 msgid "(7)"
471 msgstr ""
472
473 #. type: Plain text
474 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
475 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
476 msgid ""
477 "Having obtained information as per the previous step, the supervisor may "
478 "then choose to perform an action in response to the target's system call "
479 "(which, as noted above, is not executed when the seccomp filter returns the "
480 "B<SECCOMP_RET_USER_NOTIF> action value)."
481 msgstr ""
482
483 #. -------------------------------------
484 #. type: Plain text
485 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
486 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
487 msgid ""
488 "One example use case here relates to containers. The target may be located "
489 "inside a container where it does not have sufficient capabilities to mount a "
490 "filesystem in the container's mount namespace. However, the supervisor may "
491 "be a more privileged process that does have sufficient capabilities to "
492 "perform the mount operation."
493 msgstr ""
494
495 #. type: IP
496 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
497 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
498 #, no-wrap
499 msgid "(8)"
500 msgstr ""
501
502 #. type: Plain text
503 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
504 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
505 msgid ""
506 "The supervisor then sends a response to the notification. The information "
507 "in this response is used by the kernel to construct a return value for the "
508 "target's system call and provide a value that will be assigned to the "
509 "I<errno> variable of the target."
510 msgstr ""
511
512 #. -------------------------------------
513 #. type: Plain text
514 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
515 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
516 msgid ""
517 "The response is sent using the B<SECCOMP_IOCTL_NOTIF_SEND> B<ioctl>(2) "
518 "operation, which is used to transmit a I<seccomp_notif_resp> structure to "
519 "the kernel. This structure includes a cookie value that the supervisor "
520 "obtained in the I<seccomp_notif> structure returned by the "
521 "B<SECCOMP_IOCTL_NOTIF_RECV> operation. This cookie value allows the kernel "
522 "to associate the response with the target. This structure must include the "
523 "cookie value that the supervisor obtained in the I<seccomp_notif> structure "
524 "returned by the B<SECCOMP_IOCTL_NOTIF_RECV> operation; the cookie allows the "
525 "kernel to associate the response with the target."
526 msgstr ""
527
528 #. type: IP
529 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
530 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
531 #, no-wrap
532 msgid "(9)"
533 msgstr ""
534
535 #. -------------------------------------
536 #. type: Plain text
537 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
538 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
539 msgid ""
540 "Once the notification has been sent, the system call in the target thread "
541 "unblocks, returning the information that was provided by the supervisor in "
542 "the notification response."
543 msgstr ""
544
545 #. type: Plain text
546 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
547 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
548 msgid ""
549 "As a variation on the last two steps, the supervisor can send a response "
550 "that tells the kernel that it should execute the target thread's system "
551 "call; see the discussion of B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>, below."
552 msgstr ""
553
554 #. type: SH
555 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
556 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
557 #, no-wrap
558 msgid "IOCTL OPERATIONS"
559 msgstr ""
560
561 #. type: Plain text
562 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
563 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
564 msgid ""
565 "The following B<ioctl>(2) operations are supported by the seccomp user-"
566 "space notification file descriptor. For each of these operations, the first "
567 "(file descriptor) argument of B<ioctl>(2) is the listening file descriptor "
568 "returned by a call to B<seccomp>(2) with the "
569 "B<SECCOMP_FILTER_FLAG_NEW_LISTENER> flag."
570 msgstr ""
571
572 #. type: SS
573 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
574 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
575 #, no-wrap
576 msgid "SECCOMP_IOCTL_NOTIF_RECV"
577 msgstr ""
578
579 #. type: Plain text
580 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
581 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
582 msgid ""
583 "The B<SECCOMP_IOCTL_NOTIF_RECV> operation (available since Linux 5.0) is "
584 "used to obtain a user-space notification event. If no such event is "
585 "currently pending, the operation blocks until an event occurs. The third "
586 "B<ioctl>(2) argument is a pointer to a structure of the following form "
587 "which contains information about the event. This structure must be zeroed "
588 "out before the call."
589 msgstr ""
590
591 #. type: Plain text
592 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
593 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
594 #, no-wrap
595 msgid ""
596 "struct seccomp_notif {\n"
597 " __u64 id; /* Cookie */\n"
598 " __u32 pid; /* TID of target thread */\n"
599 " __u32 flags; /* Currently unused (0) */\n"
600 " struct seccomp_data data; /* See seccomp(2) */\n"
601 "};\n"
602 msgstr ""
603
604 #. type: Plain text
605 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
606 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
607 msgid "The fields in this structure are as follows:"
608 msgstr ""
609
610 #. type: TP
611 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
612 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
613 #, no-wrap
614 msgid "I<id>"
615 msgstr ""
616
617 #. type: Plain text
618 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
619 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
620 msgid ""
621 "This is a cookie for the notification. Each such cookie is guaranteed to be "
622 "unique for the corresponding seccomp filter."
623 msgstr ""
624
625 #. type: Plain text
626 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
627 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
628 msgid ""
629 "The cookie can be used with the B<SECCOMP_IOCTL_NOTIF_ID_VALID> B<ioctl>(2) "
630 "operation described below."
631 msgstr ""
632
633 #. type: Plain text
634 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
635 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
636 msgid ""
637 "When returning a notification response to the kernel, the supervisor must "
638 "include the cookie value in the I<seccomp_notif_resp> structure that is "
639 "specified as the argument of the B<SECCOMP_IOCTL_NOTIF_SEND> operation."
640 msgstr ""
641
642 #. type: TP
643 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
644 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
645 #, no-wrap
646 msgid "I<pid>"
647 msgstr ""
648
649 #. type: Plain text
650 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
651 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
652 msgid ""
653 "This is the thread ID of the target thread that triggered the notification "
654 "event."
655 msgstr ""
656
657 #. type: TP
658 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
659 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
660 #, no-wrap
661 msgid "I<flags>"
662 msgstr ""
663
664 #. type: Plain text
665 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
666 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
667 msgid ""
668 "This is a bit mask of flags providing further information on the event. In "
669 "the current implementation, this field is always zero."
670 msgstr ""
671
672 #. type: TP
673 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
674 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
675 #, no-wrap
676 msgid "I<data>"
677 msgstr ""
678
679 #. type: Plain text
680 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
681 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
682 msgid ""
683 "This is a I<seccomp_data> structure containing information about the system "
684 "call that triggered the notification. This is the same structure that is "
685 "passed to the seccomp filter. See B<seccomp>(2) for details of this "
686 "structure."
687 msgstr ""
688
689 #. type: Plain text
690 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
691 #: opensuse-leap-16-1 opensuse-tumbleweed
692 msgid ""
693 "On success, this operation returns 0; on failure, -1 is returned, and "
694 "I<errno> is set to indicate the error. This operation can fail with the "
695 "following errors:"
696 msgstr ""
697
698 #. type: TP
699 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
700 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
701 #, no-wrap
702 msgid "B<EINVAL> (since Linux 5.5)"
703 msgstr ""
704
705 #. commit 2882d53c9c6f3b8311d225062522f03772cf0179
706 #. type: Plain text
707 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
708 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
709 msgid ""
710 "The I<seccomp_notif> structure that was passed to the call contained nonzero "
711 "fields."
712 msgstr ""
713
714 #. type: TP
715 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
716 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
717 #, no-wrap
718 msgid "B<ENOENT>"
719 msgstr ""
720
721 #
722 #
723 #
724 #
725 #
726 #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
727 #. FIXME
728 #. From my experiments,
729 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
730 #. the target thread terminates, then the ioctl() simply
731 #. blocks (rather than returning an error to indicate that the
732 #. target no longer exists).
733 #. I found that surprising, and it required some contortions in
734 #. the example program. It was not possible to code my SIGCHLD
735 #. handler (which reaps the zombie when the worker/target
736 #. terminates) to simply set a flag checked in the main
737 #. handleNotifications() loop, since this created an
738 #. unavoidable race where the child might terminate just after
739 #. I had checked the flag, but before I blocked (forever!) in the
740 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
741 #. the signal handler to simply call _exit(2) in order to
742 #. terminate the parent process (the supervisor).
743 #. Is this expected behavior? It seems to me rather
744 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
745 #. if the target has terminated.
746 #. Jann posted a patch to rectify this, but there was no response
747 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
748 #. this issue. (I've tried building with the patch, but encountered
749 #. an issue with the target process entering D state after a signal.)
750 #. For now, this behavior is documented in BUGS.
751 #. Kees Cook commented: Let's change [this] ASAP!
752 #. type: Plain text
753 #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
754 #. FIXME
755 #. From my experiments,
756 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
757 #. the target thread terminates, then the ioctl() simply
758 #. blocks (rather than returning an error to indicate that the
759 #. target no longer exists).
760 #. I found that surprising, and it required some contortions in
761 #. the example program. It was not possible to code my SIGCHLD
762 #. handler (which reaps the zombie when the worker/target
763 #. terminates) to simply set a flag checked in the main
764 #. handleNotifications() loop, since this created an
765 #. unavoidable race where the child might terminate just after
766 #. I had checked the flag, but before I blocked (forever!) in the
767 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
768 #. the signal handler to simply call _exit(2) in order to
769 #. terminate the parent process (the supervisor).
770 #. Is this expected behavior? It seems to me rather
771 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
772 #. if the target has terminated.
773 #. Jann posted a patch to rectify this, but there was no response
774 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
775 #. this issue. (I've tried building with the patch, but encountered
776 #. an issue with the target process entering D state after a signal.)
777 #. For now, this behavior is documented in BUGS.
778 #. Kees Cook commented: Let's change [this] ASAP!
779 #. type: Plain text
780 #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
781 #. FIXME
782 #. From my experiments,
783 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
784 #. the target thread terminates, then the ioctl() simply
785 #. blocks (rather than returning an error to indicate that the
786 #. target no longer exists).
787 #. I found that surprising, and it required some contortions in
788 #. the example program. It was not possible to code my SIGCHLD
789 #. handler (which reaps the zombie when the worker/target
790 #. terminates) to simply set a flag checked in the main
791 #. handleNotifications() loop, since this created an
792 #. unavoidable race where the child might terminate just after
793 #. I had checked the flag, but before I blocked (forever!) in the
794 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
795 #. the signal handler to simply call _exit(2) in order to
796 #. terminate the parent process (the supervisor).
797 #. Is this expected behavior? It seems to me rather
798 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
799 #. if the target has terminated.
800 #. Jann posted a patch to rectify this, but there was no response
801 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
802 #. this issue. (I've tried building with the patch, but encountered
803 #. an issue with the target process entering D state after a signal.)
804 #. For now, this behavior is documented in BUGS.
805 #. Kees Cook commented: Let's change [this] ASAP!
806 #. type: Plain text
807 #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
808 #. FIXME
809 #. From my experiments,
810 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
811 #. the target thread terminates, then the ioctl() simply
812 #. blocks (rather than returning an error to indicate that the
813 #. target no longer exists).
814 #. I found that surprising, and it required some contortions in
815 #. the example program. It was not possible to code my SIGCHLD
816 #. handler (which reaps the zombie when the worker/target
817 #. terminates) to simply set a flag checked in the main
818 #. handleNotifications() loop, since this created an
819 #. unavoidable race where the child might terminate just after
820 #. I had checked the flag, but before I blocked (forever!) in the
821 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
822 #. the signal handler to simply call _exit(2) in order to
823 #. terminate the parent process (the supervisor).
824 #. Is this expected behavior? It seems to me rather
825 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
826 #. if the target has terminated.
827 #. Jann posted a patch to rectify this, but there was no response
828 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
829 #. this issue. (I've tried building with the patch, but encountered
830 #. an issue with the target process entering D state after a signal.)
831 #. For now, this behavior is documented in BUGS.
832 #. Kees Cook commented: Let's change [this] ASAP!
833 #. type: Plain text
834 #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
835 #. FIXME
836 #. From my experiments,
837 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
838 #. the target thread terminates, then the ioctl() simply
839 #. blocks (rather than returning an error to indicate that the
840 #. target no longer exists).
841 #. I found that surprising, and it required some contortions in
842 #. the example program. It was not possible to code my SIGCHLD
843 #. handler (which reaps the zombie when the worker/target
844 #. terminates) to simply set a flag checked in the main
845 #. handleNotifications() loop, since this created an
846 #. unavoidable race where the child might terminate just after
847 #. I had checked the flag, but before I blocked (forever!) in the
848 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
849 #. the signal handler to simply call _exit(2) in order to
850 #. terminate the parent process (the supervisor).
851 #. Is this expected behavior? It seems to me rather
852 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
853 #. if the target has terminated.
854 #. Jann posted a patch to rectify this, but there was no response
855 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
856 #. this issue. (I've tried building with the patch, but encountered
857 #. an issue with the target process entering D state after a signal.)
858 #. For now, this behavior is documented in BUGS.
859 #. Kees Cook commented: Let's change [this] ASAP!
860 #. type: Plain text
861 #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
862 #. FIXME
863 #. From my experiments,
864 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
865 #. the target thread terminates, then the ioctl() simply
866 #. blocks (rather than returning an error to indicate that the
867 #. target no longer exists).
868 #. I found that surprising, and it required some contortions in
869 #. the example program. It was not possible to code my SIGCHLD
870 #. handler (which reaps the zombie when the worker/target
871 #. terminates) to simply set a flag checked in the main
872 #. handleNotifications() loop, since this created an
873 #. unavoidable race where the child might terminate just after
874 #. I had checked the flag, but before I blocked (forever!) in the
875 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
876 #. the signal handler to simply call _exit(2) in order to
877 #. terminate the parent process (the supervisor).
878 #. Is this expected behavior? It seems to me rather
879 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
880 #. if the target has terminated.
881 #. Jann posted a patch to rectify this, but there was no response
882 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
883 #. this issue. (I've tried building with the patch, but encountered
884 #. an issue with the target process entering D state after a signal.)
885 #. For now, this behavior is documented in BUGS.
886 #. Kees Cook commented: Let's change [this] ASAP!
887 #. type: Plain text
888 #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
889 #. FIXME
890 #. From my experiments,
891 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
892 #. the target thread terminates, then the ioctl() simply
893 #. blocks (rather than returning an error to indicate that the
894 #. target no longer exists).
895 #. I found that surprising, and it required some contortions in
896 #. the example program. It was not possible to code my SIGCHLD
897 #. handler (which reaps the zombie when the worker/target
898 #. terminates) to simply set a flag checked in the main
899 #. handleNotifications() loop, since this created an
900 #. unavoidable race where the child might terminate just after
901 #. I had checked the flag, but before I blocked (forever!) in the
902 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
903 #. the signal handler to simply call _exit(2) in order to
904 #. terminate the parent process (the supervisor).
905 #. Is this expected behavior? It seems to me rather
906 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
907 #. if the target has terminated.
908 #. Jann posted a patch to rectify this, but there was no response
909 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
910 #. this issue. (I've tried building with the patch, but encountered
911 #. an issue with the target process entering D state after a signal.)
912 #. For now, this behavior is documented in BUGS.
913 #. Kees Cook commented: Let's change [this] ASAP!
914 #. type: Plain text
915 #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
916 #. FIXME
917 #. From my experiments,
918 #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after
919 #. the target thread terminates, then the ioctl() simply
920 #. blocks (rather than returning an error to indicate that the
921 #. target no longer exists).
922 #. I found that surprising, and it required some contortions in
923 #. the example program. It was not possible to code my SIGCHLD
924 #. handler (which reaps the zombie when the worker/target
925 #. terminates) to simply set a flag checked in the main
926 #. handleNotifications() loop, since this created an
927 #. unavoidable race where the child might terminate just after
928 #. I had checked the flag, but before I blocked (forever!) in the
929 #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code
930 #. the signal handler to simply call _exit(2) in order to
931 #. terminate the parent process (the supervisor).
932 #. Is this expected behavior? It seems to me rather
933 #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error
934 #. if the target has terminated.
935 #. Jann posted a patch to rectify this, but there was no response
936 #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing
937 #. this issue. (I've tried building with the patch, but encountered
938 #. an issue with the target process entering D state after a signal.)
939 #. For now, this behavior is documented in BUGS.
940 #. Kees Cook commented: Let's change [this] ASAP!
941 #. type: Plain text
942 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
943 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
944 msgid ""
945 "The target thread was killed by a signal as the notification information was "
946 "being generated, or the target's (blocked) system call was interrupted by a "
947 "signal handler."
948 msgstr ""
949
950 #. type: SS
951 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
952 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
953 #, no-wrap
954 msgid "SECCOMP_IOCTL_NOTIF_ID_VALID"
955 msgstr ""
956
957 #. type: Plain text
958 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
959 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
960 msgid ""
961 "The B<SECCOMP_IOCTL_NOTIF_ID_VALID> operation (available since Linux 5.0) is "
962 "used to check that a notification ID returned by an earlier "
963 "B<SECCOMP_IOCTL_NOTIF_RECV> operation is still valid (i.e., that the target "
964 "still exists and its system call is still blocked waiting for a response)."
965 msgstr ""
966
967 #. type: Plain text
968 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
969 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
970 msgid ""
971 "The third B<ioctl>(2) argument is a pointer to the cookie (I<id>) returned "
972 "by the B<SECCOMP_IOCTL_NOTIF_RECV> operation."
973 msgstr ""
974
975 #. type: Plain text
976 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
977 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
978 msgid ""
979 "This operation is necessary to avoid race conditions that can occur when the "
980 "I<pid> returned by the B<SECCOMP_IOCTL_NOTIF_RECV> operation terminates, and "
981 "that process ID is reused by another process. An example of this kind of "
982 "race is the following"
983 msgstr ""
984
985 #. type: Plain text
986 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
987 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
988 msgid ""
989 "A notification is generated on the listening file descriptor. The returned "
990 "I<seccomp_notif> contains the TID of the target thread (in the I<pid> field "
991 "of the structure)."
992 msgstr ""
993
994 #. type: Plain text
995 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
996 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
997 msgid "The target terminates."
998 msgstr ""
999
1000 #. type: Plain text
1001 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1002 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1003 msgid ""
1004 "Another thread or process is created on the system that by chance reuses the "
1005 "TID that was freed when the target terminated."
1006 msgstr ""
1007
1008 #. type: Plain text
1009 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1010 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1011 msgid ""
1012 "The supervisor B<open>(2)s the I</proc/>tidI</mem> file for the TID obtained "
1013 "in step 1, with the intention of (say) inspecting the memory location(s) "
1014 "that containing the argument(s) of the system call that triggered the "
1015 "notification in step 1."
1016 msgstr ""
1017
1018 #. Jann Horn:
1019 #. the PID can be reused, but the /proc/$pid directory is
1020 #. internally not associated with the numeric PID, but,
1021 #. conceptually speaking, with a specific incarnation of the
1022 #. PID, or something like that. (Actually, it is associated
1023 #. with the "struct pid", which is not reused, instead of the
1024 #. numeric PID.
1025 #. type: Plain text
1026 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1027 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1028 msgid ""
1029 "In the above scenario, the risk is that the supervisor may try to access the "
1030 "memory of a process other than the target. This race can be avoided by "
1031 "following the call to B<open>(2) with a B<SECCOMP_IOCTL_NOTIF_ID_VALID> "
1032 "operation to verify that the process that generated the notification is "
1033 "still alive. (Note that if the target terminates after the latter step, a "
1034 "subsequent B<read>(2) from the file descriptor may return 0, indicating end "
1035 "of file.)"
1036 msgstr ""
1037
1038 #. type: Plain text
1039 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1040 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1041 msgid ""
1042 "See NOTES for a discussion of other cases where "
1043 "B<SECCOMP_IOCTL_NOTIF_ID_VALID> checks must be performed."
1044 msgstr ""
1045
1046 #. type: Plain text
1047 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1048 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1049 msgid ""
1050 "On success (i.e., the notification ID is still valid), this operation "
1051 "returns 0. On failure (i.e., the notification ID is no longer valid), -1 is "
1052 "returned, and I<errno> is set to B<ENOENT>."
1053 msgstr ""
1054
1055 #. type: SS
1056 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1057 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1058 #, no-wrap
1059 msgid "SECCOMP_IOCTL_NOTIF_SEND"
1060 msgstr ""
1061
1062 #. type: Plain text
1063 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1064 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1065 msgid ""
1066 "The B<SECCOMP_IOCTL_NOTIF_SEND> operation (available since Linux 5.0) is "
1067 "used to send a notification response back to the kernel. The third "
1068 "B<ioctl>(2) argument of this structure is a pointer to a structure of the "
1069 "following form:"
1070 msgstr ""
1071
1072 #. type: Plain text
1073 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1074 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1075 #, no-wrap
1076 msgid ""
1077 "struct seccomp_notif_resp {\n"
1078 " __u64 id; /* Cookie value */\n"
1079 " __s64 val; /* Success return value */\n"
1080 " __s32 error; /* 0 (success) or negative error number */\n"
1081 " __u32 flags; /* See below */\n"
1082 "};\n"
1083 msgstr ""
1084
1085 #. type: Plain text
1086 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1087 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1088 msgid "The fields of this structure are as follows:"
1089 msgstr ""
1090
1091 #. type: Plain text
1092 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1093 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1094 msgid ""
1095 "This is the cookie value that was obtained using the "
1096 "B<SECCOMP_IOCTL_NOTIF_RECV> operation. This cookie value allows the kernel "
1097 "to correctly associate this response with the system call that triggered the "
1098 "user-space notification."
1099 msgstr ""
1100
1101 #. type: TP
1102 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1103 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1104 #, no-wrap
1105 msgid "I<val>"
1106 msgstr ""
1107
1108 #. type: Plain text
1109 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1110 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1111 msgid ""
1112 "This is the value that will be used for a spoofed success return for the "
1113 "target's system call; see below."
1114 msgstr ""
1115
1116 #. type: TP
1117 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1118 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1119 #, no-wrap
1120 msgid "I<error>"
1121 msgstr ""
1122
1123 #. type: Plain text
1124 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1125 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1126 msgid ""
1127 "This is the value that will be used as the error number (I<errno>) for a "
1128 "spoofed error return for the target's system call; see below."
1129 msgstr ""
1130
1131 #. type: Plain text
1132 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1133 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1134 msgid "This is a bit mask that includes zero or more of the following flags:"
1135 msgstr ""
1136
1137 #. type: TP
1138 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1139 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1140 #, no-wrap
1141 msgid "B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> (since Linux 5.5)"
1142 msgstr ""
1143
1144 #. commit fb3c5386b382d4097476ce9647260fc89b34afdb
1145 #. type: Plain text
1146 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1147 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1148 msgid "Tell the kernel to execute the target's system call."
1149 msgstr ""
1150
1151 #. type: Plain text
1152 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1153 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1154 msgid "Two kinds of response are possible:"
1155 msgstr ""
1156
1157 #. type: Plain text
1158 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1159 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1160 msgid ""
1161 "A response to the kernel telling it to execute the target's system call. In "
1162 "this case, the I<flags> field includes B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> "
1163 "and the I<error> and I<val> fields must be zero."
1164 msgstr ""
1165
1166 #. type: Plain text
1167 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1168 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1169 msgid ""
1170 "This kind of response can be useful in cases where the supervisor needs to "
1171 "do deeper analysis of the target's system call than is possible from a "
1172 "seccomp filter (e.g., examining the values of pointer arguments), and, "
1173 "having decided that the system call does not require emulation by the "
1174 "supervisor, the supervisor wants the system call to be executed normally in "
1175 "the target."
1176 msgstr ""
1177
1178 #. type: Plain text
1179 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1180 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1181 msgid ""
1182 "The B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> flag should be used with caution; "
1183 "see NOTES."
1184 msgstr ""
1185
1186 #. type: Plain text
1187 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1188 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1189 msgid ""
1190 "A spoofed return value for the target's system call. In this case, the "
1191 "kernel does not execute the target's system call, instead causing the system "
1192 "call to return a spoofed value as specified by fields of the "
1193 "I<seccomp_notif_resp> structure. The supervisor should set the fields of "
1194 "this structure as follows:"
1195 msgstr ""
1196
1197 #. type: Plain text
1198 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1199 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1200 msgid "I<flags> does not contain B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>."
1201 msgstr ""
1202
1203 #. type: Plain text
1204 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1205 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1206 msgid ""
1207 "I<error> is set either to 0 for a spoofed \"success\" return or to a "
1208 "negative error number for a spoofed \"failure\" return. In the former case, "
1209 "the kernel causes the target's system call to return the value specified in "
1210 "the I<val> field. In the latter case, the kernel causes the target's system "
1211 "call to return -1, and I<errno> is assigned the negated I<error> value."
1212 msgstr ""
1213
1214 #
1215 #
1216 #
1217 #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1218 #. FIXME
1219 #. Kees Cook suggested:
1220 #. Strictly speaking, this is architecture specific, but
1221 #. all architectures do it this way. Should seccomp enforce
1222 #. val == 0 when err != 0 ?
1223 #. Christian Brauner
1224 #. Feels like it should, at least for the SEND ioctl where we already
1225 #. verify that val and err are both 0 when CONTINUE is specified (as you
1226 #. pointed out correctly above).
1227 #. type: Plain text
1228 #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1229 #. FIXME
1230 #. Kees Cook suggested:
1231 #. Strictly speaking, this is architecture specific, but
1232 #. all architectures do it this way. Should seccomp enforce
1233 #. val == 0 when err != 0 ?
1234 #. Christian Brauner
1235 #. Feels like it should, at least for the SEND ioctl where we already
1236 #. verify that val and err are both 0 when CONTINUE is specified (as you
1237 #. pointed out correctly above).
1238 #. type: Plain text
1239 #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1240 #. FIXME
1241 #. Kees Cook suggested:
1242 #. Strictly speaking, this is architecture specific, but
1243 #. all architectures do it this way. Should seccomp enforce
1244 #. val == 0 when err != 0 ?
1245 #. Christian Brauner
1246 #. Feels like it should, at least for the SEND ioctl where we already
1247 #. verify that val and err are both 0 when CONTINUE is specified (as you
1248 #. pointed out correctly above).
1249 #. type: Plain text
1250 #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1251 #. FIXME
1252 #. Kees Cook suggested:
1253 #. Strictly speaking, this is architecture specific, but
1254 #. all architectures do it this way. Should seccomp enforce
1255 #. val == 0 when err != 0 ?
1256 #. Christian Brauner
1257 #. Feels like it should, at least for the SEND ioctl where we already
1258 #. verify that val and err are both 0 when CONTINUE is specified (as you
1259 #. pointed out correctly above).
1260 #. type: Plain text
1261 #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1262 #. FIXME
1263 #. Kees Cook suggested:
1264 #. Strictly speaking, this is architecture specific, but
1265 #. all architectures do it this way. Should seccomp enforce
1266 #. val == 0 when err != 0 ?
1267 #. Christian Brauner
1268 #. Feels like it should, at least for the SEND ioctl where we already
1269 #. verify that val and err are both 0 when CONTINUE is specified (as you
1270 #. pointed out correctly above).
1271 #. type: Plain text
1272 #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1273 #. FIXME
1274 #. Kees Cook suggested:
1275 #. Strictly speaking, this is architecture specific, but
1276 #. all architectures do it this way. Should seccomp enforce
1277 #. val == 0 when err != 0 ?
1278 #. Christian Brauner
1279 #. Feels like it should, at least for the SEND ioctl where we already
1280 #. verify that val and err are both 0 when CONTINUE is specified (as you
1281 #. pointed out correctly above).
1282 #. type: Plain text
1283 #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1284 #. FIXME
1285 #. Kees Cook suggested:
1286 #. Strictly speaking, this is architecture specific, but
1287 #. all architectures do it this way. Should seccomp enforce
1288 #. val == 0 when err != 0 ?
1289 #. Christian Brauner
1290 #. Feels like it should, at least for the SEND ioctl where we already
1291 #. verify that val and err are both 0 when CONTINUE is specified (as you
1292 #. pointed out correctly above).
1293 #. type: Plain text
1294 #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
1295 #. FIXME
1296 #. Kees Cook suggested:
1297 #. Strictly speaking, this is architecture specific, but
1298 #. all architectures do it this way. Should seccomp enforce
1299 #. val == 0 when err != 0 ?
1300 #. Christian Brauner
1301 #. Feels like it should, at least for the SEND ioctl where we already
1302 #. verify that val and err are both 0 when CONTINUE is specified (as you
1303 #. pointed out correctly above).
1304 #. type: Plain text
1305 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1306 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1307 msgid ""
1308 "I<val> is set to a value that will be used as the return value for a spoofed "
1309 "\"success\" return for the target's system call. The value in this field is "
1310 "ignored if the I<error> field contains a nonzero value."
1311 msgstr ""
1312
1313 #. type: TP
1314 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1315 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1316 #, no-wrap
1317 msgid "B<EINPROGRESS>"
1318 msgstr ""
1319
1320 #. type: Plain text
1321 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1322 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1323 msgid "A response to this notification has already been sent."
1324 msgstr ""
1325
1326 #. type: TP
1327 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1328 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1329 #, no-wrap
1330 msgid "B<EINVAL>"
1331 msgstr ""
1332
1333 #. type: Plain text
1334 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1335 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1336 msgid "An invalid value was specified in the I<flags field.>"
1337 msgstr ""
1338
1339 #. type: Plain text
1340 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1341 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1342 msgid ""
1343 "The I<flags> field contained B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>, and the "
1344 "I<error> or I<val> field was not zero."
1345 msgstr ""
1346
1347 #. type: Plain text
1348 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1349 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1350 msgid ""
1351 "The blocked system call in the target has been interrupted by a signal "
1352 "handler or the target has terminated."
1353 msgstr ""
1354
1355 #. type: SS
1356 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1357 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1358 #, no-wrap
1359 msgid "SECCOMP_IOCTL_NOTIF_ADDFD"
1360 msgstr ""
1361
1362 #. type: Plain text
1363 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1364 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1365 msgid ""
1366 "The B<SECCOMP_IOCTL_NOTIF_ADDFD> operation (available since Linux 5.9) "
1367 "allows the supervisor to install a file descriptor into the target's file "
1368 "descriptor table. Much like the use of B<SCM_RIGHTS> messages described in "
1369 "B<unix>(7), this operation is semantically equivalent to duplicating a file "
1370 "descriptor from the supervisor's file descriptor table into the target's "
1371 "file descriptor table."
1372 msgstr ""
1373
1374 #. type: Plain text
1375 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1376 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1377 msgid ""
1378 "The B<SECCOMP_IOCTL_NOTIF_ADDFD> operation permits the supervisor to emulate "
1379 "a target system call (such as B<socket>(2) or B<openat>(2)) that generates "
1380 "a file descriptor. The supervisor can perform the system call that "
1381 "generates the file descriptor (and associated open file description) and "
1382 "then use this operation to allocate a file descriptor that refers to the "
1383 "same open file description in the target. (For an explanation of open file "
1384 "descriptions, see B<open>(2).)"
1385 msgstr ""
1386
1387 #. type: Plain text
1388 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1389 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1390 msgid ""
1391 "Once this operation has been performed, the supervisor can close its copy of "
1392 "the file descriptor."
1393 msgstr ""
1394
1395 #. type: Plain text
1396 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1397 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1398 msgid ""
1399 "In the target, the received file descriptor is subject to the same Linux "
1400 "Security Module (LSM) checks as are applied to a file descriptor that is "
1401 "received in an B<SCM_RIGHTS> ancillary message. If the file descriptor "
1402 "refers to a socket, it inherits the cgroup version 1 network controller "
1403 "settings (I<classid> and I<netprioidx>) of the target."
1404 msgstr ""
1405
1406 #. type: Plain text
1407 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1408 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1409 msgid ""
1410 "The third B<ioctl>(2) argument is a pointer to a structure of the following "
1411 "form:"
1412 msgstr ""
1413
1414 #. type: Plain text
1415 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1416 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1417 #, no-wrap
1418 msgid ""
1419 "struct seccomp_notif_addfd {\n"
1420 " __u64 id; /* Cookie value */\n"
1421 " __u32 flags; /* Flags */\n"
1422 " __u32 srcfd; /* Local file descriptor number */\n"
1423 " __u32 newfd; /* 0 or desired file descriptor\n"
1424 " number in target */\n"
1425 " __u32 newfd_flags; /* Flags to set on target file\n"
1426 " descriptor */\n"
1427 "};\n"
1428 msgstr ""
1429
1430 #. type: Plain text
1431 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1432 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1433 msgid ""
1434 "This field should be set to the notification ID (cookie value) that was "
1435 "obtained via B<SECCOMP_IOCTL_NOTIF_RECV>."
1436 msgstr ""
1437
1438 #. type: Plain text
1439 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1440 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1441 msgid ""
1442 "This field is a bit mask of flags that modify the behavior of the "
1443 "operation. Currently, only one flag is supported:"
1444 msgstr ""
1445
1446 #. type: TP
1447 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1448 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1449 #, no-wrap
1450 msgid "B<SECCOMP_ADDFD_FLAG_SETFD>"
1451 msgstr ""
1452
1453 #. type: Plain text
1454 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1455 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1456 msgid ""
1457 "When allocating the file descriptor in the target, use the file descriptor "
1458 "number specified in the I<newfd> field."
1459 msgstr ""
1460
1461 #. type: TP
1462 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1463 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1464 #, no-wrap
1465 msgid "B<SECCOMP_ADDFD_FLAG_SEND> (since Linux 5.14)"
1466 msgstr ""
1467
1468 #. commit 0ae71c7720e3ae3aabd2e8a072d27f7bd173d25c
1469 #. type: Plain text
1470 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1471 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1472 msgid ""
1473 "Perform the equivalent of B<SECCOMP_IOCTL_NOTIF_ADDFD> plus "
1474 "B<SECCOMP_IOCTL_NOTIF_SEND> as an atomic operation. On successful "
1475 "invocation, the target process's I<errno> will be 0 and the return value "
1476 "will be the file descriptor number that was allocated in the target. If "
1477 "allocating the file descriptor in the target fails, the target's system call "
1478 "continues to be blocked until a successful response is sent."
1479 msgstr ""
1480
1481 #. type: TP
1482 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1483 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1484 #, no-wrap
1485 msgid "I<srcfd>"
1486 msgstr ""
1487
1488 #. type: Plain text
1489 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1490 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1491 msgid ""
1492 "This field should be set to the number of the file descriptor in the "
1493 "supervisor that is to be duplicated."
1494 msgstr ""
1495
1496 #. type: TP
1497 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1498 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1499 #, no-wrap
1500 msgid "I<newfd>"
1501 msgstr ""
1502
1503 #. type: Plain text
1504 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1505 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1506 msgid ""
1507 "This field determines which file descriptor number is allocated in the "
1508 "target. If the B<SECCOMP_ADDFD_FLAG_SETFD> flag is set, then this field "
1509 "specifies which file descriptor number should be allocated. If this file "
1510 "descriptor number is already open in the target, it is atomically closed and "
1511 "reused. If the descriptor duplication fails due to an LSM check, or if "
1512 "I<srcfd> is not a valid file descriptor, the file descriptor I<newfd> will "
1513 "not be closed in the target process."
1514 msgstr ""
1515
1516 #. type: Plain text
1517 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1518 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1519 msgid ""
1520 "If the B<SECCOMP_ADDFD_FLAG_SETFD> flag it not set, then this field must be "
1521 "0, and the kernel allocates the lowest unused file descriptor number in the "
1522 "target."
1523 msgstr ""
1524
1525 #. type: TP
1526 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1527 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1528 #, no-wrap
1529 msgid "I<newfd_flags>"
1530 msgstr ""
1531
1532 #. type: Plain text
1533 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1534 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1535 msgid ""
1536 "This field is a bit mask specifying flags that should be set on the file "
1537 "descriptor that is received in the target process. Currently, only the "
1538 "following flag is implemented:"
1539 msgstr ""
1540
1541 #. type: TP
1542 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1543 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1544 #, no-wrap
1545 msgid "B<O_CLOEXEC>"
1546 msgstr ""
1547
1548 #. type: Plain text
1549 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1550 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1551 msgid "Set the close-on-exec flag on the received file descriptor."
1552 msgstr ""
1553
1554 #. type: Plain text
1555 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1556 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1557 msgid ""
1558 "On success, this B<ioctl>(2) call returns the number of the file descriptor "
1559 "that was allocated in the target. Assuming that the emulated system call is "
1560 "one that returns a file descriptor as its function result (e.g., "
1561 "B<socket>(2)), this value can be used as the return value (I<resp.val>) "
1562 "that is supplied in the response that is subsequently sent with the "
1563 "B<SECCOMP_IOCTL_NOTIF_SEND> operation."
1564 msgstr ""
1565
1566 #. type: Plain text
1567 #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron
1568 #: opensuse-leap-16-1 opensuse-tumbleweed
1569 msgid "On error, -1 is returned and I<errno> is set to indicate the error."
1570 msgstr ""
1571
1572 #. type: Plain text
1573 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1574 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1575 msgid "This operation can fail with the following errors:"
1576 msgstr ""
1577
1578 #. type: TP
1579 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1580 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1581 #, no-wrap
1582 msgid "B<EBADF>"
1583 msgstr ""
1584
1585 #. type: Plain text
1586 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1587 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1588 msgid ""
1589 "Allocating the file descriptor in the target would cause the target's "
1590 "B<RLIMIT_NOFILE> limit to be exceeded (see B<getrlimit>(2))."
1591 msgstr ""
1592
1593 #. type: TP
1594 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1595 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1596 #, no-wrap
1597 msgid "B<EBUSY>"
1598 msgstr ""
1599
1600 #. type: Plain text
1601 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1602 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1603 msgid ""
1604 "If the flag B<SECCOMP_IOCTL_NOTIF_SEND> is used, this means the operation "
1605 "can't proceed until other B<SECCOMP_IOCTL_NOTIF_ADDFD> requests are "
1606 "processed."
1607 msgstr ""
1608
1609 #. type: Plain text
1610 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1611 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1612 msgid ""
1613 "The user-space notification specified in the I<id> field exists but has not "
1614 "yet been fetched (by a B<SECCOMP_IOCTL_NOTIF_RECV>) or has already been "
1615 "responded to (by a B<SECCOMP_IOCTL_NOTIF_SEND>)."
1616 msgstr ""
1617
1618 #. type: Plain text
1619 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1620 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1621 msgid ""
1622 "An invalid flag was specified in the I<flags> or I<newfd_flags> field, or "
1623 "the I<newfd> field is nonzero and the B<SECCOMP_ADDFD_FLAG_SETFD> flag was "
1624 "not specified in the I<flags> field."
1625 msgstr ""
1626
1627 #. type: TP
1628 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1629 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1630 #, no-wrap
1631 msgid "B<EMFILE>"
1632 msgstr ""
1633
1634 #. type: Plain text
1635 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1636 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1637 msgid ""
1638 "The file descriptor number specified in I<newfd> exceeds the limit specified "
1639 "in I</proc/sys/fs/nr_open>."
1640 msgstr ""
1641
1642 #. type: Plain text
1643 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1644 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1645 msgid ""
1646 "Here is some sample code (with error handling omitted) that uses the "
1647 "B<SECCOMP_ADDFD_FLAG_SETFD> operation (here, to emulate a call to "
1648 "B<openat>(2)):"
1649 msgstr ""
1650
1651 #. type: Plain text
1652 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1653 #: opensuse-tumbleweed
1654 #, no-wrap
1655 msgid ""
1656 "int fd, removeFd;\n"
1657 "\\&\n"
1658 "fd = openat(req-E<gt>data.args[0], path, req-E<gt>data.args[2],\n"
1659 " req-E<gt>data.args[3]);\n"
1660 "\\&\n"
1661 "struct seccomp_notif_addfd addfd;\n"
1662 "addfd.id = req-E<gt>id; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n"
1663 "addfd.srcfd = fd;\n"
1664 "addfd.newfd = 0;\n"
1665 "addfd.flags = 0;\n"
1666 "addfd.newfd_flags = O_CLOEXEC;\n"
1667 "\\&\n"
1668 "targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n"
1669 "\\&\n"
1670 "close(fd); /* No longer needed in supervisor */\n"
1671 "\\&\n"
1672 "struct seccomp_notif_resp *resp;\n"
1673 " /* Code to allocate 'resp' omitted */\n"
1674 "resp-E<gt>id = req-E<gt>id;\n"
1675 "resp-E<gt>error = 0; /* \"Success\" */\n"
1676 "resp-E<gt>val = targetFd;\n"
1677 "resp-E<gt>flags = 0;\n"
1678 "ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n"
1679 msgstr ""
1680
1681 #. type: SH
1682 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1683 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1684 #, no-wrap
1685 msgid "NOTES"
1686 msgstr ""
1687
1688 #. type: Plain text
1689 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1690 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1691 msgid ""
1692 "One example use case for the user-space notification mechanism is to allow a "
1693 "container manager (a process which is typically running with more privilege "
1694 "than the processes inside the container) to mount block devices or create "
1695 "device nodes for the container. The mount use case provides an example of "
1696 "where the B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> B<ioctl>(2) operation is "
1697 "useful. Upon receiving a notification for the B<mount>(2) system call, the "
1698 "container manager (the \"supervisor\") can distinguish a request to mount a "
1699 "block filesystem (which would not be possible for a \"target\" process "
1700 "inside the container) and mount that file system. If, on the other hand, "
1701 "the container manager detects that the operation could be performed by the "
1702 "process inside the container (e.g., a mount of a B<tmpfs>(5) filesystem), "
1703 "it can notify the kernel that the target process's B<mount>(2) system call "
1704 "can continue."
1705 msgstr ""
1706
1707 #. type: SS
1708 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1709 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1710 #, no-wrap
1711 msgid "select()/poll()/epoll semantics"
1712 msgstr ""
1713
1714 #. type: Plain text
1715 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1716 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1717 msgid ""
1718 "The file descriptor returned when B<seccomp>(2) is employed with the "
1719 "B<SECCOMP_FILTER_FLAG_NEW_LISTENER> flag can be monitored using B<poll>(2), "
1720 "B<epoll>(7), and B<select>(2). These interfaces indicate that the file "
1721 "descriptor is ready as follows:"
1722 msgstr ""
1723
1724 #. type: Plain text
1725 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1726 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1727 msgid ""
1728 "When a notification is pending, these interfaces indicate that the file "
1729 "descriptor is readable. Following such an indication, a subsequent "
1730 "B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) will not block, returning either "
1731 "information about a notification or else failing with the error B<EINTR> if "
1732 "the target has been killed by a signal or its system call has been "
1733 "interrupted by a signal handler."
1734 msgstr ""
1735
1736 #. type: Plain text
1737 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1738 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1739 msgid ""
1740 "After the notification has been received (i.e., by the "
1741 "B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) operation), these interfaces "
1742 "indicate that the file descriptor is writable, meaning that a notification "
1743 "response can be sent using the B<SECCOMP_IOCTL_NOTIF_SEND> B<ioctl>(2) "
1744 "operation."
1745 msgstr ""
1746
1747 #. type: Plain text
1748 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1749 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1750 msgid ""
1751 "After the last thread using the filter has terminated and been reaped using "
1752 "B<waitpid>(2) (or similar), the file descriptor indicates an end-of-file "
1753 "condition (readable in B<select>(2); B<POLLHUP>/B<EPOLLHUP> in B<poll>(2)/ "
1754 "B<epoll_wait>(2))."
1755 msgstr ""
1756
1757 #. type: SS
1758 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1759 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1760 #, no-wrap
1761 msgid "Design goals; use of SECCOMP_USER_NOTIF_FLAG_CONTINUE"
1762 msgstr ""
1763
1764 #. type: Plain text
1765 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1766 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1767 msgid ""
1768 "The intent of the user-space notification feature is to allow system calls "
1769 "to be performed on behalf of the target. The target's system call should "
1770 "either be handled by the supervisor or allowed to continue normally in the "
1771 "kernel (where standard security policies will be applied)."
1772 msgstr ""
1773
1774 #. type: Plain text
1775 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1776 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1777 msgid ""
1778 "B<Note well>: this mechanism must not be used to make security policy "
1779 "decisions about the system call, which would be inherently race-prone for "
1780 "reasons described next."
1781 msgstr ""
1782
1783 #. type: Plain text
1784 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1785 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1786 msgid ""
1787 "The B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> flag must be used with caution. If "
1788 "set by the supervisor, the target's system call will continue. However, "
1789 "there is a time-of-check, time-of-use race here, since an attacker could "
1790 "exploit the interval of time where the target is blocked waiting on the "
1791 "\"continue\" response to do things such as rewriting the system call "
1792 "arguments."
1793 msgstr ""
1794
1795 #. type: Plain text
1796 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1797 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1798 msgid ""
1799 "Note furthermore that a user-space notifier can be bypassed if the existing "
1800 "filters allow the use of B<seccomp>(2) or B<prctl>(2) to install a filter "
1801 "that returns an action value with a higher precedence than "
1802 "B<SECCOMP_RET_USER_NOTIF> (see B<seccomp>(2))."
1803 msgstr ""
1804
1805 #. type: Plain text
1806 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1807 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1808 msgid ""
1809 "It should thus be absolutely clear that the seccomp user-space notification "
1810 "mechanism B<can not> be used to implement a security policy! It should only "
1811 "ever be used in scenarios where a more privileged process supervises the "
1812 "system calls of a lesser privileged target to get around kernel-enforced "
1813 "security restrictions when the supervisor deems this safe. In other words, "
1814 "in order to continue a system call, the supervisor should be sure that "
1815 "another security mechanism or the kernel itself will sufficiently block the "
1816 "system call if its arguments are rewritten to something unsafe."
1817 msgstr ""
1818
1819 #. type: SS
1820 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1821 #: opensuse-tumbleweed
1822 #, no-wrap
1823 msgid "Caveats regarding the use of"
1824 msgstr ""
1825
1826 #. type: Plain text
1827 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1828 #: opensuse-tumbleweed
1829 msgid ""
1830 "I</proc/>tidI</mem> The discussion above noted the need to use the "
1831 "B<SECCOMP_IOCTL_NOTIF_ID_VALID> B<ioctl>(2) when opening the I</proc/>tidI</"
1832 "mem> file of the target to avoid the possibility of accessing the memory of "
1833 "the wrong process in the event that the target terminates and its ID is "
1834 "recycled by another (unrelated) thread. However, the use of this "
1835 "B<ioctl>(2) operation is also necessary in other situations, as explained "
1836 "in the following paragraphs."
1837 msgstr ""
1838
1839 #. type: Plain text
1840 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1841 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1842 msgid ""
1843 "Consider the following scenario, where the supervisor tries to read the "
1844 "pathname argument of a target's blocked B<mount>(2) system call:"
1845 msgstr ""
1846
1847 #. type: Plain text
1848 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1849 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1850 msgid ""
1851 "From one of its functions (I<func()>), the target calls B<mount>(2), which "
1852 "triggers a user-space notification and causes the target to block."
1853 msgstr ""
1854
1855 #. type: Plain text
1856 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1857 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1858 msgid ""
1859 "The supervisor receives the notification, opens I</proc/>tidI</mem>, and "
1860 "(successfully) performs the B<SECCOMP_IOCTL_NOTIF_ID_VALID> check."
1861 msgstr ""
1862
1863 #. type: Plain text
1864 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1865 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1866 msgid "The target receives a signal, which causes the B<mount>(2) to abort."
1867 msgstr ""
1868
1869 #. type: Plain text
1870 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1871 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1872 msgid "The signal handler executes in the target, and returns."
1873 msgstr ""
1874
1875 #. type: Plain text
1876 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1877 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1878 msgid ""
1879 "Upon return from the handler, the execution of I<func()> resumes, and it "
1880 "returns (and perhaps other functions are called, overwriting the memory that "
1881 "had been used for the stack frame of I<func()>)."
1882 msgstr ""
1883
1884 #. type: Plain text
1885 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1886 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1887 msgid ""
1888 "Using the address provided in the notification information, the supervisor "
1889 "reads from the target's memory location that used to contain the pathname."
1890 msgstr ""
1891
1892 #. type: Plain text
1893 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1894 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1895 msgid ""
1896 "The supervisor now calls B<mount>(2) with some arbitrary bytes obtained in "
1897 "the previous step."
1898 msgstr ""
1899
1900 #. type: Plain text
1901 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1902 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1903 msgid ""
1904 "The conclusion from the above scenario is this: since the target's blocked "
1905 "system call may be interrupted by a signal handler, the supervisor must be "
1906 "written to expect that the target may abandon its system call at B<any> "
1907 "time; in such an event, any information that the supervisor obtained from "
1908 "the target's memory must be considered invalid."
1909 msgstr ""
1910
1911 #. type: Plain text
1912 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1913 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1914 msgid ""
1915 "To prevent such scenarios, every read from the target's memory must be "
1916 "separated from use of the bytes so obtained by a "
1917 "B<SECCOMP_IOCTL_NOTIF_ID_VALID> check. In the above example, the check "
1918 "would be placed between the two final steps. An example of such a check is "
1919 "shown in EXAMPLES."
1920 msgstr ""
1921
1922 #. type: Plain text
1923 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1924 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1925 msgid ""
1926 "Following on from the above, it should be clear that a write by the "
1927 "supervisor into the target's memory can B<never> be considered safe."
1928 msgstr ""
1929
1930 #. type: SS
1931 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1932 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1933 #, no-wrap
1934 msgid "Caveats regarding blocking system calls"
1935 msgstr ""
1936
1937 #. type: Plain text
1938 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1939 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1940 msgid ""
1941 "Suppose that the target performs a blocking system call (e.g., "
1942 "B<accept>(2)) that the supervisor should handle. The supervisor might then "
1943 "in turn execute the same blocking system call."
1944 msgstr ""
1945
1946 #. type: Plain text
1947 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
1948 #: opensuse-tumbleweed
1949 msgid ""
1950 "In this scenario, it is important to note that if the target's system call "
1951 "is now interrupted by a signal, the supervisor is I<not> informed of this. "
1952 "If the supervisor does not take suitable steps to actively discover that the "
1953 "target's system call has been canceled, various difficulties can occur. "
1954 "Taking the example of B<accept>(2), the supervisor might remain blocked in "
1955 "its B<accept>(2) holding a port number that the target (which, after the "
1956 "interruption by the signal handler, perhaps closed its listening socket) "
1957 "might expect to be able to reuse in a B<bind>(2) call."
1958 msgstr ""
1959
1960 #. type: Plain text
1961 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1962 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1963 msgid ""
1964 "Therefore, when the supervisor wishes to emulate a blocking system call, it "
1965 "must do so in such a way that it gets informed if the target's system call "
1966 "is interrupted by a signal handler. For example, if the supervisor itself "
1967 "executes the same blocking system call, then it could employ a separate "
1968 "thread that uses the B<SECCOMP_IOCTL_NOTIF_ID_VALID> operation to check if "
1969 "the target is still blocked in its system call. Alternatively, in the "
1970 "B<accept>(2) example, the supervisor might use B<poll>(2) to monitor both "
1971 "the notification file descriptor (so as to discover when the target's "
1972 "B<accept>(2) call has been interrupted) and the listening file descriptor "
1973 "(so as to know when a connection is available)."
1974 msgstr ""
1975
1976 #. type: Plain text
1977 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1978 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1979 msgid ""
1980 "If the target's system call is interrupted, the supervisor must take care to "
1981 "release resources (e.g., file descriptors) that it acquired on behalf of "
1982 "the target."
1983 msgstr ""
1984
1985 #. type: SS
1986 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1987 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1988 #, no-wrap
1989 msgid "Interaction with SA_RESTART signal handlers"
1990 msgstr ""
1991
1992 #. type: Plain text
1993 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
1994 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
1995 msgid "Consider the following scenario:"
1996 msgstr ""
1997
1998 #. type: Plain text
1999 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2000 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2001 msgid ""
2002 "The target process has used B<sigaction>(2) to install a signal handler "
2003 "with the B<SA_RESTART> flag."
2004 msgstr ""
2005
2006 #. type: Plain text
2007 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2008 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2009 msgid ""
2010 "The target has made a system call that triggered a seccomp user-space "
2011 "notification and the target is currently blocked until the supervisor sends "
2012 "a notification response."
2013 msgstr ""
2014
2015 #. type: Plain text
2016 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2017 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2018 msgid "A signal is delivered to the target and the signal handler is executed."
2019 msgstr ""
2020
2021 #. type: Plain text
2022 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2023 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2024 msgid ""
2025 "When (if) the supervisor attempts to send a notification response, the "
2026 "B<SECCOMP_IOCTL_NOTIF_SEND> B<ioctl>(2)) operation will fail with the "
2027 "B<ENOENT> error."
2028 msgstr ""
2029
2030 #. type: Plain text
2031 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2032 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2033 msgid ""
2034 "In this scenario, the kernel will restart the target's system call. "
2035 "Consequently, the supervisor will receive another user-space notification. "
2036 "Thus, depending on how many times the blocked system call is interrupted by "
2037 "a signal handler, the supervisor may receive multiple notifications for the "
2038 "same instance of a system call in the target."
2039 msgstr ""
2040
2041 #
2042 #
2043 #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2044 #. FIXME
2045 #. About the above, Kees Cook commented:
2046 #. Does this need fixing? I imagine the correct behavior for this case
2047 #. would be a response to _SEND of EINPROGRESS and the target would see
2048 #. EINTR normally?
2049 #. I mean, it's not like seccomp doesn't already expose weirdness with
2050 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2051 #. regard. :(
2052 #. type: Plain text
2053 #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2054 #. FIXME
2055 #. About the above, Kees Cook commented:
2056 #. Does this need fixing? I imagine the correct behavior for this case
2057 #. would be a response to _SEND of EINPROGRESS and the target would see
2058 #. EINTR normally?
2059 #. I mean, it's not like seccomp doesn't already expose weirdness with
2060 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2061 #. regard. :(
2062 #. type: Plain text
2063 #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2064 #. FIXME
2065 #. About the above, Kees Cook commented:
2066 #. Does this need fixing? I imagine the correct behavior for this case
2067 #. would be a response to _SEND of EINPROGRESS and the target would see
2068 #. EINTR normally?
2069 #. I mean, it's not like seccomp doesn't already expose weirdness with
2070 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2071 #. regard. :(
2072 #. type: Plain text
2073 #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2074 #. FIXME
2075 #. About the above, Kees Cook commented:
2076 #. Does this need fixing? I imagine the correct behavior for this case
2077 #. would be a response to _SEND of EINPROGRESS and the target would see
2078 #. EINTR normally?
2079 #. I mean, it's not like seccomp doesn't already expose weirdness with
2080 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2081 #. regard. :(
2082 #. type: Plain text
2083 #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2084 #. FIXME
2085 #. About the above, Kees Cook commented:
2086 #. Does this need fixing? I imagine the correct behavior for this case
2087 #. would be a response to _SEND of EINPROGRESS and the target would see
2088 #. EINTR normally?
2089 #. I mean, it's not like seccomp doesn't already expose weirdness with
2090 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2091 #. regard. :(
2092 #. type: Plain text
2093 #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2094 #. FIXME
2095 #. About the above, Kees Cook commented:
2096 #. Does this need fixing? I imagine the correct behavior for this case
2097 #. would be a response to _SEND of EINPROGRESS and the target would see
2098 #. EINTR normally?
2099 #. I mean, it's not like seccomp doesn't already expose weirdness with
2100 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2101 #. regard. :(
2102 #. type: Plain text
2103 #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2104 #. FIXME
2105 #. About the above, Kees Cook commented:
2106 #. Does this need fixing? I imagine the correct behavior for this case
2107 #. would be a response to _SEND of EINPROGRESS and the target would see
2108 #. EINTR normally?
2109 #. I mean, it's not like seccomp doesn't already expose weirdness with
2110 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2111 #. regard. :(
2112 #. type: Plain text
2113 #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2114 #. FIXME
2115 #. About the above, Kees Cook commented:
2116 #. Does this need fixing? I imagine the correct behavior for this case
2117 #. would be a response to _SEND of EINPROGRESS and the target would see
2118 #. EINTR normally?
2119 #. I mean, it's not like seccomp doesn't already expose weirdness with
2120 #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this
2121 #. regard. :(
2122 #. type: Plain text
2123 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2124 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2125 msgid ""
2126 "One oddity is that system call restarting as described in this scenario will "
2127 "occur even for the blocking system calls listed in B<signal>(7) that would "
2128 "B<never> normally be restarted by the B<SA_RESTART> flag."
2129 msgstr ""
2130
2131 #. type: Plain text
2132 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2133 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2134 msgid ""
2135 "Furthermore, if the supervisor response is a file descriptor added with "
2136 "B<SECCOMP_IOCTL_NOTIF_ADDFD>, then the flag B<SECCOMP_ADDFD_FLAG_SEND> can "
2137 "be used to atomically add the file descriptor and return that value, making "
2138 "sure no file descriptors are inadvertently leaked into the target."
2139 msgstr ""
2140
2141 #. type: SH
2142 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2143 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2144 #, no-wrap
2145 msgid "BUGS"
2146 msgstr ""
2147
2148 #
2149 #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2150 #. or a poll/epoll/select
2151 #. FIXME
2152 #. Comment from Kees Cook:
2153 #. I want this fixed. It caused me no end of pain when building the
2154 #. selftests, and ended up spawning my implementing a global test timeout
2155 #. in kselftest. :P Before the usage counter refactor, there was no sane
2156 #. way to deal with this, but now I think we're close.
2157 #. type: Plain text
2158 #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2159 #. or a poll/epoll/select
2160 #. FIXME
2161 #. Comment from Kees Cook:
2162 #. I want this fixed. It caused me no end of pain when building the
2163 #. selftests, and ended up spawning my implementing a global test timeout
2164 #. in kselftest. :P Before the usage counter refactor, there was no sane
2165 #. way to deal with this, but now I think we're close.
2166 #. type: Plain text
2167 #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2168 #. or a poll/epoll/select
2169 #. FIXME
2170 #. Comment from Kees Cook:
2171 #. I want this fixed. It caused me no end of pain when building the
2172 #. selftests, and ended up spawning my implementing a global test timeout
2173 #. in kselftest. :P Before the usage counter refactor, there was no sane
2174 #. way to deal with this, but now I think we're close.
2175 #. type: Plain text
2176 #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2177 #. or a poll/epoll/select
2178 #. FIXME
2179 #. Comment from Kees Cook:
2180 #. I want this fixed. It caused me no end of pain when building the
2181 #. selftests, and ended up spawning my implementing a global test timeout
2182 #. in kselftest. :P Before the usage counter refactor, there was no sane
2183 #. way to deal with this, but now I think we're close.
2184 #. type: Plain text
2185 #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2186 #. or a poll/epoll/select
2187 #. FIXME
2188 #. Comment from Kees Cook:
2189 #. I want this fixed. It caused me no end of pain when building the
2190 #. selftests, and ended up spawning my implementing a global test timeout
2191 #. in kselftest. :P Before the usage counter refactor, there was no sane
2192 #. way to deal with this, but now I think we're close.
2193 #. type: Plain text
2194 #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2195 #. or a poll/epoll/select
2196 #. FIXME
2197 #. Comment from Kees Cook:
2198 #. I want this fixed. It caused me no end of pain when building the
2199 #. selftests, and ended up spawning my implementing a global test timeout
2200 #. in kselftest. :P Before the usage counter refactor, there was no sane
2201 #. way to deal with this, but now I think we're close.
2202 #. type: Plain text
2203 #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2204 #. or a poll/epoll/select
2205 #. FIXME
2206 #. Comment from Kees Cook:
2207 #. I want this fixed. It caused me no end of pain when building the
2208 #. selftests, and ended up spawning my implementing a global test timeout
2209 #. in kselftest. :P Before the usage counter refactor, there was no sane
2210 #. way to deal with this, but now I think we're close.
2211 #. type: Plain text
2212 #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-#
2213 #. or a poll/epoll/select
2214 #. FIXME
2215 #. Comment from Kees Cook:
2216 #. I want this fixed. It caused me no end of pain when building the
2217 #. selftests, and ended up spawning my implementing a global test timeout
2218 #. in kselftest. :P Before the usage counter refactor, there was no sane
2219 #. way to deal with this, but now I think we're close.
2220 #. type: Plain text
2221 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2222 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2223 msgid ""
2224 "If a B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) operation is performed after "
2225 "the target terminates, then the B<ioctl>(2) call simply blocks (rather than "
2226 "returning an error to indicate that the target no longer exists)."
2227 msgstr ""
2228
2229 #. type: SH
2230 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2231 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2232 #, no-wrap
2233 msgid "EXAMPLES"
2234 msgstr ""
2235
2236 #. type: Plain text
2237 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2238 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2239 msgid ""
2240 "The (somewhat contrived) program shown below demonstrates the use of the "
2241 "interfaces described in this page. The program creates a child process that "
2242 "serves as the \"target\" process. The child process installs a seccomp "
2243 "filter that returns the B<SECCOMP_RET_USER_NOTIF> action value if a call is "
2244 "made to B<mkdir>(2). The child process then calls B<mkdir>(2) once for "
2245 "each of the supplied command-line arguments, and reports the result returned "
2246 "by the call. After processing all arguments, the child process terminates."
2247 msgstr ""
2248
2249 #. type: Plain text
2250 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2251 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2252 msgid ""
2253 "The parent process acts as the supervisor, listening for the notifications "
2254 "that are generated when the target process calls B<mkdir>(2). When such a "
2255 "notification occurs, the supervisor examines the memory of the target "
2256 "process (using I</proc/>pidI</mem>) to discover the pathname argument that "
2257 "was supplied to the B<mkdir>(2) call, and performs one of the following "
2258 "actions:"
2259 msgstr ""
2260
2261 #. type: Plain text
2262 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2263 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2264 msgid ""
2265 "If the pathname begins with the prefix \"/tmp/\", then the supervisor "
2266 "attempts to create the specified directory, and then spoofs a return for the "
2267 "target process based on the return value of the supervisor's B<mkdir>(2) "
2268 "call. In the event that that call succeeds, the spoofed success return "
2269 "value is the length of the pathname."
2270 msgstr ""
2271
2272 #. type: Plain text
2273 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2274 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2275 msgid ""
2276 "If the pathname begins with \"./\" (i.e., it is a relative pathname), the "
2277 "supervisor sends a B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> response to the "
2278 "kernel to say that the kernel should execute the target process's "
2279 "B<mkdir>(2) call."
2280 msgstr ""
2281
2282 #. type: Plain text
2283 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2284 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2285 msgid ""
2286 "If the pathname begins with some other prefix, the supervisor spoofs an "
2287 "error return for the target process, so that the target process's "
2288 "B<mkdir>(2) call appears to fail with the error B<EOPNOTSUPP> (\"Operation "
2289 "not supported\"). Additionally, if the specified pathname is exactly \"/"
2290 "bye\", then the supervisor terminates."
2291 msgstr ""
2292
2293 #. type: Plain text
2294 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2295 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2296 msgid ""
2297 "This program can be used to demonstrate various aspects of the behavior of "
2298 "the seccomp user-space notification mechanism. To help aid such "
2299 "demonstrations, the program logs various messages to show the operation of "
2300 "the target process (lines prefixed \"T:\") and the supervisor (indented "
2301 "lines prefixed \"S:\")."
2302 msgstr ""
2303
2304 #. type: Plain text
2305 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2306 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2307 msgid ""
2308 "In the following example, the target attempts to create the directory I</tmp/"
2309 "x>. Upon receiving the notification, the supervisor creates the directory "
2310 "on the target's behalf, and spoofs a success return to be received by the "
2311 "target process's B<mkdir>(2) call."
2312 msgstr ""
2313
2314 #. type: Plain text
2315 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2316 #: opensuse-tumbleweed
2317 #, no-wrap
2318 msgid ""
2319 "$B< ./seccomp_unotify /tmp/x>;\n"
2320 "T: PID = 23168\n"
2321 "\\&\n"
2322 "T: about to mkdir(\"/tmp/x\")\n"
2323 " S: got notification (ID 0x17445c4a0f4e0e3c) for PID 23168\n"
2324 " S: executing: mkdir(\"/tmp/x\", 0700)\n"
2325 " S: success! spoofed return = 6\n"
2326 " S: sending response (flags = 0; val = 6; error = 0)\n"
2327 "T: SUCCESS: mkdir(2) returned 6\n"
2328 "\\&\n"
2329 "T: terminating\n"
2330 " S: target has terminated; bye\n"
2331 msgstr ""
2332
2333 #. type: Plain text
2334 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2335 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2336 msgid ""
2337 "In the above output, note that the spoofed return value seen by the target "
2338 "process is 6 (the length of the pathname I</tmp/x>), whereas a normal "
2339 "B<mkdir>(2) call returns 0 on success."
2340 msgstr ""
2341
2342 #. type: Plain text
2343 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2344 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2345 msgid ""
2346 "In the next example, the target attempts to create a directory using the "
2347 "relative pathname I<./sub>. Since this pathname starts with \"./\", the "
2348 "supervisor sends a B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> response to the "
2349 "kernel, and the kernel then (successfully) executes the target process's "
2350 "B<mkdir>(2) call."
2351 msgstr ""
2352
2353 #. type: Plain text
2354 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2355 #: opensuse-tumbleweed
2356 #, no-wrap
2357 msgid ""
2358 "$B< ./seccomp_unotify ./sub>;\n"
2359 "T: PID = 23204\n"
2360 "\\&\n"
2361 "T: about to mkdir(\"./sub\")\n"
2362 " S: got notification (ID 0xddb16abe25b4c12) for PID 23204\n"
2363 " S: target can execute system call\n"
2364 " S: sending response (flags = 0x1; val = 0; error = 0)\n"
2365 "T: SUCCESS: mkdir(2) returned 0\n"
2366 "\\&\n"
2367 "T: terminating\n"
2368 " S: target has terminated; bye\n"
2369 msgstr ""
2370
2371 #. type: Plain text
2372 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2373 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2374 msgid ""
2375 "If the target process attempts to create a directory with a pathname that "
2376 "doesn't start with \".\" and doesn't begin with the prefix \"/tmp/\", then "
2377 "the supervisor spoofs an error return (B<EOPNOTSUPP>, \"Operation not "
2378 "supported\") for the target's B<mkdir>(2) call (which is not executed):"
2379 msgstr ""
2380
2381 #. type: Plain text
2382 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2383 #: opensuse-tumbleweed
2384 #, no-wrap
2385 msgid ""
2386 "$B< ./seccomp_unotify /xxx>;\n"
2387 "T: PID = 23178\n"
2388 "\\&\n"
2389 "T: about to mkdir(\"/xxx\")\n"
2390 " S: got notification (ID 0xe7dc095d1c524e80) for PID 23178\n"
2391 " S: spoofing error response (Operation not supported)\n"
2392 " S: sending response (flags = 0; val = 0; error = -95)\n"
2393 "T: ERROR: mkdir(2): Operation not supported\n"
2394 "\\&\n"
2395 "T: terminating\n"
2396 " S: target has terminated; bye\n"
2397 msgstr ""
2398
2399 #. type: Plain text
2400 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2401 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2402 msgid ""
2403 "In the next example, the target process attempts to create a directory with "
2404 "the pathname B</tmp/nosuchdir/b>. Upon receiving the notification, the "
2405 "supervisor attempts to create that directory, but the B<mkdir>(2) call "
2406 "fails because the directory B</tmp/nosuchdir> does not exist. Consequently, "
2407 "the supervisor spoofs an error return that passes the error that it received "
2408 "back to the target process's B<mkdir>(2) call."
2409 msgstr ""
2410
2411 #. type: Plain text
2412 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2413 #: opensuse-tumbleweed
2414 #, no-wrap
2415 msgid ""
2416 "$B< ./seccomp_unotify /tmp/nosuchdir/b>;\n"
2417 "T: PID = 23199\n"
2418 "\\&\n"
2419 "T: about to mkdir(\"/tmp/nosuchdir/b\")\n"
2420 " S: got notification (ID 0x8744454293506046) for PID 23199\n"
2421 " S: executing: mkdir(\"/tmp/nosuchdir/b\", 0700)\n"
2422 " S: failure! (errno = 2; No such file or directory)\n"
2423 " S: sending response (flags = 0; val = 0; error = -2)\n"
2424 "T: ERROR: mkdir(2): No such file or directory\n"
2425 "\\&\n"
2426 "T: terminating\n"
2427 " S: target has terminated; bye\n"
2428 msgstr ""
2429
2430 #. type: Plain text
2431 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2432 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2433 msgid ""
2434 "If the supervisor receives a notification and sees that the argument of the "
2435 "target's B<mkdir>(2) is the string \"/bye\", then (as well as spoofing an "
2436 "B<EOPNOTSUPP> error), the supervisor terminates. If the target process "
2437 "subsequently executes another B<mkdir>(2) that triggers its seccomp filter "
2438 "to return the B<SECCOMP_RET_USER_NOTIF> action value, then the kernel causes "
2439 "the target process's system call to fail with the error B<ENOSYS> "
2440 "(\"Function not implemented\"). This is demonstrated by the following "
2441 "example:"
2442 msgstr ""
2443
2444 #. type: Plain text
2445 #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1
2446 #: opensuse-tumbleweed
2447 #, no-wrap
2448 msgid ""
2449 "$B< ./seccomp_unotify /bye /tmp/y>;\n"
2450 "T: PID = 23185\n"
2451 "\\&\n"
2452 "T: about to mkdir(\"/bye\")\n"
2453 " S: got notification (ID 0xa81236b1d2f7b0f4) for PID 23185\n"
2454 " S: spoofing error response (Operation not supported)\n"
2455 " S: sending response (flags = 0; val = 0; error = -95)\n"
2456 " S: terminating **********\n"
2457 "T: ERROR: mkdir(2): Operation not supported\n"
2458 "\\&\n"
2459 "T: about to mkdir(\"/tmp/y\")\n"
2460 "T: ERROR: mkdir(2): Function not implemented\n"
2461 "\\&\n"
2462 "T: terminating\n"
2463 msgstr ""
2464
2465 #. type: SS
2466 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
2467 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
2468 #, no-wrap
2469 msgid "Program source"
2470 msgstr ""
2471
2472 #. type: Plain text
2473 #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed
2474 #, no-wrap
2475 msgid ""
2476 "#define _GNU_SOURCE\n"
2477 "#include E<lt>err.hE<gt>\n"
2478 "#include E<lt>errno.hE<gt>\n"
2479 "#include E<lt>fcntl.hE<gt>\n"
2480 "#include E<lt>limits.hE<gt>\n"
2481 "#include E<lt>linux/audit.hE<gt>\n"
2482 "#include E<lt>linux/filter.hE<gt>\n"
2483 "#include E<lt>linux/seccomp.hE<gt>\n"
2484 "#include E<lt>signal.hE<gt>\n"
2485 "#include E<lt>stdbool.hE<gt>\n"
2486 "#include E<lt>stdcountof.hE<gt>\n"
2487 "#include E<lt>stddef.hE<gt>\n"
2488 "#include E<lt>stdint.hE<gt>\n"
2489 "#include E<lt>stdio.hE<gt>\n"
2490 "#include E<lt>stdlib.hE<gt>\n"
2491 "#include E<lt>string.hE<gt>\n"
2492 "#include E<lt>sys/ioctl.hE<gt>\n"
2493 "#include E<lt>sys/prctl.hE<gt>\n"
2494 "#include E<lt>sys/socket.hE<gt>\n"
2495 "#include E<lt>sys/stat.hE<gt>\n"
2496 "#include E<lt>sys/syscall.hE<gt>\n"
2497 "#include E<lt>sys/types.hE<gt>\n"
2498 "#include E<lt>sys/un.hE<gt>\n"
2499 "#include E<lt>unistd.hE<gt>\n"
2500 "\\&\n"
2501 "#define streq(...) (strcmp(__VA_ARGS__) == 0)\n"
2502 "\\&\n"
2503 "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n"
2504 " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n"
2505 "\\&\n"
2506 "static int\n"
2507 "sendfd(int sockfd, int fd)\n"
2508 "{\n"
2509 " int data;\n"
2510 " struct iovec iov;\n"
2511 " struct msghdr msgh;\n"
2512 " struct cmsghdr *cmsgp;\n"
2513 "\\&\n"
2514 " /* Allocate a char array of suitable size to hold the ancillary data.\n"
2515 " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n"
2516 " union to ensure that it is suitably aligned. */\n"
2517 " union {\n"
2518 " char buf[CMSG_SPACE(sizeof(int))];\n"
2519 " /* Space large enough to hold an \\[aq]int\\[aq] */\n"
2520 " struct cmsghdr align;\n"
2521 " } controlMsg;\n"
2522 "\\&\n"
2523 " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n"
2524 " destination socket when sending a datagram. However, we do not\n"
2525 " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n"
2526 "\\&\n"
2527 " msgh.msg_name = NULL;\n"
2528 " msgh.msg_namelen = 0;\n"
2529 "\\&\n"
2530 " /* On Linux, we must transmit at least one byte of real data in\n"
2531 " order to send ancillary data. We transmit an arbitrary integer\n"
2532 " whose value is ignored by recvfd(). */\n"
2533 "\\&\n"
2534 " msgh.msg_iov = &iov;\n"
2535 " msgh.msg_iovlen = 1;\n"
2536 " iov.iov_base = &data;\n"
2537 " iov.iov_len = sizeof(int);\n"
2538 " data = 12345;\n"
2539 "\\&\n"
2540 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
2541 "\\&\n"
2542 " msgh.msg_control = controlMsg.buf;\n"
2543 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
2544 "\\&\n"
2545 " /* Set up ancillary data describing file descriptor to send */\n"
2546 "\\&\n"
2547 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
2548 " cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n"
2549 " cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n"
2550 " cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n"
2551 " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n"
2552 "\\&\n"
2553 " /* Send real plus ancillary data */\n"
2554 "\\&\n"
2555 " if (sendmsg(sockfd, &msgh, 0) == -1)\n"
2556 " return -1;\n"
2557 "\\&\n"
2558 " return 0;\n"
2559 "}\n"
2560 "\\&\n"
2561 "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n"
2562 " the received file descriptor on success, or -1 on error. */\n"
2563 "\\&\n"
2564 "static int\n"
2565 "recvfd(int sockfd)\n"
2566 "{\n"
2567 " int data, fd;\n"
2568 " ssize_t nr;\n"
2569 " struct iovec iov;\n"
2570 " struct msghdr msgh;\n"
2571 "\\&\n"
2572 " /* Allocate a char buffer for the ancillary data. See the comments\n"
2573 " in sendfd() */\n"
2574 " union {\n"
2575 " char buf[CMSG_SPACE(sizeof(int))];\n"
2576 " struct cmsghdr align;\n"
2577 " } controlMsg;\n"
2578 " struct cmsghdr *cmsgp;\n"
2579 "\\&\n"
2580 " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n"
2581 " sending socket. However, we do not need this information. */\n"
2582 "\\&\n"
2583 " msgh.msg_name = NULL;\n"
2584 " msgh.msg_namelen = 0;\n"
2585 "\\&\n"
2586 " /* Specify buffer for receiving real data */\n"
2587 "\\&\n"
2588 " msgh.msg_iov = &iov;\n"
2589 " msgh.msg_iovlen = 1;\n"
2590 " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n"
2591 " iov.iov_len = sizeof(int);\n"
2592 "\\&\n"
2593 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
2594 "\\&\n"
2595 " msgh.msg_control = controlMsg.buf;\n"
2596 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
2597 "\\&\n"
2598 " /* Receive real plus ancillary data; real data is ignored */\n"
2599 "\\&\n"
2600 " nr = recvmsg(sockfd, &msgh, 0);\n"
2601 " if (nr == -1)\n"
2602 " return -1;\n"
2603 "\\&\n"
2604 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
2605 "\\&\n"
2606 " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n"
2607 "\\&\n"
2608 " if (cmsgp == NULL\n"
2609 " || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n"
2610 " || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n"
2611 " || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n"
2612 " {\n"
2613 " errno = EINVAL;\n"
2614 " return -1;\n"
2615 " }\n"
2616 "\\&\n"
2617 " /* Return the received file descriptor to our caller */\n"
2618 "\\&\n"
2619 " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n"
2620 " return fd;\n"
2621 "}\n"
2622 "\\&\n"
2623 "static void\n"
2624 "sigchldHandler(int sig)\n"
2625 "{\n"
2626 " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n"
2627 "\\&\n"
2628 " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n"
2629 " _exit(EXIT_SUCCESS);\n"
2630 "}\n"
2631 "\\&\n"
2632 "static int\n"
2633 "seccomp(unsigned int operation, unsigned int flags, void *args)\n"
2634 "{\n"
2635 " return syscall(SYS_seccomp, operation, flags, args);\n"
2636 "}\n"
2637 "\\&\n"
2638 "/* The following is the x86-64-specific BPF boilerplate code for checking\n"
2639 " that the BPF program is running on the right architecture + ABI. At\n"
2640 " completion of these instructions, the accumulator contains the system\n"
2641 " call number. */\n"
2642 "\\&\n"
2643 "/* For the x32 ABI, all system call numbers have bit 30 set */\n"
2644 "\\&\n"
2645 "#define X32_SYSCALL_BIT 0x40000000\n"
2646 "\\&\n"
2647 "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n"
2648 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
2649 " (offsetof(struct seccomp_data, arch))), \\[rs]\n"
2650 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n"
2651 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
2652 " (offsetof(struct seccomp_data, nr))), \\[rs]\n"
2653 " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n"
2654 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n"
2655 "\\&\n"
2656 "/* installNotifyFilter() installs a seccomp filter that generates\n"
2657 " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n"
2658 " calls mkdir(2); the filter allows all other system calls.\n"
2659 "\\&\n"
2660 " The function return value is a file descriptor from which the\n"
2661 " user-space notifications can be fetched. */\n"
2662 "\\&\n"
2663 "static int\n"
2664 "installNotifyFilter(void)\n"
2665 "{\n"
2666 " int notifyFd;\n"
2667 "\\&\n"
2668 " struct sock_filter filter[] = {\n"
2669 " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n"
2670 "\\&\n"
2671 " /* mkdir() triggers notification to user-space supervisor */\n"
2672 "\\&\n"
2673 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n"
2674 " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n"
2675 "\\&\n"
2676 " /* Every other system call is allowed */\n"
2677 "\\&\n"
2678 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n"
2679 " };\n"
2680 "\\&\n"
2681 " struct sock_fprog prog = {\n"
2682 " .len = countof(filter),\n"
2683 " .filter = filter,\n"
2684 " };\n"
2685 "\\&\n"
2686 " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
2687 " as a result, seccomp() returns a notification file descriptor. */\n"
2688 "\\&\n"
2689 " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n"
2690 " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n"
2691 " if (notifyFd == -1)\n"
2692 " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n"
2693 "\\&\n"
2694 " return notifyFd;\n"
2695 "}\n"
2696 "\\&\n"
2697 "/* Close a pair of sockets created by socketpair() */\n"
2698 "\\&\n"
2699 "static void\n"
2700 "closeSocketPair(int sockPair[2])\n"
2701 "{\n"
2702 " if (close(sockPair[0]) == -1)\n"
2703 " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n"
2704 " if (close(sockPair[1]) == -1)\n"
2705 " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n"
2706 "}\n"
2707 "\\&\n"
2708 "/* Implementation of the target process. Create a child process that:\n"
2709 "\\&\n"
2710 " (1) installs a seccomp filter with the\n"
2711 " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
2712 " (2) writes the seccomp notification file descriptor returned from\n"
2713 " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n"
2714 " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n"
2715 "\\&\n"
2716 " The function return value in the parent is the PID of the child\n"
2717 " process; the child does not return from this function. */\n"
2718 "\\&\n"
2719 "static pid_t\n"
2720 "targetProcess(int sockPair[2], char *argv[])\n"
2721 "{\n"
2722 " int notifyFd, s;\n"
2723 " pid_t targetPid;\n"
2724 "\\&\n"
2725 " targetPid = fork();\n"
2726 "\\&\n"
2727 " if (targetPid == -1)\n"
2728 " err(EXIT_FAILURE, \"fork\");\n"
2729 "\\&\n"
2730 " if (targetPid E<gt> 0) /* In parent, return PID of child */\n"
2731 " return targetPid;\n"
2732 "\\&\n"
2733 " /* Child falls through to here */\n"
2734 "\\&\n"
2735 " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n"
2736 "\\&\n"
2737 " /* Install seccomp filter(s) */\n"
2738 "\\&\n"
2739 " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n"
2740 " err(EXIT_FAILURE, \"prctl\");\n"
2741 "\\&\n"
2742 " notifyFd = installNotifyFilter();\n"
2743 "\\&\n"
2744 " /* Pass the notification file descriptor to the tracing process over\n"
2745 " a UNIX domain socket */\n"
2746 "\\&\n"
2747 " if (sendfd(sockPair[0], notifyFd) == -1)\n"
2748 " err(EXIT_FAILURE, \"sendfd\");\n"
2749 "\\&\n"
2750 " /* Notification and socket FDs are no longer needed in target */\n"
2751 "\\&\n"
2752 " if (close(notifyFd) == -1)\n"
2753 " err(EXIT_FAILURE, \"close-target-notify-fd\");\n"
2754 "\\&\n"
2755 " closeSocketPair(sockPair);\n"
2756 "\\&\n"
2757 " /* Perform a mkdir() call for each of the command-line arguments */\n"
2758 "\\&\n"
2759 " for (char **ap = argv; *ap != NULL; ap++) {\n"
2760 " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n"
2761 "\\&\n"
2762 " s = mkdir(*ap, 0700);\n"
2763 " if (s == -1)\n"
2764 " perror(\"T: ERROR: mkdir(2)\");\n"
2765 " else\n"
2766 " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n"
2767 " }\n"
2768 "\\&\n"
2769 " printf(\"\\[rs]nT: terminating\\[rs]n\");\n"
2770 " exit(EXIT_SUCCESS);\n"
2771 "}\n"
2772 "\\&\n"
2773 "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n"
2774 " operation is still valid. It will no longer be valid if the target\n"
2775 " process has terminated or is no longer blocked in the system call that\n"
2776 " generated the notification (because it was interrupted by a signal).\n"
2777 "\\&\n"
2778 " This operation can be used when doing such things as accessing\n"
2779 " /proc/PID files in the target process in order to avoid TOCTOU race\n"
2780 " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n"
2781 " terminates and is reused by another process. */\n"
2782 "\\&\n"
2783 "static bool\n"
2784 "cookieIsValid(int notifyFd, uint64_t id)\n"
2785 "{\n"
2786 " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n"
2787 "}\n"
2788 "\\&\n"
2789 "/* Access the memory of the target process in order to fetch the\n"
2790 " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n"
2791 " \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n"
2792 " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n"
2793 "\\&\n"
2794 " Returns true if the pathname is successfully fetched, and false\n"
2795 " otherwise. For possible causes of failure, see the comments below. */\n"
2796 "\\&\n"
2797 "static bool\n"
2798 "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n"
2799 " int argNum, char *path, size_t size)\n"
2800 "{\n"
2801 " int procMemFd;\n"
2802 " char procMemPath[PATH_MAX];\n"
2803 " ssize_t nread;\n"
2804 "\\&\n"
2805 " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n"
2806 "\\&\n"
2807 " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n"
2808 " if (procMemFd == -1)\n"
2809 " return false;\n"
2810 "\\&\n"
2811 " /* Check that the process whose info we are accessing is still alive\n"
2812 " and blocked in the system call that caused the notification.\n"
2813 " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n"
2814 " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n"
2815 " descriptor that we opened corresponded to the process for which we\n"
2816 " received a notification. If that process subsequently terminates,\n"
2817 " then read() on that file descriptor will return 0 (EOF). */\n"
2818 "\\&\n"
2819 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
2820 " close(procMemFd);\n"
2821 " return false;\n"
2822 " }\n"
2823 "\\&\n"
2824 " /* Read bytes at the location containing the pathname argument */\n"
2825 "\\&\n"
2826 " nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n"
2827 "\\&\n"
2828 " close(procMemFd);\n"
2829 "\\&\n"
2830 " if (nread E<lt>= 0)\n"
2831 " return false;\n"
2832 "\\&\n"
2833 " /* Once again check that the notification ID is still valid. The\n"
2834 " case we are particularly concerned about here is that just\n"
2835 " before we fetched the pathname, the target\\[aq]s blocked system\n"
2836 " call was interrupted by a signal handler, and after the handler\n"
2837 " returned, the target carried on execution (past the interrupted\n"
2838 " system call). In that case, we have no guarantees about what we\n"
2839 " are reading, since the target\\[aq]s memory may have been arbitrarily\n"
2840 " changed by subsequent operations. */\n"
2841 "\\&\n"
2842 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
2843 " perror(\"\\[rs]tS: notification ID check failed!!!\");\n"
2844 " return false;\n"
2845 " }\n"
2846 "\\&\n"
2847 " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n"
2848 " we have no guarantees about what was in the memory of the target\n"
2849 " process. (The memory may have been modified by another thread, or\n"
2850 " even by an external attacking process.) We therefore treat the\n"
2851 " buffer returned by pread() as untrusted input. The buffer should\n"
2852 " contain a terminating null byte; if not, then we will trigger an\n"
2853 " error for the target process. */\n"
2854 "\\&\n"
2855 " if (strnlen(path, nread) E<lt> nread)\n"
2856 " return true;\n"
2857 "\\&\n"
2858 " return false;\n"
2859 "}\n"
2860 "\\&\n"
2861 "/* Allocate buffers for the seccomp user-space notification request and\n"
2862 " response structures. It is the caller\\[aq]s responsibility to free the\n"
2863 " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n"
2864 "\\&\n"
2865 "static void\n"
2866 "allocSeccompNotifBuffers(struct seccomp_notif **req,\n"
2867 " struct seccomp_notif_resp **resp,\n"
2868 " struct seccomp_notif_sizes *sizes)\n"
2869 "{\n"
2870 " size_t resp_size;\n"
2871 "\\&\n"
2872 " /* Discover the sizes of the structures that are used to receive\n"
2873 " notifications and send notification responses, and allocate\n"
2874 " buffers of those sizes. */\n"
2875 "\\&\n"
2876 " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n"
2877 " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n"
2878 "\\&\n"
2879 " *req = malloc(sizes-E<gt>seccomp_notif);\n"
2880 " if (*req == NULL)\n"
2881 " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n"
2882 "\\&\n"
2883 " /* When allocating the response buffer, we must allow for the fact\n"
2884 " that the user-space binary may have been built with user-space\n"
2885 " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n"
2886 " response buffer expected by the (older) kernel. Therefore, we\n"
2887 " allocate a buffer that is the maximum of the two sizes. This\n"
2888 " ensures that if the supervisor places bytes into the response\n"
2889 " structure that are past the response size that the kernel expects,\n"
2890 " then the supervisor is not touching an invalid memory location. */\n"
2891 "\\&\n"
2892 " resp_size = sizes-E<gt>seccomp_notif_resp;\n"
2893 " if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n"
2894 " resp_size = sizeof(struct seccomp_notif_resp);\n"
2895 "\\&\n"
2896 " *resp = malloc(resp_size);\n"
2897 " if (*resp == NULL)\n"
2898 " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n"
2899 "\\&\n"
2900 "}\n"
2901 "\\&\n"
2902 "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n"
2903 " descriptor, \\[aq]notifyFd\\[aq]. */\n"
2904 "\\&\n"
2905 "static void\n"
2906 "handleNotifications(int notifyFd)\n"
2907 "{\n"
2908 " bool pathOK;\n"
2909 " char path[PATH_MAX];\n"
2910 " struct seccomp_notif *req;\n"
2911 " struct seccomp_notif_resp *resp;\n"
2912 " struct seccomp_notif_sizes sizes;\n"
2913 "\\&\n"
2914 " allocSeccompNotifBuffers(&req, &resp, &sizes);\n"
2915 "\\&\n"
2916 " /* Loop handling notifications */\n"
2917 "\\&\n"
2918 " for (;;) {\n"
2919 "\\&\n"
2920 " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n"
2921 "\\&\n"
2922 " memset(req, 0, sizes.seccomp_notif);\n"
2923 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n"
2924 " if (errno == EINTR)\n"
2925 " continue;\n"
2926 " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n"
2927 " }\n"
2928 "\\&\n"
2929 " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n"
2930 " req-E<gt>id, req-E<gt>pid);\n"
2931 "\\&\n"
2932 " /* The only system call that can generate a notification event\n"
2933 " is mkdir(2). Nevertheless, we check that the notified system\n"
2934 " call is indeed mkdir() as kind of future-proofing of this\n"
2935 " code in case the seccomp filter is later modified to\n"
2936 " generate notifications for other system calls. */\n"
2937 "\\&\n"
2938 " if (req-E<gt>data.nr != SYS_mkdir) {\n"
2939 " printf(\"\\[rs]tS: notification contained unexpected \"\n"
2940 " \"system call number; bye!!!\\[rs]n\");\n"
2941 " exit(EXIT_FAILURE);\n"
2942 " }\n"
2943 "\\&\n"
2944 " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n"
2945 "\\&\n"
2946 " /* Prepopulate some fields of the response */\n"
2947 "\\&\n"
2948 " resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n"
2949 " resp-E<gt>flags = 0;\n"
2950 " resp-E<gt>val = 0;\n"
2951 "\\&\n"
2952 " /* If getTargetPathname() failed, trigger an EINVAL error\n"
2953 " response (sending this response may yield an error if the\n"
2954 " failure occurred because the notification ID was no longer\n"
2955 " valid); if the directory is in /tmp, then create it on behalf\n"
2956 " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n"
2957 " kernel to let the target process execute the mkdir();\n"
2958 " otherwise, give an error for a directory pathname in any other\n"
2959 " location. */\n"
2960 "\\&\n"
2961 " if (!pathOK) {\n"
2962 " resp-E<gt>error = -EINVAL;\n"
2963 " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n"
2964 " strerror(-resp-E<gt>error));\n"
2965 " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n"
2966 " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n"
2967 " path, req-E<gt>data.args[1]);\n"
2968 "\\&\n"
2969 " if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n"
2970 " resp-E<gt>error = 0; /* \"Success\" */\n"
2971 " resp-E<gt>val = strlen(path); /* Used as return value of\n"
2972 " mkdir() in target */\n"
2973 " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n"
2974 " resp-E<gt>val);\n"
2975 " } else {\n"
2976 "\\&\n"
2977 " /* If mkdir() failed in the supervisor, pass the error\n"
2978 " back to the target */\n"
2979 "\\&\n"
2980 " resp-E<gt>error = -errno;\n"
2981 " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n"
2982 " strerror(errno));\n"
2983 " }\n"
2984 " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n"
2985 " resp-E<gt>error = resp-E<gt>val = 0;\n"
2986 " resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n"
2987 " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n"
2988 " } else {\n"
2989 " resp-E<gt>error = -EOPNOTSUPP;\n"
2990 " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n"
2991 " strerror(-resp-E<gt>error));\n"
2992 " }\n"
2993 "\\&\n"
2994 " /* Send a response to the notification */\n"
2995 "\\&\n"
2996 " printf(\"\\[rs]tS: sending response \"\n"
2997 " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n"
2998 " resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n"
2999 "\\&\n"
3000 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n"
3001 " if (errno == ENOENT)\n"
3002 " printf(\"\\[rs]tS: response failed with ENOENT; \"\n"
3003 " \"perhaps target process\\[aq]s syscall was \"\n"
3004 " \"interrupted by a signal?\\[rs]n\");\n"
3005 " else\n"
3006 " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n"
3007 " }\n"
3008 "\\&\n"
3009 " /* If the pathname is just \"/bye\", then the supervisor breaks out\n"
3010 " of the loop and terminates. This allows us to see what happens\n"
3011 " if the target process makes further calls to mkdir(2). */\n"
3012 "\\&\n"
3013 " if (streq(path, \"/bye\"))\n"
3014 " break;\n"
3015 " }\n"
3016 "\\&\n"
3017 " free(req);\n"
3018 " free(resp);\n"
3019 " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n"
3020 " exit(EXIT_FAILURE);\n"
3021 "}\n"
3022 "\\&\n"
3023 "/* Implementation of the supervisor process:\n"
3024 "\\&\n"
3025 " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n"
3026 " (2) handles notifications that arrive on that file descriptor. */\n"
3027 "\\&\n"
3028 "static void\n"
3029 "supervisor(int sockPair[2])\n"
3030 "{\n"
3031 " int notifyFd;\n"
3032 "\\&\n"
3033 " notifyFd = recvfd(sockPair[1]);\n"
3034 "\\&\n"
3035 " if (notifyFd == -1)\n"
3036 " err(EXIT_FAILURE, \"recvfd\");\n"
3037 "\\&\n"
3038 " closeSocketPair(sockPair); /* We no longer need the socket pair */\n"
3039 "\\&\n"
3040 " handleNotifications(notifyFd);\n"
3041 "}\n"
3042 "\\&\n"
3043 "int\n"
3044 "main(int argc, char *argv[])\n"
3045 "{\n"
3046 " int sockPair[2];\n"
3047 " struct sigaction sa;\n"
3048 "\\&\n"
3049 " setbuf(stdout, NULL);\n"
3050 "\\&\n"
3051 " if (argc E<lt> 2) {\n"
3052 " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n"
3053 " exit(EXIT_FAILURE);\n"
3054 " }\n"
3055 "\\&\n"
3056 " /* Create a UNIX domain socket that is used to pass the seccomp\n"
3057 " notification file descriptor from the target process to the\n"
3058 " supervisor process. */\n"
3059 "\\&\n"
3060 " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n"
3061 " err(EXIT_FAILURE, \"socketpair\");\n"
3062 "\\&\n"
3063 " /* Create a child process--the \"target\"--that installs seccomp\n"
3064 " filtering. The target process writes the seccomp notification\n"
3065 " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n"
3066 " each directory in the command-line arguments. */\n"
3067 "\\&\n"
3068 " (void) targetProcess(sockPair, &argv[optind]);\n"
3069 "\\&\n"
3070 " /* Catch SIGCHLD when the target terminates, so that the\n"
3071 " supervisor can also terminate. */\n"
3072 "\\&\n"
3073 " sa.sa_handler = sigchldHandler;\n"
3074 " sa.sa_flags = 0;\n"
3075 " sigemptyset(&sa.sa_mask);\n"
3076 " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n"
3077 " err(EXIT_FAILURE, \"sigaction\");\n"
3078 "\\&\n"
3079 " supervisor(sockPair);\n"
3080 "\\&\n"
3081 " exit(EXIT_SUCCESS);\n"
3082 "}\n"
3083 msgstr ""
3084
3085 #. SRC END
3086 #. type: SH
3087 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
3088 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
3089 #, no-wrap
3090 msgid "SEE ALSO"
3091 msgstr ""
3092
3093 #. type: Plain text
3094 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
3095 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
3096 msgid "B<ioctl>(2), B<pidfd_getfd>(2), B<pidfd_open>(2), B<seccomp>(2)"
3097 msgstr ""
3098
3099 #. type: Plain text
3100 #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide
3101 #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed
3102 msgid ""
3103 "A further example program can be found in the kernel source file I<samples/"
3104 "seccomp/user-trap.c>."
3105 msgstr ""
3106
3107 #. type: TH
3108 #: debian-trixie
3109 #, no-wrap
3110 msgid "2024-06-15"
3111 msgstr ""
3112
3113 #. type: TH
3114 #: debian-trixie
3115 #, no-wrap
3116 msgid "Linux man-pages 6.9.1"
3117 msgstr ""
3118
3119 #. type: Plain text
3120 #: debian-trixie
3121 msgid "Standard C library (I<libc>, I<-lc>)"
3122 msgstr ""
3123
3124 #. type: Plain text
3125 #: debian-trixie
3126 msgid ""
3127 "On success, this operation returns 0; on failure, -1 is returned, and "
3128 "I<errno> is set to indicate the cause of the error. This operation can fail "
3129 "with the following errors:"
3130 msgstr ""
3131
3132 #. type: Plain text
3133 #: debian-trixie
3134 msgid ""
3135 "On error, -1 is returned and I<errno> is set to indicate the cause of the "
3136 "error."
3137 msgstr ""
3138
3139 #. type: Plain text
3140 #: debian-trixie fedora-44 fedora-rawhide
3141 #, no-wrap
3142 msgid ""
3143 "int fd, removeFd;\n"
3144 "\\&\n"
3145 "fd = openat(req-E<gt>data.args[0], path, req-E<gt>data.args[2],\n"
3146 " req-E<gt>data.args[3]);\n"
3147 "\\&\n"
3148 "struct seccomp_notif_addfd addfd;\n"
3149 "addfd.id = req-E<gt>id; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n"
3150 "addfd.srcfd = fd;\n"
3151 "addfd.newfd = 0;\n"
3152 "addfd.flags = 0;\n"
3153 "addfd.newfd_flags = O_CLOEXEC;\n"
3154 "\\&\n"
3155 "targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n"
3156 "\\&\n"
3157 "close(fd); /* No longer needed in supervisor */\n"
3158 "\\&\n"
3159 "struct seccomp_notif_resp *resp;\n"
3160 " /* Code to allocate 'resp' omitted */\n"
3161 "resp-E<gt>id = req-E<gt>id;\n"
3162 "resp-E<gt>error = 0; /* \"Success\" */\n"
3163 "resp-E<gt>val = targetFd;\n"
3164 "resp-E<gt>flags = 0;\n"
3165 "ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n"
3166 msgstr ""
3167
3168 #. type: SS
3169 #: debian-trixie fedora-44 fedora-rawhide
3170 #, no-wrap
3171 msgid "Caveats regarding the use of I</proc/>tidI</mem>"
3172 msgstr ""
3173
3174 #. type: Plain text
3175 #: debian-trixie fedora-44 fedora-rawhide
3176 msgid ""
3177 "The discussion above noted the need to use the "
3178 "B<SECCOMP_IOCTL_NOTIF_ID_VALID> B<ioctl>(2) when opening the I</proc/>tidI</"
3179 "mem> file of the target to avoid the possibility of accessing the memory of "
3180 "the wrong process in the event that the target terminates and its ID is "
3181 "recycled by another (unrelated) thread. However, the use of this "
3182 "B<ioctl>(2) operation is also necessary in other situations, as explained "
3183 "in the following paragraphs."
3184 msgstr ""
3185
3186 #. type: Plain text
3187 #: debian-trixie fedora-44 fedora-rawhide
3188 msgid ""
3189 "In this scenario, it is important to note that if the target's system call "
3190 "is now interrupted by a signal, the supervisor is I<not> informed of this. "
3191 "If the supervisor does not take suitable steps to actively discover that the "
3192 "target's system call has been canceled, various difficulties can occur. "
3193 "Taking the example of B<accept>(2), the supervisor might remain blocked in "
3194 "its B<accept>(2) holding a port number that the target (which, after the "
3195 "interruption by the signal handler, perhaps closed its listening socket) "
3196 "might expect to be able to reuse in a B<bind>(2) call."
3197 msgstr ""
3198
3199 #. type: Plain text
3200 #: debian-trixie fedora-44 fedora-rawhide
3201 #, no-wrap
3202 msgid ""
3203 "$ B<./seccomp_unotify /tmp/x>\n"
3204 "T: PID = 23168\n"
3205 "\\&\n"
3206 "T: about to mkdir(\"/tmp/x\")\n"
3207 " S: got notification (ID 0x17445c4a0f4e0e3c) for PID 23168\n"
3208 " S: executing: mkdir(\"/tmp/x\", 0700)\n"
3209 " S: success! spoofed return = 6\n"
3210 " S: sending response (flags = 0; val = 6; error = 0)\n"
3211 "T: SUCCESS: mkdir(2) returned 6\n"
3212 "\\&\n"
3213 "T: terminating\n"
3214 " S: target has terminated; bye\n"
3215 msgstr ""
3216
3217 #. type: Plain text
3218 #: debian-trixie fedora-44 fedora-rawhide
3219 #, no-wrap
3220 msgid ""
3221 "$ B<./seccomp_unotify ./sub>\n"
3222 "T: PID = 23204\n"
3223 "\\&\n"
3224 "T: about to mkdir(\"./sub\")\n"
3225 " S: got notification (ID 0xddb16abe25b4c12) for PID 23204\n"
3226 " S: target can execute system call\n"
3227 " S: sending response (flags = 0x1; val = 0; error = 0)\n"
3228 "T: SUCCESS: mkdir(2) returned 0\n"
3229 "\\&\n"
3230 "T: terminating\n"
3231 " S: target has terminated; bye\n"
3232 msgstr ""
3233
3234 #. type: Plain text
3235 #: debian-trixie fedora-44 fedora-rawhide
3236 #, no-wrap
3237 msgid ""
3238 "$ B<./seccomp_unotify /xxx>\n"
3239 "T: PID = 23178\n"
3240 "\\&\n"
3241 "T: about to mkdir(\"/xxx\")\n"
3242 " S: got notification (ID 0xe7dc095d1c524e80) for PID 23178\n"
3243 " S: spoofing error response (Operation not supported)\n"
3244 " S: sending response (flags = 0; val = 0; error = -95)\n"
3245 "T: ERROR: mkdir(2): Operation not supported\n"
3246 "\\&\n"
3247 "T: terminating\n"
3248 " S: target has terminated; bye\n"
3249 msgstr ""
3250
3251 #. type: Plain text
3252 #: debian-trixie fedora-44 fedora-rawhide
3253 #, no-wrap
3254 msgid ""
3255 "$ B<./seccomp_unotify /tmp/nosuchdir/b>\n"
3256 "T: PID = 23199\n"
3257 "\\&\n"
3258 "T: about to mkdir(\"/tmp/nosuchdir/b\")\n"
3259 " S: got notification (ID 0x8744454293506046) for PID 23199\n"
3260 " S: executing: mkdir(\"/tmp/nosuchdir/b\", 0700)\n"
3261 " S: failure! (errno = 2; No such file or directory)\n"
3262 " S: sending response (flags = 0; val = 0; error = -2)\n"
3263 "T: ERROR: mkdir(2): No such file or directory\n"
3264 "\\&\n"
3265 "T: terminating\n"
3266 " S: target has terminated; bye\n"
3267 msgstr ""
3268
3269 #. type: Plain text
3270 #: debian-trixie fedora-44 fedora-rawhide
3271 #, no-wrap
3272 msgid ""
3273 "$ B<./seccomp_unotify /bye /tmp/y>\n"
3274 "T: PID = 23185\n"
3275 "\\&\n"
3276 "T: about to mkdir(\"/bye\")\n"
3277 " S: got notification (ID 0xa81236b1d2f7b0f4) for PID 23185\n"
3278 " S: spoofing error response (Operation not supported)\n"
3279 " S: sending response (flags = 0; val = 0; error = -95)\n"
3280 " S: terminating **********\n"
3281 "T: ERROR: mkdir(2): Operation not supported\n"
3282 "\\&\n"
3283 "T: about to mkdir(\"/tmp/y\")\n"
3284 "T: ERROR: mkdir(2): Function not implemented\n"
3285 "\\&\n"
3286 "T: terminating\n"
3287 msgstr ""
3288
3289 #. type: Plain text
3290 #: debian-trixie
3291 #, no-wrap
3292 msgid ""
3293 "#define _GNU_SOURCE\n"
3294 "#include E<lt>err.hE<gt>\n"
3295 "#include E<lt>errno.hE<gt>\n"
3296 "#include E<lt>fcntl.hE<gt>\n"
3297 "#include E<lt>limits.hE<gt>\n"
3298 "#include E<lt>linux/audit.hE<gt>\n"
3299 "#include E<lt>linux/filter.hE<gt>\n"
3300 "#include E<lt>linux/seccomp.hE<gt>\n"
3301 "#include E<lt>signal.hE<gt>\n"
3302 "#include E<lt>stdbool.hE<gt>\n"
3303 "#include E<lt>stddef.hE<gt>\n"
3304 "#include E<lt>stdint.hE<gt>\n"
3305 "#include E<lt>stdio.hE<gt>\n"
3306 "#include E<lt>stdlib.hE<gt>\n"
3307 "#include E<lt>string.hE<gt>\n"
3308 "#include E<lt>sys/ioctl.hE<gt>\n"
3309 "#include E<lt>sys/prctl.hE<gt>\n"
3310 "#include E<lt>sys/socket.hE<gt>\n"
3311 "#include E<lt>sys/stat.hE<gt>\n"
3312 "#include E<lt>sys/syscall.hE<gt>\n"
3313 "#include E<lt>sys/types.hE<gt>\n"
3314 "#include E<lt>sys/un.hE<gt>\n"
3315 "#include E<lt>unistd.hE<gt>\n"
3316 "\\&\n"
3317 "#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n"
3318 "\\&\n"
3319 "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n"
3320 " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n"
3321 "\\&\n"
3322 "static int\n"
3323 "sendfd(int sockfd, int fd)\n"
3324 "{\n"
3325 " int data;\n"
3326 " struct iovec iov;\n"
3327 " struct msghdr msgh;\n"
3328 " struct cmsghdr *cmsgp;\n"
3329 "\\&\n"
3330 " /* Allocate a char array of suitable size to hold the ancillary data.\n"
3331 " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n"
3332 " union to ensure that it is suitably aligned. */\n"
3333 " union {\n"
3334 " char buf[CMSG_SPACE(sizeof(int))];\n"
3335 " /* Space large enough to hold an \\[aq]int\\[aq] */\n"
3336 " struct cmsghdr align;\n"
3337 " } controlMsg;\n"
3338 "\\&\n"
3339 " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n"
3340 " destination socket when sending a datagram. However, we do not\n"
3341 " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n"
3342 "\\&\n"
3343 " msgh.msg_name = NULL;\n"
3344 " msgh.msg_namelen = 0;\n"
3345 "\\&\n"
3346 " /* On Linux, we must transmit at least one byte of real data in\n"
3347 " order to send ancillary data. We transmit an arbitrary integer\n"
3348 " whose value is ignored by recvfd(). */\n"
3349 "\\&\n"
3350 " msgh.msg_iov = &iov;\n"
3351 " msgh.msg_iovlen = 1;\n"
3352 " iov.iov_base = &data;\n"
3353 " iov.iov_len = sizeof(int);\n"
3354 " data = 12345;\n"
3355 "\\&\n"
3356 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
3357 "\\&\n"
3358 " msgh.msg_control = controlMsg.buf;\n"
3359 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
3360 "\\&\n"
3361 " /* Set up ancillary data describing file descriptor to send */\n"
3362 "\\&\n"
3363 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
3364 " cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n"
3365 " cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n"
3366 " cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n"
3367 " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n"
3368 "\\&\n"
3369 " /* Send real plus ancillary data */\n"
3370 "\\&\n"
3371 " if (sendmsg(sockfd, &msgh, 0) == -1)\n"
3372 " return -1;\n"
3373 "\\&\n"
3374 " return 0;\n"
3375 "}\n"
3376 "\\&\n"
3377 "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n"
3378 " the received file descriptor on success, or -1 on error. */\n"
3379 "\\&\n"
3380 "static int\n"
3381 "recvfd(int sockfd)\n"
3382 "{\n"
3383 " int data, fd;\n"
3384 " ssize_t nr;\n"
3385 " struct iovec iov;\n"
3386 " struct msghdr msgh;\n"
3387 "\\&\n"
3388 " /* Allocate a char buffer for the ancillary data. See the comments\n"
3389 " in sendfd() */\n"
3390 " union {\n"
3391 " char buf[CMSG_SPACE(sizeof(int))];\n"
3392 " struct cmsghdr align;\n"
3393 " } controlMsg;\n"
3394 " struct cmsghdr *cmsgp;\n"
3395 "\\&\n"
3396 " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n"
3397 " sending socket. However, we do not need this information. */\n"
3398 "\\&\n"
3399 " msgh.msg_name = NULL;\n"
3400 " msgh.msg_namelen = 0;\n"
3401 "\\&\n"
3402 " /* Specify buffer for receiving real data */\n"
3403 "\\&\n"
3404 " msgh.msg_iov = &iov;\n"
3405 " msgh.msg_iovlen = 1;\n"
3406 " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n"
3407 " iov.iov_len = sizeof(int);\n"
3408 "\\&\n"
3409 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
3410 "\\&\n"
3411 " msgh.msg_control = controlMsg.buf;\n"
3412 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
3413 "\\&\n"
3414 " /* Receive real plus ancillary data; real data is ignored */\n"
3415 "\\&\n"
3416 " nr = recvmsg(sockfd, &msgh, 0);\n"
3417 " if (nr == -1)\n"
3418 " return -1;\n"
3419 "\\&\n"
3420 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
3421 "\\&\n"
3422 " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n"
3423 "\\&\n"
3424 " if (cmsgp == NULL\n"
3425 " || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n"
3426 " || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n"
3427 " || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n"
3428 " {\n"
3429 " errno = EINVAL;\n"
3430 " return -1;\n"
3431 " }\n"
3432 "\\&\n"
3433 " /* Return the received file descriptor to our caller */\n"
3434 "\\&\n"
3435 " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n"
3436 " return fd;\n"
3437 "}\n"
3438 "\\&\n"
3439 "static void\n"
3440 "sigchldHandler(int sig)\n"
3441 "{\n"
3442 " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n"
3443 "\\&\n"
3444 " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n"
3445 " _exit(EXIT_SUCCESS);\n"
3446 "}\n"
3447 "\\&\n"
3448 "static int\n"
3449 "seccomp(unsigned int operation, unsigned int flags, void *args)\n"
3450 "{\n"
3451 " return syscall(SYS_seccomp, operation, flags, args);\n"
3452 "}\n"
3453 "\\&\n"
3454 "/* The following is the x86-64-specific BPF boilerplate code for checking\n"
3455 " that the BPF program is running on the right architecture + ABI. At\n"
3456 " completion of these instructions, the accumulator contains the system\n"
3457 " call number. */\n"
3458 "\\&\n"
3459 "/* For the x32 ABI, all system call numbers have bit 30 set */\n"
3460 "\\&\n"
3461 "#define X32_SYSCALL_BIT 0x40000000\n"
3462 "\\&\n"
3463 "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n"
3464 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
3465 " (offsetof(struct seccomp_data, arch))), \\[rs]\n"
3466 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n"
3467 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
3468 " (offsetof(struct seccomp_data, nr))), \\[rs]\n"
3469 " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n"
3470 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n"
3471 "\\&\n"
3472 "/* installNotifyFilter() installs a seccomp filter that generates\n"
3473 " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n"
3474 " calls mkdir(2); the filter allows all other system calls.\n"
3475 "\\&\n"
3476 " The function return value is a file descriptor from which the\n"
3477 " user-space notifications can be fetched. */\n"
3478 "\\&\n"
3479 "static int\n"
3480 "installNotifyFilter(void)\n"
3481 "{\n"
3482 " int notifyFd;\n"
3483 "\\&\n"
3484 " struct sock_filter filter[] = {\n"
3485 " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n"
3486 "\\&\n"
3487 " /* mkdir() triggers notification to user-space supervisor */\n"
3488 "\\&\n"
3489 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n"
3490 " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n"
3491 "\\&\n"
3492 " /* Every other system call is allowed */\n"
3493 "\\&\n"
3494 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n"
3495 " };\n"
3496 "\\&\n"
3497 " struct sock_fprog prog = {\n"
3498 " .len = ARRAY_SIZE(filter),\n"
3499 " .filter = filter,\n"
3500 " };\n"
3501 "\\&\n"
3502 " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
3503 " as a result, seccomp() returns a notification file descriptor. */\n"
3504 "\\&\n"
3505 " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n"
3506 " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n"
3507 " if (notifyFd == -1)\n"
3508 " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n"
3509 "\\&\n"
3510 " return notifyFd;\n"
3511 "}\n"
3512 "\\&\n"
3513 "/* Close a pair of sockets created by socketpair() */\n"
3514 "\\&\n"
3515 "static void\n"
3516 "closeSocketPair(int sockPair[2])\n"
3517 "{\n"
3518 " if (close(sockPair[0]) == -1)\n"
3519 " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n"
3520 " if (close(sockPair[1]) == -1)\n"
3521 " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n"
3522 "}\n"
3523 "\\&\n"
3524 "/* Implementation of the target process; create a child process that:\n"
3525 "\\&\n"
3526 " (1) installs a seccomp filter with the\n"
3527 " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
3528 " (2) writes the seccomp notification file descriptor returned from\n"
3529 " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n"
3530 " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n"
3531 "\\&\n"
3532 " The function return value in the parent is the PID of the child\n"
3533 " process; the child does not return from this function. */\n"
3534 "\\&\n"
3535 "static pid_t\n"
3536 "targetProcess(int sockPair[2], char *argv[])\n"
3537 "{\n"
3538 " int notifyFd, s;\n"
3539 " pid_t targetPid;\n"
3540 "\\&\n"
3541 " targetPid = fork();\n"
3542 "\\&\n"
3543 " if (targetPid == -1)\n"
3544 " err(EXIT_FAILURE, \"fork\");\n"
3545 "\\&\n"
3546 " if (targetPid E<gt> 0) /* In parent, return PID of child */\n"
3547 " return targetPid;\n"
3548 "\\&\n"
3549 " /* Child falls through to here */\n"
3550 "\\&\n"
3551 " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n"
3552 "\\&\n"
3553 " /* Install seccomp filter(s) */\n"
3554 "\\&\n"
3555 " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n"
3556 " err(EXIT_FAILURE, \"prctl\");\n"
3557 "\\&\n"
3558 " notifyFd = installNotifyFilter();\n"
3559 "\\&\n"
3560 " /* Pass the notification file descriptor to the tracing process over\n"
3561 " a UNIX domain socket */\n"
3562 "\\&\n"
3563 " if (sendfd(sockPair[0], notifyFd) == -1)\n"
3564 " err(EXIT_FAILURE, \"sendfd\");\n"
3565 "\\&\n"
3566 " /* Notification and socket FDs are no longer needed in target */\n"
3567 "\\&\n"
3568 " if (close(notifyFd) == -1)\n"
3569 " err(EXIT_FAILURE, \"close-target-notify-fd\");\n"
3570 "\\&\n"
3571 " closeSocketPair(sockPair);\n"
3572 "\\&\n"
3573 " /* Perform a mkdir() call for each of the command-line arguments */\n"
3574 "\\&\n"
3575 " for (char **ap = argv; *ap != NULL; ap++) {\n"
3576 " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n"
3577 "\\&\n"
3578 " s = mkdir(*ap, 0700);\n"
3579 " if (s == -1)\n"
3580 " perror(\"T: ERROR: mkdir(2)\");\n"
3581 " else\n"
3582 " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n"
3583 " }\n"
3584 "\\&\n"
3585 " printf(\"\\[rs]nT: terminating\\[rs]n\");\n"
3586 " exit(EXIT_SUCCESS);\n"
3587 "}\n"
3588 "\\&\n"
3589 "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n"
3590 " operation is still valid. It will no longer be valid if the target\n"
3591 " process has terminated or is no longer blocked in the system call that\n"
3592 " generated the notification (because it was interrupted by a signal).\n"
3593 "\\&\n"
3594 " This operation can be used when doing such things as accessing\n"
3595 " /proc/PID files in the target process in order to avoid TOCTOU race\n"
3596 " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n"
3597 " terminates and is reused by another process. */\n"
3598 "\\&\n"
3599 "static bool\n"
3600 "cookieIsValid(int notifyFd, uint64_t id)\n"
3601 "{\n"
3602 " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n"
3603 "}\n"
3604 "\\&\n"
3605 "/* Access the memory of the target process in order to fetch the\n"
3606 " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n"
3607 " \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n"
3608 " a buffer of \\[aq]len\\[aq] bytes allocated by the caller.\n"
3609 "\\&\n"
3610 " Returns true if the pathname is successfully fetched, and false\n"
3611 " otherwise. For possible causes of failure, see the comments below. */\n"
3612 "\\&\n"
3613 "static bool\n"
3614 "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n"
3615 " int argNum, char *path, size_t len)\n"
3616 "{\n"
3617 " int procMemFd;\n"
3618 " char procMemPath[PATH_MAX];\n"
3619 " ssize_t nread;\n"
3620 "\\&\n"
3621 " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n"
3622 "\\&\n"
3623 " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n"
3624 " if (procMemFd == -1)\n"
3625 " return false;\n"
3626 "\\&\n"
3627 " /* Check that the process whose info we are accessing is still alive\n"
3628 " and blocked in the system call that caused the notification.\n"
3629 " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n"
3630 " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n"
3631 " descriptor that we opened corresponded to the process for which we\n"
3632 " received a notification. If that process subsequently terminates,\n"
3633 " then read() on that file descriptor will return 0 (EOF). */\n"
3634 "\\&\n"
3635 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
3636 " close(procMemFd);\n"
3637 " return false;\n"
3638 " }\n"
3639 "\\&\n"
3640 " /* Read bytes at the location containing the pathname argument */\n"
3641 "\\&\n"
3642 " nread = pread(procMemFd, path, len, req-E<gt>data.args[argNum]);\n"
3643 "\\&\n"
3644 " close(procMemFd);\n"
3645 "\\&\n"
3646 " if (nread E<lt>= 0)\n"
3647 " return false;\n"
3648 "\\&\n"
3649 " /* Once again check that the notification ID is still valid. The\n"
3650 " case we are particularly concerned about here is that just\n"
3651 " before we fetched the pathname, the target\\[aq]s blocked system\n"
3652 " call was interrupted by a signal handler, and after the handler\n"
3653 " returned, the target carried on execution (past the interrupted\n"
3654 " system call). In that case, we have no guarantees about what we\n"
3655 " are reading, since the target\\[aq]s memory may have been arbitrarily\n"
3656 " changed by subsequent operations. */\n"
3657 "\\&\n"
3658 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
3659 " perror(\"\\[rs]tS: notification ID check failed!!!\");\n"
3660 " return false;\n"
3661 " }\n"
3662 "\\&\n"
3663 " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n"
3664 " we have no guarantees about what was in the memory of the target\n"
3665 " process. (The memory may have been modified by another thread, or\n"
3666 " even by an external attacking process.) We therefore treat the\n"
3667 " buffer returned by pread() as untrusted input. The buffer should\n"
3668 " contain a terminating null byte; if not, then we will trigger an\n"
3669 " error for the target process. */\n"
3670 "\\&\n"
3671 " if (strnlen(path, nread) E<lt> nread)\n"
3672 " return true;\n"
3673 "\\&\n"
3674 " return false;\n"
3675 "}\n"
3676 "\\&\n"
3677 "/* Allocate buffers for the seccomp user-space notification request and\n"
3678 " response structures. It is the caller\\[aq]s responsibility to free the\n"
3679 " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n"
3680 "\\&\n"
3681 "static void\n"
3682 "allocSeccompNotifBuffers(struct seccomp_notif **req,\n"
3683 " struct seccomp_notif_resp **resp,\n"
3684 " struct seccomp_notif_sizes *sizes)\n"
3685 "{\n"
3686 " size_t resp_size;\n"
3687 "\\&\n"
3688 " /* Discover the sizes of the structures that are used to receive\n"
3689 " notifications and send notification responses, and allocate\n"
3690 " buffers of those sizes. */\n"
3691 "\\&\n"
3692 " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n"
3693 " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n"
3694 "\\&\n"
3695 " *req = malloc(sizes-E<gt>seccomp_notif);\n"
3696 " if (*req == NULL)\n"
3697 " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n"
3698 "\\&\n"
3699 " /* When allocating the response buffer, we must allow for the fact\n"
3700 " that the user-space binary may have been built with user-space\n"
3701 " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n"
3702 " response buffer expected by the (older) kernel. Therefore, we\n"
3703 " allocate a buffer that is the maximum of the two sizes. This\n"
3704 " ensures that if the supervisor places bytes into the response\n"
3705 " structure that are past the response size that the kernel expects,\n"
3706 " then the supervisor is not touching an invalid memory location. */\n"
3707 "\\&\n"
3708 " resp_size = sizes-E<gt>seccomp_notif_resp;\n"
3709 " if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n"
3710 " resp_size = sizeof(struct seccomp_notif_resp);\n"
3711 "\\&\n"
3712 " *resp = malloc(resp_size);\n"
3713 " if (*resp == NULL)\n"
3714 " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n"
3715 "\\&\n"
3716 "}\n"
3717 "\\&\n"
3718 "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n"
3719 " descriptor, \\[aq]notifyFd\\[aq]. */\n"
3720 "\\&\n"
3721 "static void\n"
3722 "handleNotifications(int notifyFd)\n"
3723 "{\n"
3724 " bool pathOK;\n"
3725 " char path[PATH_MAX];\n"
3726 " struct seccomp_notif *req;\n"
3727 " struct seccomp_notif_resp *resp;\n"
3728 " struct seccomp_notif_sizes sizes;\n"
3729 "\\&\n"
3730 " allocSeccompNotifBuffers(&req, &resp, &sizes);\n"
3731 "\\&\n"
3732 " /* Loop handling notifications */\n"
3733 "\\&\n"
3734 " for (;;) {\n"
3735 "\\&\n"
3736 " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n"
3737 "\\&\n"
3738 " memset(req, 0, sizes.seccomp_notif);\n"
3739 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n"
3740 " if (errno == EINTR)\n"
3741 " continue;\n"
3742 " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n"
3743 " }\n"
3744 "\\&\n"
3745 " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n"
3746 " req-E<gt>id, req-E<gt>pid);\n"
3747 "\\&\n"
3748 " /* The only system call that can generate a notification event\n"
3749 " is mkdir(2). Nevertheless, we check that the notified system\n"
3750 " call is indeed mkdir() as kind of future-proofing of this\n"
3751 " code in case the seccomp filter is later modified to\n"
3752 " generate notifications for other system calls. */\n"
3753 "\\&\n"
3754 " if (req-E<gt>data.nr != SYS_mkdir) {\n"
3755 " printf(\"\\[rs]tS: notification contained unexpected \"\n"
3756 " \"system call number; bye!!!\\[rs]n\");\n"
3757 " exit(EXIT_FAILURE);\n"
3758 " }\n"
3759 "\\&\n"
3760 " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n"
3761 "\\&\n"
3762 " /* Prepopulate some fields of the response */\n"
3763 "\\&\n"
3764 " resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n"
3765 " resp-E<gt>flags = 0;\n"
3766 " resp-E<gt>val = 0;\n"
3767 "\\&\n"
3768 " /* If getTargetPathname() failed, trigger an EINVAL error\n"
3769 " response (sending this response may yield an error if the\n"
3770 " failure occurred because the notification ID was no longer\n"
3771 " valid); if the directory is in /tmp, then create it on behalf\n"
3772 " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n"
3773 " kernel to let the target process execute the mkdir();\n"
3774 " otherwise, give an error for a directory pathname in any other\n"
3775 " location. */\n"
3776 "\\&\n"
3777 " if (!pathOK) {\n"
3778 " resp-E<gt>error = -EINVAL;\n"
3779 " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n"
3780 " strerror(-resp-E<gt>error));\n"
3781 " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n"
3782 " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n"
3783 " path, req-E<gt>data.args[1]);\n"
3784 "\\&\n"
3785 " if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n"
3786 " resp-E<gt>error = 0; /* \"Success\" */\n"
3787 " resp-E<gt>val = strlen(path); /* Used as return value of\n"
3788 " mkdir() in target */\n"
3789 " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n"
3790 " resp-E<gt>val);\n"
3791 " } else {\n"
3792 "\\&\n"
3793 " /* If mkdir() failed in the supervisor, pass the error\n"
3794 " back to the target */\n"
3795 "\\&\n"
3796 " resp-E<gt>error = -errno;\n"
3797 " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n"
3798 " strerror(errno));\n"
3799 " }\n"
3800 " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n"
3801 " resp-E<gt>error = resp-E<gt>val = 0;\n"
3802 " resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n"
3803 " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n"
3804 " } else {\n"
3805 " resp-E<gt>error = -EOPNOTSUPP;\n"
3806 " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n"
3807 " strerror(-resp-E<gt>error));\n"
3808 " }\n"
3809 "\\&\n"
3810 " /* Send a response to the notification */\n"
3811 "\\&\n"
3812 " printf(\"\\[rs]tS: sending response \"\n"
3813 " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n"
3814 " resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n"
3815 "\\&\n"
3816 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n"
3817 " if (errno == ENOENT)\n"
3818 " printf(\"\\[rs]tS: response failed with ENOENT; \"\n"
3819 " \"perhaps target process\\[aq]s syscall was \"\n"
3820 " \"interrupted by a signal?\\[rs]n\");\n"
3821 " else\n"
3822 " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n"
3823 " }\n"
3824 "\\&\n"
3825 " /* If the pathname is just \"/bye\", then the supervisor breaks out\n"
3826 " of the loop and terminates. This allows us to see what happens\n"
3827 " if the target process makes further calls to mkdir(2). */\n"
3828 "\\&\n"
3829 " if (strcmp(path, \"/bye\") == 0)\n"
3830 " break;\n"
3831 " }\n"
3832 "\\&\n"
3833 " free(req);\n"
3834 " free(resp);\n"
3835 " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n"
3836 " exit(EXIT_FAILURE);\n"
3837 "}\n"
3838 "\\&\n"
3839 "/* Implementation of the supervisor process:\n"
3840 "\\&\n"
3841 " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n"
3842 " (2) handles notifications that arrive on that file descriptor. */\n"
3843 "\\&\n"
3844 "static void\n"
3845 "supervisor(int sockPair[2])\n"
3846 "{\n"
3847 " int notifyFd;\n"
3848 "\\&\n"
3849 " notifyFd = recvfd(sockPair[1]);\n"
3850 "\\&\n"
3851 " if (notifyFd == -1)\n"
3852 " err(EXIT_FAILURE, \"recvfd\");\n"
3853 "\\&\n"
3854 " closeSocketPair(sockPair); /* We no longer need the socket pair */\n"
3855 "\\&\n"
3856 " handleNotifications(notifyFd);\n"
3857 "}\n"
3858 "\\&\n"
3859 "int\n"
3860 "main(int argc, char *argv[])\n"
3861 "{\n"
3862 " int sockPair[2];\n"
3863 " struct sigaction sa;\n"
3864 "\\&\n"
3865 " setbuf(stdout, NULL);\n"
3866 "\\&\n"
3867 " if (argc E<lt> 2) {\n"
3868 " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n"
3869 " exit(EXIT_FAILURE);\n"
3870 " }\n"
3871 "\\&\n"
3872 " /* Create a UNIX domain socket that is used to pass the seccomp\n"
3873 " notification file descriptor from the target process to the\n"
3874 " supervisor process. */\n"
3875 "\\&\n"
3876 " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n"
3877 " err(EXIT_FAILURE, \"socketpair\");\n"
3878 "\\&\n"
3879 " /* Create a child process--the \"target\"--that installs seccomp\n"
3880 " filtering. The target process writes the seccomp notification\n"
3881 " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n"
3882 " each directory in the command-line arguments. */\n"
3883 "\\&\n"
3884 " (void) targetProcess(sockPair, &argv[optind]);\n"
3885 "\\&\n"
3886 " /* Catch SIGCHLD when the target terminates, so that the\n"
3887 " supervisor can also terminate. */\n"
3888 "\\&\n"
3889 " sa.sa_handler = sigchldHandler;\n"
3890 " sa.sa_flags = 0;\n"
3891 " sigemptyset(&sa.sa_mask);\n"
3892 " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n"
3893 " err(EXIT_FAILURE, \"sigaction\");\n"
3894 "\\&\n"
3895 " supervisor(sockPair);\n"
3896 "\\&\n"
3897 " exit(EXIT_SUCCESS);\n"
3898 "}\n"
3899 msgstr ""
3900
3901 #. type: TH
3902 #: fedora-44 fedora-rawhide
3903 #, no-wrap
3904 msgid "2024-11-17"
3905 msgstr ""
3906
3907 #. type: TH
3908 #: fedora-44 fedora-rawhide
3909 #, no-wrap
3910 msgid "Linux man-pages 6.13"
3911 msgstr ""
3912
3913 #. type: Plain text
3914 #: fedora-44 fedora-rawhide
3915 #, no-wrap
3916 msgid ""
3917 "#define _GNU_SOURCE\n"
3918 "#include E<lt>err.hE<gt>\n"
3919 "#include E<lt>errno.hE<gt>\n"
3920 "#include E<lt>fcntl.hE<gt>\n"
3921 "#include E<lt>limits.hE<gt>\n"
3922 "#include E<lt>linux/audit.hE<gt>\n"
3923 "#include E<lt>linux/filter.hE<gt>\n"
3924 "#include E<lt>linux/seccomp.hE<gt>\n"
3925 "#include E<lt>signal.hE<gt>\n"
3926 "#include E<lt>stdbool.hE<gt>\n"
3927 "#include E<lt>stddef.hE<gt>\n"
3928 "#include E<lt>stdint.hE<gt>\n"
3929 "#include E<lt>stdio.hE<gt>\n"
3930 "#include E<lt>stdlib.hE<gt>\n"
3931 "#include E<lt>string.hE<gt>\n"
3932 "#include E<lt>sys/ioctl.hE<gt>\n"
3933 "#include E<lt>sys/prctl.hE<gt>\n"
3934 "#include E<lt>sys/socket.hE<gt>\n"
3935 "#include E<lt>sys/stat.hE<gt>\n"
3936 "#include E<lt>sys/syscall.hE<gt>\n"
3937 "#include E<lt>sys/types.hE<gt>\n"
3938 "#include E<lt>sys/un.hE<gt>\n"
3939 "#include E<lt>unistd.hE<gt>\n"
3940 "\\&\n"
3941 "#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n"
3942 "\\&\n"
3943 "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n"
3944 " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n"
3945 "\\&\n"
3946 "static int\n"
3947 "sendfd(int sockfd, int fd)\n"
3948 "{\n"
3949 " int data;\n"
3950 " struct iovec iov;\n"
3951 " struct msghdr msgh;\n"
3952 " struct cmsghdr *cmsgp;\n"
3953 "\\&\n"
3954 " /* Allocate a char array of suitable size to hold the ancillary data.\n"
3955 " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n"
3956 " union to ensure that it is suitably aligned. */\n"
3957 " union {\n"
3958 " char buf[CMSG_SPACE(sizeof(int))];\n"
3959 " /* Space large enough to hold an \\[aq]int\\[aq] */\n"
3960 " struct cmsghdr align;\n"
3961 " } controlMsg;\n"
3962 "\\&\n"
3963 " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n"
3964 " destination socket when sending a datagram. However, we do not\n"
3965 " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n"
3966 "\\&\n"
3967 " msgh.msg_name = NULL;\n"
3968 " msgh.msg_namelen = 0;\n"
3969 "\\&\n"
3970 " /* On Linux, we must transmit at least one byte of real data in\n"
3971 " order to send ancillary data. We transmit an arbitrary integer\n"
3972 " whose value is ignored by recvfd(). */\n"
3973 "\\&\n"
3974 " msgh.msg_iov = &iov;\n"
3975 " msgh.msg_iovlen = 1;\n"
3976 " iov.iov_base = &data;\n"
3977 " iov.iov_len = sizeof(int);\n"
3978 " data = 12345;\n"
3979 "\\&\n"
3980 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
3981 "\\&\n"
3982 " msgh.msg_control = controlMsg.buf;\n"
3983 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
3984 "\\&\n"
3985 " /* Set up ancillary data describing file descriptor to send */\n"
3986 "\\&\n"
3987 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
3988 " cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n"
3989 " cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n"
3990 " cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n"
3991 " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n"
3992 "\\&\n"
3993 " /* Send real plus ancillary data */\n"
3994 "\\&\n"
3995 " if (sendmsg(sockfd, &msgh, 0) == -1)\n"
3996 " return -1;\n"
3997 "\\&\n"
3998 " return 0;\n"
3999 "}\n"
4000 "\\&\n"
4001 "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n"
4002 " the received file descriptor on success, or -1 on error. */\n"
4003 "\\&\n"
4004 "static int\n"
4005 "recvfd(int sockfd)\n"
4006 "{\n"
4007 " int data, fd;\n"
4008 " ssize_t nr;\n"
4009 " struct iovec iov;\n"
4010 " struct msghdr msgh;\n"
4011 "\\&\n"
4012 " /* Allocate a char buffer for the ancillary data. See the comments\n"
4013 " in sendfd() */\n"
4014 " union {\n"
4015 " char buf[CMSG_SPACE(sizeof(int))];\n"
4016 " struct cmsghdr align;\n"
4017 " } controlMsg;\n"
4018 " struct cmsghdr *cmsgp;\n"
4019 "\\&\n"
4020 " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n"
4021 " sending socket. However, we do not need this information. */\n"
4022 "\\&\n"
4023 " msgh.msg_name = NULL;\n"
4024 " msgh.msg_namelen = 0;\n"
4025 "\\&\n"
4026 " /* Specify buffer for receiving real data */\n"
4027 "\\&\n"
4028 " msgh.msg_iov = &iov;\n"
4029 " msgh.msg_iovlen = 1;\n"
4030 " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n"
4031 " iov.iov_len = sizeof(int);\n"
4032 "\\&\n"
4033 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
4034 "\\&\n"
4035 " msgh.msg_control = controlMsg.buf;\n"
4036 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
4037 "\\&\n"
4038 " /* Receive real plus ancillary data; real data is ignored */\n"
4039 "\\&\n"
4040 " nr = recvmsg(sockfd, &msgh, 0);\n"
4041 " if (nr == -1)\n"
4042 " return -1;\n"
4043 "\\&\n"
4044 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
4045 "\\&\n"
4046 " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n"
4047 "\\&\n"
4048 " if (cmsgp == NULL\n"
4049 " || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n"
4050 " || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n"
4051 " || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n"
4052 " {\n"
4053 " errno = EINVAL;\n"
4054 " return -1;\n"
4055 " }\n"
4056 "\\&\n"
4057 " /* Return the received file descriptor to our caller */\n"
4058 "\\&\n"
4059 " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n"
4060 " return fd;\n"
4061 "}\n"
4062 "\\&\n"
4063 "static void\n"
4064 "sigchldHandler(int sig)\n"
4065 "{\n"
4066 " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n"
4067 "\\&\n"
4068 " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n"
4069 " _exit(EXIT_SUCCESS);\n"
4070 "}\n"
4071 "\\&\n"
4072 "static int\n"
4073 "seccomp(unsigned int operation, unsigned int flags, void *args)\n"
4074 "{\n"
4075 " return syscall(SYS_seccomp, operation, flags, args);\n"
4076 "}\n"
4077 "\\&\n"
4078 "/* The following is the x86-64-specific BPF boilerplate code for checking\n"
4079 " that the BPF program is running on the right architecture + ABI. At\n"
4080 " completion of these instructions, the accumulator contains the system\n"
4081 " call number. */\n"
4082 "\\&\n"
4083 "/* For the x32 ABI, all system call numbers have bit 30 set */\n"
4084 "\\&\n"
4085 "#define X32_SYSCALL_BIT 0x40000000\n"
4086 "\\&\n"
4087 "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n"
4088 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
4089 " (offsetof(struct seccomp_data, arch))), \\[rs]\n"
4090 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n"
4091 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
4092 " (offsetof(struct seccomp_data, nr))), \\[rs]\n"
4093 " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n"
4094 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n"
4095 "\\&\n"
4096 "/* installNotifyFilter() installs a seccomp filter that generates\n"
4097 " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n"
4098 " calls mkdir(2); the filter allows all other system calls.\n"
4099 "\\&\n"
4100 " The function return value is a file descriptor from which the\n"
4101 " user-space notifications can be fetched. */\n"
4102 "\\&\n"
4103 "static int\n"
4104 "installNotifyFilter(void)\n"
4105 "{\n"
4106 " int notifyFd;\n"
4107 "\\&\n"
4108 " struct sock_filter filter[] = {\n"
4109 " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n"
4110 "\\&\n"
4111 " /* mkdir() triggers notification to user-space supervisor */\n"
4112 "\\&\n"
4113 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n"
4114 " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n"
4115 "\\&\n"
4116 " /* Every other system call is allowed */\n"
4117 "\\&\n"
4118 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n"
4119 " };\n"
4120 "\\&\n"
4121 " struct sock_fprog prog = {\n"
4122 " .len = ARRAY_SIZE(filter),\n"
4123 " .filter = filter,\n"
4124 " };\n"
4125 "\\&\n"
4126 " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
4127 " as a result, seccomp() returns a notification file descriptor. */\n"
4128 "\\&\n"
4129 " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n"
4130 " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n"
4131 " if (notifyFd == -1)\n"
4132 " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n"
4133 "\\&\n"
4134 " return notifyFd;\n"
4135 "}\n"
4136 "\\&\n"
4137 "/* Close a pair of sockets created by socketpair() */\n"
4138 "\\&\n"
4139 "static void\n"
4140 "closeSocketPair(int sockPair[2])\n"
4141 "{\n"
4142 " if (close(sockPair[0]) == -1)\n"
4143 " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n"
4144 " if (close(sockPair[1]) == -1)\n"
4145 " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n"
4146 "}\n"
4147 "\\&\n"
4148 "/* Implementation of the target process; create a child process that:\n"
4149 "\\&\n"
4150 " (1) installs a seccomp filter with the\n"
4151 " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
4152 " (2) writes the seccomp notification file descriptor returned from\n"
4153 " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n"
4154 " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n"
4155 "\\&\n"
4156 " The function return value in the parent is the PID of the child\n"
4157 " process; the child does not return from this function. */\n"
4158 "\\&\n"
4159 "static pid_t\n"
4160 "targetProcess(int sockPair[2], char *argv[])\n"
4161 "{\n"
4162 " int notifyFd, s;\n"
4163 " pid_t targetPid;\n"
4164 "\\&\n"
4165 " targetPid = fork();\n"
4166 "\\&\n"
4167 " if (targetPid == -1)\n"
4168 " err(EXIT_FAILURE, \"fork\");\n"
4169 "\\&\n"
4170 " if (targetPid E<gt> 0) /* In parent, return PID of child */\n"
4171 " return targetPid;\n"
4172 "\\&\n"
4173 " /* Child falls through to here */\n"
4174 "\\&\n"
4175 " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n"
4176 "\\&\n"
4177 " /* Install seccomp filter(s) */\n"
4178 "\\&\n"
4179 " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n"
4180 " err(EXIT_FAILURE, \"prctl\");\n"
4181 "\\&\n"
4182 " notifyFd = installNotifyFilter();\n"
4183 "\\&\n"
4184 " /* Pass the notification file descriptor to the tracing process over\n"
4185 " a UNIX domain socket */\n"
4186 "\\&\n"
4187 " if (sendfd(sockPair[0], notifyFd) == -1)\n"
4188 " err(EXIT_FAILURE, \"sendfd\");\n"
4189 "\\&\n"
4190 " /* Notification and socket FDs are no longer needed in target */\n"
4191 "\\&\n"
4192 " if (close(notifyFd) == -1)\n"
4193 " err(EXIT_FAILURE, \"close-target-notify-fd\");\n"
4194 "\\&\n"
4195 " closeSocketPair(sockPair);\n"
4196 "\\&\n"
4197 " /* Perform a mkdir() call for each of the command-line arguments */\n"
4198 "\\&\n"
4199 " for (char **ap = argv; *ap != NULL; ap++) {\n"
4200 " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n"
4201 "\\&\n"
4202 " s = mkdir(*ap, 0700);\n"
4203 " if (s == -1)\n"
4204 " perror(\"T: ERROR: mkdir(2)\");\n"
4205 " else\n"
4206 " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n"
4207 " }\n"
4208 "\\&\n"
4209 " printf(\"\\[rs]nT: terminating\\[rs]n\");\n"
4210 " exit(EXIT_SUCCESS);\n"
4211 "}\n"
4212 "\\&\n"
4213 "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n"
4214 " operation is still valid. It will no longer be valid if the target\n"
4215 " process has terminated or is no longer blocked in the system call that\n"
4216 " generated the notification (because it was interrupted by a signal).\n"
4217 "\\&\n"
4218 " This operation can be used when doing such things as accessing\n"
4219 " /proc/PID files in the target process in order to avoid TOCTOU race\n"
4220 " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n"
4221 " terminates and is reused by another process. */\n"
4222 "\\&\n"
4223 "static bool\n"
4224 "cookieIsValid(int notifyFd, uint64_t id)\n"
4225 "{\n"
4226 " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n"
4227 "}\n"
4228 "\\&\n"
4229 "/* Access the memory of the target process in order to fetch the\n"
4230 " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n"
4231 " \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n"
4232 " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n"
4233 "\\&\n"
4234 " Returns true if the pathname is successfully fetched, and false\n"
4235 " otherwise. For possible causes of failure, see the comments below. */\n"
4236 "\\&\n"
4237 "static bool\n"
4238 "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n"
4239 " int argNum, char *path, size_t size)\n"
4240 "{\n"
4241 " int procMemFd;\n"
4242 " char procMemPath[PATH_MAX];\n"
4243 " ssize_t nread;\n"
4244 "\\&\n"
4245 " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n"
4246 "\\&\n"
4247 " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n"
4248 " if (procMemFd == -1)\n"
4249 " return false;\n"
4250 "\\&\n"
4251 " /* Check that the process whose info we are accessing is still alive\n"
4252 " and blocked in the system call that caused the notification.\n"
4253 " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n"
4254 " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n"
4255 " descriptor that we opened corresponded to the process for which we\n"
4256 " received a notification. If that process subsequently terminates,\n"
4257 " then read() on that file descriptor will return 0 (EOF). */\n"
4258 "\\&\n"
4259 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
4260 " close(procMemFd);\n"
4261 " return false;\n"
4262 " }\n"
4263 "\\&\n"
4264 " /* Read bytes at the location containing the pathname argument */\n"
4265 "\\&\n"
4266 " nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n"
4267 "\\&\n"
4268 " close(procMemFd);\n"
4269 "\\&\n"
4270 " if (nread E<lt>= 0)\n"
4271 " return false;\n"
4272 "\\&\n"
4273 " /* Once again check that the notification ID is still valid. The\n"
4274 " case we are particularly concerned about here is that just\n"
4275 " before we fetched the pathname, the target\\[aq]s blocked system\n"
4276 " call was interrupted by a signal handler, and after the handler\n"
4277 " returned, the target carried on execution (past the interrupted\n"
4278 " system call). In that case, we have no guarantees about what we\n"
4279 " are reading, since the target\\[aq]s memory may have been arbitrarily\n"
4280 " changed by subsequent operations. */\n"
4281 "\\&\n"
4282 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
4283 " perror(\"\\[rs]tS: notification ID check failed!!!\");\n"
4284 " return false;\n"
4285 " }\n"
4286 "\\&\n"
4287 " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n"
4288 " we have no guarantees about what was in the memory of the target\n"
4289 " process. (The memory may have been modified by another thread, or\n"
4290 " even by an external attacking process.) We therefore treat the\n"
4291 " buffer returned by pread() as untrusted input. The buffer should\n"
4292 " contain a terminating null byte; if not, then we will trigger an\n"
4293 " error for the target process. */\n"
4294 "\\&\n"
4295 " if (strnlen(path, nread) E<lt> nread)\n"
4296 " return true;\n"
4297 "\\&\n"
4298 " return false;\n"
4299 "}\n"
4300 "\\&\n"
4301 "/* Allocate buffers for the seccomp user-space notification request and\n"
4302 " response structures. It is the caller\\[aq]s responsibility to free the\n"
4303 " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n"
4304 "\\&\n"
4305 "static void\n"
4306 "allocSeccompNotifBuffers(struct seccomp_notif **req,\n"
4307 " struct seccomp_notif_resp **resp,\n"
4308 " struct seccomp_notif_sizes *sizes)\n"
4309 "{\n"
4310 " size_t resp_size;\n"
4311 "\\&\n"
4312 " /* Discover the sizes of the structures that are used to receive\n"
4313 " notifications and send notification responses, and allocate\n"
4314 " buffers of those sizes. */\n"
4315 "\\&\n"
4316 " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n"
4317 " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n"
4318 "\\&\n"
4319 " *req = malloc(sizes-E<gt>seccomp_notif);\n"
4320 " if (*req == NULL)\n"
4321 " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n"
4322 "\\&\n"
4323 " /* When allocating the response buffer, we must allow for the fact\n"
4324 " that the user-space binary may have been built with user-space\n"
4325 " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n"
4326 " response buffer expected by the (older) kernel. Therefore, we\n"
4327 " allocate a buffer that is the maximum of the two sizes. This\n"
4328 " ensures that if the supervisor places bytes into the response\n"
4329 " structure that are past the response size that the kernel expects,\n"
4330 " then the supervisor is not touching an invalid memory location. */\n"
4331 "\\&\n"
4332 " resp_size = sizes-E<gt>seccomp_notif_resp;\n"
4333 " if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n"
4334 " resp_size = sizeof(struct seccomp_notif_resp);\n"
4335 "\\&\n"
4336 " *resp = malloc(resp_size);\n"
4337 " if (*resp == NULL)\n"
4338 " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n"
4339 "\\&\n"
4340 "}\n"
4341 "\\&\n"
4342 "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n"
4343 " descriptor, \\[aq]notifyFd\\[aq]. */\n"
4344 "\\&\n"
4345 "static void\n"
4346 "handleNotifications(int notifyFd)\n"
4347 "{\n"
4348 " bool pathOK;\n"
4349 " char path[PATH_MAX];\n"
4350 " struct seccomp_notif *req;\n"
4351 " struct seccomp_notif_resp *resp;\n"
4352 " struct seccomp_notif_sizes sizes;\n"
4353 "\\&\n"
4354 " allocSeccompNotifBuffers(&req, &resp, &sizes);\n"
4355 "\\&\n"
4356 " /* Loop handling notifications */\n"
4357 "\\&\n"
4358 " for (;;) {\n"
4359 "\\&\n"
4360 " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n"
4361 "\\&\n"
4362 " memset(req, 0, sizes.seccomp_notif);\n"
4363 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n"
4364 " if (errno == EINTR)\n"
4365 " continue;\n"
4366 " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n"
4367 " }\n"
4368 "\\&\n"
4369 " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n"
4370 " req-E<gt>id, req-E<gt>pid);\n"
4371 "\\&\n"
4372 " /* The only system call that can generate a notification event\n"
4373 " is mkdir(2). Nevertheless, we check that the notified system\n"
4374 " call is indeed mkdir() as kind of future-proofing of this\n"
4375 " code in case the seccomp filter is later modified to\n"
4376 " generate notifications for other system calls. */\n"
4377 "\\&\n"
4378 " if (req-E<gt>data.nr != SYS_mkdir) {\n"
4379 " printf(\"\\[rs]tS: notification contained unexpected \"\n"
4380 " \"system call number; bye!!!\\[rs]n\");\n"
4381 " exit(EXIT_FAILURE);\n"
4382 " }\n"
4383 "\\&\n"
4384 " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n"
4385 "\\&\n"
4386 " /* Prepopulate some fields of the response */\n"
4387 "\\&\n"
4388 " resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n"
4389 " resp-E<gt>flags = 0;\n"
4390 " resp-E<gt>val = 0;\n"
4391 "\\&\n"
4392 " /* If getTargetPathname() failed, trigger an EINVAL error\n"
4393 " response (sending this response may yield an error if the\n"
4394 " failure occurred because the notification ID was no longer\n"
4395 " valid); if the directory is in /tmp, then create it on behalf\n"
4396 " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n"
4397 " kernel to let the target process execute the mkdir();\n"
4398 " otherwise, give an error for a directory pathname in any other\n"
4399 " location. */\n"
4400 "\\&\n"
4401 " if (!pathOK) {\n"
4402 " resp-E<gt>error = -EINVAL;\n"
4403 " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n"
4404 " strerror(-resp-E<gt>error));\n"
4405 " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n"
4406 " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n"
4407 " path, req-E<gt>data.args[1]);\n"
4408 "\\&\n"
4409 " if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n"
4410 " resp-E<gt>error = 0; /* \"Success\" */\n"
4411 " resp-E<gt>val = strlen(path); /* Used as return value of\n"
4412 " mkdir() in target */\n"
4413 " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n"
4414 " resp-E<gt>val);\n"
4415 " } else {\n"
4416 "\\&\n"
4417 " /* If mkdir() failed in the supervisor, pass the error\n"
4418 " back to the target */\n"
4419 "\\&\n"
4420 " resp-E<gt>error = -errno;\n"
4421 " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n"
4422 " strerror(errno));\n"
4423 " }\n"
4424 " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n"
4425 " resp-E<gt>error = resp-E<gt>val = 0;\n"
4426 " resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n"
4427 " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n"
4428 " } else {\n"
4429 " resp-E<gt>error = -EOPNOTSUPP;\n"
4430 " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n"
4431 " strerror(-resp-E<gt>error));\n"
4432 " }\n"
4433 "\\&\n"
4434 " /* Send a response to the notification */\n"
4435 "\\&\n"
4436 " printf(\"\\[rs]tS: sending response \"\n"
4437 " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n"
4438 " resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n"
4439 "\\&\n"
4440 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n"
4441 " if (errno == ENOENT)\n"
4442 " printf(\"\\[rs]tS: response failed with ENOENT; \"\n"
4443 " \"perhaps target process\\[aq]s syscall was \"\n"
4444 " \"interrupted by a signal?\\[rs]n\");\n"
4445 " else\n"
4446 " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n"
4447 " }\n"
4448 "\\&\n"
4449 " /* If the pathname is just \"/bye\", then the supervisor breaks out\n"
4450 " of the loop and terminates. This allows us to see what happens\n"
4451 " if the target process makes further calls to mkdir(2). */\n"
4452 "\\&\n"
4453 " if (strcmp(path, \"/bye\") == 0)\n"
4454 " break;\n"
4455 " }\n"
4456 "\\&\n"
4457 " free(req);\n"
4458 " free(resp);\n"
4459 " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n"
4460 " exit(EXIT_FAILURE);\n"
4461 "}\n"
4462 "\\&\n"
4463 "/* Implementation of the supervisor process:\n"
4464 "\\&\n"
4465 " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n"
4466 " (2) handles notifications that arrive on that file descriptor. */\n"
4467 "\\&\n"
4468 "static void\n"
4469 "supervisor(int sockPair[2])\n"
4470 "{\n"
4471 " int notifyFd;\n"
4472 "\\&\n"
4473 " notifyFd = recvfd(sockPair[1]);\n"
4474 "\\&\n"
4475 " if (notifyFd == -1)\n"
4476 " err(EXIT_FAILURE, \"recvfd\");\n"
4477 "\\&\n"
4478 " closeSocketPair(sockPair); /* We no longer need the socket pair */\n"
4479 "\\&\n"
4480 " handleNotifications(notifyFd);\n"
4481 "}\n"
4482 "\\&\n"
4483 "int\n"
4484 "main(int argc, char *argv[])\n"
4485 "{\n"
4486 " int sockPair[2];\n"
4487 " struct sigaction sa;\n"
4488 "\\&\n"
4489 " setbuf(stdout, NULL);\n"
4490 "\\&\n"
4491 " if (argc E<lt> 2) {\n"
4492 " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n"
4493 " exit(EXIT_FAILURE);\n"
4494 " }\n"
4495 "\\&\n"
4496 " /* Create a UNIX domain socket that is used to pass the seccomp\n"
4497 " notification file descriptor from the target process to the\n"
4498 " supervisor process. */\n"
4499 "\\&\n"
4500 " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n"
4501 " err(EXIT_FAILURE, \"socketpair\");\n"
4502 "\\&\n"
4503 " /* Create a child process--the \"target\"--that installs seccomp\n"
4504 " filtering. The target process writes the seccomp notification\n"
4505 " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n"
4506 " each directory in the command-line arguments. */\n"
4507 "\\&\n"
4508 " (void) targetProcess(sockPair, &argv[optind]);\n"
4509 "\\&\n"
4510 " /* Catch SIGCHLD when the target terminates, so that the\n"
4511 " supervisor can also terminate. */\n"
4512 "\\&\n"
4513 " sa.sa_handler = sigchldHandler;\n"
4514 " sa.sa_flags = 0;\n"
4515 " sigemptyset(&sa.sa_mask);\n"
4516 " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n"
4517 " err(EXIT_FAILURE, \"sigaction\");\n"
4518 "\\&\n"
4519 " supervisor(sockPair);\n"
4520 "\\&\n"
4521 " exit(EXIT_SUCCESS);\n"
4522 "}\n"
4523 msgstr ""
4524
4525 #. type: TH
4526 #: mageia-cauldron
4527 #, no-wrap
4528 msgid "2026-02-10"
4529 msgstr ""
4530
4531 #. type: TH
4532 #: mageia-cauldron
4533 #, no-wrap
4534 msgid "Linux man-pages 6.17"
4535 msgstr ""
4536
4537 #. type: Plain text
4538 #: mageia-cauldron
4539 #, no-wrap
4540 msgid ""
4541 "#define _GNU_SOURCE\n"
4542 "#include E<lt>err.hE<gt>\n"
4543 "#include E<lt>errno.hE<gt>\n"
4544 "#include E<lt>fcntl.hE<gt>\n"
4545 "#include E<lt>limits.hE<gt>\n"
4546 "#include E<lt>linux/audit.hE<gt>\n"
4547 "#include E<lt>linux/filter.hE<gt>\n"
4548 "#include E<lt>linux/seccomp.hE<gt>\n"
4549 "#include E<lt>signal.hE<gt>\n"
4550 "#include E<lt>stdbool.hE<gt>\n"
4551 "#include E<lt>stdcountof.hE<gt>\n"
4552 "#include E<lt>stddef.hE<gt>\n"
4553 "#include E<lt>stdint.hE<gt>\n"
4554 "#include E<lt>stdio.hE<gt>\n"
4555 "#include E<lt>stdlib.hE<gt>\n"
4556 "#include E<lt>string.hE<gt>\n"
4557 "#include E<lt>sys/ioctl.hE<gt>\n"
4558 "#include E<lt>sys/prctl.hE<gt>\n"
4559 "#include E<lt>sys/socket.hE<gt>\n"
4560 "#include E<lt>sys/stat.hE<gt>\n"
4561 "#include E<lt>sys/syscall.hE<gt>\n"
4562 "#include E<lt>sys/types.hE<gt>\n"
4563 "#include E<lt>sys/un.hE<gt>\n"
4564 "#include E<lt>unistd.hE<gt>\n"
4565 "\\&\n"
4566 "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n"
4567 " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n"
4568 "\\&\n"
4569 "static int\n"
4570 "sendfd(int sockfd, int fd)\n"
4571 "{\n"
4572 " int data;\n"
4573 " struct iovec iov;\n"
4574 " struct msghdr msgh;\n"
4575 " struct cmsghdr *cmsgp;\n"
4576 "\\&\n"
4577 " /* Allocate a char array of suitable size to hold the ancillary data.\n"
4578 " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n"
4579 " union to ensure that it is suitably aligned. */\n"
4580 " union {\n"
4581 " char buf[CMSG_SPACE(sizeof(int))];\n"
4582 " /* Space large enough to hold an \\[aq]int\\[aq] */\n"
4583 " struct cmsghdr align;\n"
4584 " } controlMsg;\n"
4585 "\\&\n"
4586 " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n"
4587 " destination socket when sending a datagram. However, we do not\n"
4588 " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n"
4589 "\\&\n"
4590 " msgh.msg_name = NULL;\n"
4591 " msgh.msg_namelen = 0;\n"
4592 "\\&\n"
4593 " /* On Linux, we must transmit at least one byte of real data in\n"
4594 " order to send ancillary data. We transmit an arbitrary integer\n"
4595 " whose value is ignored by recvfd(). */\n"
4596 "\\&\n"
4597 " msgh.msg_iov = &iov;\n"
4598 " msgh.msg_iovlen = 1;\n"
4599 " iov.iov_base = &data;\n"
4600 " iov.iov_len = sizeof(int);\n"
4601 " data = 12345;\n"
4602 "\\&\n"
4603 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
4604 "\\&\n"
4605 " msgh.msg_control = controlMsg.buf;\n"
4606 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
4607 "\\&\n"
4608 " /* Set up ancillary data describing file descriptor to send */\n"
4609 "\\&\n"
4610 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
4611 " cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n"
4612 " cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n"
4613 " cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n"
4614 " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n"
4615 "\\&\n"
4616 " /* Send real plus ancillary data */\n"
4617 "\\&\n"
4618 " if (sendmsg(sockfd, &msgh, 0) == -1)\n"
4619 " return -1;\n"
4620 "\\&\n"
4621 " return 0;\n"
4622 "}\n"
4623 "\\&\n"
4624 "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n"
4625 " the received file descriptor on success, or -1 on error. */\n"
4626 "\\&\n"
4627 "static int\n"
4628 "recvfd(int sockfd)\n"
4629 "{\n"
4630 " int data, fd;\n"
4631 " ssize_t nr;\n"
4632 " struct iovec iov;\n"
4633 " struct msghdr msgh;\n"
4634 "\\&\n"
4635 " /* Allocate a char buffer for the ancillary data. See the comments\n"
4636 " in sendfd() */\n"
4637 " union {\n"
4638 " char buf[CMSG_SPACE(sizeof(int))];\n"
4639 " struct cmsghdr align;\n"
4640 " } controlMsg;\n"
4641 " struct cmsghdr *cmsgp;\n"
4642 "\\&\n"
4643 " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n"
4644 " sending socket. However, we do not need this information. */\n"
4645 "\\&\n"
4646 " msgh.msg_name = NULL;\n"
4647 " msgh.msg_namelen = 0;\n"
4648 "\\&\n"
4649 " /* Specify buffer for receiving real data */\n"
4650 "\\&\n"
4651 " msgh.msg_iov = &iov;\n"
4652 " msgh.msg_iovlen = 1;\n"
4653 " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n"
4654 " iov.iov_len = sizeof(int);\n"
4655 "\\&\n"
4656 " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n"
4657 "\\&\n"
4658 " msgh.msg_control = controlMsg.buf;\n"
4659 " msgh.msg_controllen = sizeof(controlMsg.buf);\n"
4660 "\\&\n"
4661 " /* Receive real plus ancillary data; real data is ignored */\n"
4662 "\\&\n"
4663 " nr = recvmsg(sockfd, &msgh, 0);\n"
4664 " if (nr == -1)\n"
4665 " return -1;\n"
4666 "\\&\n"
4667 " cmsgp = CMSG_FIRSTHDR(&msgh);\n"
4668 "\\&\n"
4669 " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n"
4670 "\\&\n"
4671 " if (cmsgp == NULL\n"
4672 " || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n"
4673 " || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n"
4674 " || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n"
4675 " {\n"
4676 " errno = EINVAL;\n"
4677 " return -1;\n"
4678 " }\n"
4679 "\\&\n"
4680 " /* Return the received file descriptor to our caller */\n"
4681 "\\&\n"
4682 " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n"
4683 " return fd;\n"
4684 "}\n"
4685 "\\&\n"
4686 "static void\n"
4687 "sigchldHandler(int sig)\n"
4688 "{\n"
4689 " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n"
4690 "\\&\n"
4691 " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n"
4692 " _exit(EXIT_SUCCESS);\n"
4693 "}\n"
4694 "\\&\n"
4695 "static int\n"
4696 "seccomp(unsigned int operation, unsigned int flags, void *args)\n"
4697 "{\n"
4698 " return syscall(SYS_seccomp, operation, flags, args);\n"
4699 "}\n"
4700 "\\&\n"
4701 "/* The following is the x86-64-specific BPF boilerplate code for checking\n"
4702 " that the BPF program is running on the right architecture + ABI. At\n"
4703 " completion of these instructions, the accumulator contains the system\n"
4704 " call number. */\n"
4705 "\\&\n"
4706 "/* For the x32 ABI, all system call numbers have bit 30 set */\n"
4707 "\\&\n"
4708 "#define X32_SYSCALL_BIT 0x40000000\n"
4709 "\\&\n"
4710 "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n"
4711 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
4712 " (offsetof(struct seccomp_data, arch))), \\[rs]\n"
4713 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n"
4714 " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n"
4715 " (offsetof(struct seccomp_data, nr))), \\[rs]\n"
4716 " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n"
4717 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n"
4718 "\\&\n"
4719 "/* installNotifyFilter() installs a seccomp filter that generates\n"
4720 " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n"
4721 " calls mkdir(2); the filter allows all other system calls.\n"
4722 "\\&\n"
4723 " The function return value is a file descriptor from which the\n"
4724 " user-space notifications can be fetched. */\n"
4725 "\\&\n"
4726 "static int\n"
4727 "installNotifyFilter(void)\n"
4728 "{\n"
4729 " int notifyFd;\n"
4730 "\\&\n"
4731 " struct sock_filter filter[] = {\n"
4732 " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n"
4733 "\\&\n"
4734 " /* mkdir() triggers notification to user-space supervisor */\n"
4735 "\\&\n"
4736 " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n"
4737 " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n"
4738 "\\&\n"
4739 " /* Every other system call is allowed */\n"
4740 "\\&\n"
4741 " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n"
4742 " };\n"
4743 "\\&\n"
4744 " struct sock_fprog prog = {\n"
4745 " .len = countof(filter),\n"
4746 " .filter = filter,\n"
4747 " };\n"
4748 "\\&\n"
4749 " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
4750 " as a result, seccomp() returns a notification file descriptor. */\n"
4751 "\\&\n"
4752 " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n"
4753 " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n"
4754 " if (notifyFd == -1)\n"
4755 " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n"
4756 "\\&\n"
4757 " return notifyFd;\n"
4758 "}\n"
4759 "\\&\n"
4760 "/* Close a pair of sockets created by socketpair() */\n"
4761 "\\&\n"
4762 "static void\n"
4763 "closeSocketPair(int sockPair[2])\n"
4764 "{\n"
4765 " if (close(sockPair[0]) == -1)\n"
4766 " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n"
4767 " if (close(sockPair[1]) == -1)\n"
4768 " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n"
4769 "}\n"
4770 "\\&\n"
4771 "/* Implementation of the target process. Create a child process that:\n"
4772 "\\&\n"
4773 " (1) installs a seccomp filter with the\n"
4774 " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n"
4775 " (2) writes the seccomp notification file descriptor returned from\n"
4776 " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n"
4777 " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n"
4778 "\\&\n"
4779 " The function return value in the parent is the PID of the child\n"
4780 " process; the child does not return from this function. */\n"
4781 "\\&\n"
4782 "static pid_t\n"
4783 "targetProcess(int sockPair[2], char *argv[])\n"
4784 "{\n"
4785 " int notifyFd, s;\n"
4786 " pid_t targetPid;\n"
4787 "\\&\n"
4788 " targetPid = fork();\n"
4789 "\\&\n"
4790 " if (targetPid == -1)\n"
4791 " err(EXIT_FAILURE, \"fork\");\n"
4792 "\\&\n"
4793 " if (targetPid E<gt> 0) /* In parent, return PID of child */\n"
4794 " return targetPid;\n"
4795 "\\&\n"
4796 " /* Child falls through to here */\n"
4797 "\\&\n"
4798 " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n"
4799 "\\&\n"
4800 " /* Install seccomp filter(s) */\n"
4801 "\\&\n"
4802 " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n"
4803 " err(EXIT_FAILURE, \"prctl\");\n"
4804 "\\&\n"
4805 " notifyFd = installNotifyFilter();\n"
4806 "\\&\n"
4807 " /* Pass the notification file descriptor to the tracing process over\n"
4808 " a UNIX domain socket */\n"
4809 "\\&\n"
4810 " if (sendfd(sockPair[0], notifyFd) == -1)\n"
4811 " err(EXIT_FAILURE, \"sendfd\");\n"
4812 "\\&\n"
4813 " /* Notification and socket FDs are no longer needed in target */\n"
4814 "\\&\n"
4815 " if (close(notifyFd) == -1)\n"
4816 " err(EXIT_FAILURE, \"close-target-notify-fd\");\n"
4817 "\\&\n"
4818 " closeSocketPair(sockPair);\n"
4819 "\\&\n"
4820 " /* Perform a mkdir() call for each of the command-line arguments */\n"
4821 "\\&\n"
4822 " for (char **ap = argv; *ap != NULL; ap++) {\n"
4823 " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n"
4824 "\\&\n"
4825 " s = mkdir(*ap, 0700);\n"
4826 " if (s == -1)\n"
4827 " perror(\"T: ERROR: mkdir(2)\");\n"
4828 " else\n"
4829 " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n"
4830 " }\n"
4831 "\\&\n"
4832 " printf(\"\\[rs]nT: terminating\\[rs]n\");\n"
4833 " exit(EXIT_SUCCESS);\n"
4834 "}\n"
4835 "\\&\n"
4836 "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n"
4837 " operation is still valid. It will no longer be valid if the target\n"
4838 " process has terminated or is no longer blocked in the system call that\n"
4839 " generated the notification (because it was interrupted by a signal).\n"
4840 "\\&\n"
4841 " This operation can be used when doing such things as accessing\n"
4842 " /proc/PID files in the target process in order to avoid TOCTOU race\n"
4843 " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n"
4844 " terminates and is reused by another process. */\n"
4845 "\\&\n"
4846 "static bool\n"
4847 "cookieIsValid(int notifyFd, uint64_t id)\n"
4848 "{\n"
4849 " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n"
4850 "}\n"
4851 "\\&\n"
4852 "/* Access the memory of the target process in order to fetch the\n"
4853 " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n"
4854 " \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n"
4855 " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n"
4856 "\\&\n"
4857 " Returns true if the pathname is successfully fetched, and false\n"
4858 " otherwise. For possible causes of failure, see the comments below. */\n"
4859 "\\&\n"
4860 "static bool\n"
4861 "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n"
4862 " int argNum, char *path, size_t size)\n"
4863 "{\n"
4864 " int procMemFd;\n"
4865 " char procMemPath[PATH_MAX];\n"
4866 " ssize_t nread;\n"
4867 "\\&\n"
4868 " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n"
4869 "\\&\n"
4870 " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n"
4871 " if (procMemFd == -1)\n"
4872 " return false;\n"
4873 "\\&\n"
4874 " /* Check that the process whose info we are accessing is still alive\n"
4875 " and blocked in the system call that caused the notification.\n"
4876 " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n"
4877 " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n"
4878 " descriptor that we opened corresponded to the process for which we\n"
4879 " received a notification. If that process subsequently terminates,\n"
4880 " then read() on that file descriptor will return 0 (EOF). */\n"
4881 "\\&\n"
4882 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
4883 " close(procMemFd);\n"
4884 " return false;\n"
4885 " }\n"
4886 "\\&\n"
4887 " /* Read bytes at the location containing the pathname argument */\n"
4888 "\\&\n"
4889 " nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n"
4890 "\\&\n"
4891 " close(procMemFd);\n"
4892 "\\&\n"
4893 " if (nread E<lt>= 0)\n"
4894 " return false;\n"
4895 "\\&\n"
4896 " /* Once again check that the notification ID is still valid. The\n"
4897 " case we are particularly concerned about here is that just\n"
4898 " before we fetched the pathname, the target\\[aq]s blocked system\n"
4899 " call was interrupted by a signal handler, and after the handler\n"
4900 " returned, the target carried on execution (past the interrupted\n"
4901 " system call). In that case, we have no guarantees about what we\n"
4902 " are reading, since the target\\[aq]s memory may have been arbitrarily\n"
4903 " changed by subsequent operations. */\n"
4904 "\\&\n"
4905 " if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n"
4906 " perror(\"\\[rs]tS: notification ID check failed!!!\");\n"
4907 " return false;\n"
4908 " }\n"
4909 "\\&\n"
4910 " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n"
4911 " we have no guarantees about what was in the memory of the target\n"
4912 " process. (The memory may have been modified by another thread, or\n"
4913 " even by an external attacking process.) We therefore treat the\n"
4914 " buffer returned by pread() as untrusted input. The buffer should\n"
4915 " contain a terminating null byte; if not, then we will trigger an\n"
4916 " error for the target process. */\n"
4917 "\\&\n"
4918 " if (strnlen(path, nread) E<lt> nread)\n"
4919 " return true;\n"
4920 "\\&\n"
4921 " return false;\n"
4922 "}\n"
4923 "\\&\n"
4924 "/* Allocate buffers for the seccomp user-space notification request and\n"
4925 " response structures. It is the caller\\[aq]s responsibility to free the\n"
4926 " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n"
4927 "\\&\n"
4928 "static void\n"
4929 "allocSeccompNotifBuffers(struct seccomp_notif **req,\n"
4930 " struct seccomp_notif_resp **resp,\n"
4931 " struct seccomp_notif_sizes *sizes)\n"
4932 "{\n"
4933 " size_t resp_size;\n"
4934 "\\&\n"
4935 " /* Discover the sizes of the structures that are used to receive\n"
4936 " notifications and send notification responses, and allocate\n"
4937 " buffers of those sizes. */\n"
4938 "\\&\n"
4939 " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n"
4940 " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n"
4941 "\\&\n"
4942 " *req = malloc(sizes-E<gt>seccomp_notif);\n"
4943 " if (*req == NULL)\n"
4944 " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n"
4945 "\\&\n"
4946 " /* When allocating the response buffer, we must allow for the fact\n"
4947 " that the user-space binary may have been built with user-space\n"
4948 " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n"
4949 " response buffer expected by the (older) kernel. Therefore, we\n"
4950 " allocate a buffer that is the maximum of the two sizes. This\n"
4951 " ensures that if the supervisor places bytes into the response\n"
4952 " structure that are past the response size that the kernel expects,\n"
4953 " then the supervisor is not touching an invalid memory location. */\n"
4954 "\\&\n"
4955 " resp_size = sizes-E<gt>seccomp_notif_resp;\n"
4956 " if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n"
4957 " resp_size = sizeof(struct seccomp_notif_resp);\n"
4958 "\\&\n"
4959 " *resp = malloc(resp_size);\n"
4960 " if (*resp == NULL)\n"
4961 " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n"
4962 "\\&\n"
4963 "}\n"
4964 "\\&\n"
4965 "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n"
4966 " descriptor, \\[aq]notifyFd\\[aq]. */\n"
4967 "\\&\n"
4968 "static void\n"
4969 "handleNotifications(int notifyFd)\n"
4970 "{\n"
4971 " bool pathOK;\n"
4972 " char path[PATH_MAX];\n"
4973 " struct seccomp_notif *req;\n"
4974 " struct seccomp_notif_resp *resp;\n"
4975 " struct seccomp_notif_sizes sizes;\n"
4976 "\\&\n"
4977 " allocSeccompNotifBuffers(&req, &resp, &sizes);\n"
4978 "\\&\n"
4979 " /* Loop handling notifications */\n"
4980 "\\&\n"
4981 " for (;;) {\n"
4982 "\\&\n"
4983 " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n"
4984 "\\&\n"
4985 " memset(req, 0, sizes.seccomp_notif);\n"
4986 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n"
4987 " if (errno == EINTR)\n"
4988 " continue;\n"
4989 " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n"
4990 " }\n"
4991 "\\&\n"
4992 " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n"
4993 " req-E<gt>id, req-E<gt>pid);\n"
4994 "\\&\n"
4995 " /* The only system call that can generate a notification event\n"
4996 " is mkdir(2). Nevertheless, we check that the notified system\n"
4997 " call is indeed mkdir() as kind of future-proofing of this\n"
4998 " code in case the seccomp filter is later modified to\n"
4999 " generate notifications for other system calls. */\n"
5000 "\\&\n"
5001 " if (req-E<gt>data.nr != SYS_mkdir) {\n"
5002 " printf(\"\\[rs]tS: notification contained unexpected \"\n"
5003 " \"system call number; bye!!!\\[rs]n\");\n"
5004 " exit(EXIT_FAILURE);\n"
5005 " }\n"
5006 "\\&\n"
5007 " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n"
5008 "\\&\n"
5009 " /* Prepopulate some fields of the response */\n"
5010 "\\&\n"
5011 " resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n"
5012 " resp-E<gt>flags = 0;\n"
5013 " resp-E<gt>val = 0;\n"
5014 "\\&\n"
5015 " /* If getTargetPathname() failed, trigger an EINVAL error\n"
5016 " response (sending this response may yield an error if the\n"
5017 " failure occurred because the notification ID was no longer\n"
5018 " valid); if the directory is in /tmp, then create it on behalf\n"
5019 " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n"
5020 " kernel to let the target process execute the mkdir();\n"
5021 " otherwise, give an error for a directory pathname in any other\n"
5022 " location. */\n"
5023 "\\&\n"
5024 " if (!pathOK) {\n"
5025 " resp-E<gt>error = -EINVAL;\n"
5026 " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n"
5027 " strerror(-resp-E<gt>error));\n"
5028 " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n"
5029 " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n"
5030 " path, req-E<gt>data.args[1]);\n"
5031 "\\&\n"
5032 " if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n"
5033 " resp-E<gt>error = 0; /* \"Success\" */\n"
5034 " resp-E<gt>val = strlen(path); /* Used as return value of\n"
5035 " mkdir() in target */\n"
5036 " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n"
5037 " resp-E<gt>val);\n"
5038 " } else {\n"
5039 "\\&\n"
5040 " /* If mkdir() failed in the supervisor, pass the error\n"
5041 " back to the target */\n"
5042 "\\&\n"
5043 " resp-E<gt>error = -errno;\n"
5044 " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n"
5045 " strerror(errno));\n"
5046 " }\n"
5047 " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n"
5048 " resp-E<gt>error = resp-E<gt>val = 0;\n"
5049 " resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n"
5050 " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n"
5051 " } else {\n"
5052 " resp-E<gt>error = -EOPNOTSUPP;\n"
5053 " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n"
5054 " strerror(-resp-E<gt>error));\n"
5055 " }\n"
5056 "\\&\n"
5057 " /* Send a response to the notification */\n"
5058 "\\&\n"
5059 " printf(\"\\[rs]tS: sending response \"\n"
5060 " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n"
5061 " resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n"
5062 "\\&\n"
5063 " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n"
5064 " if (errno == ENOENT)\n"
5065 " printf(\"\\[rs]tS: response failed with ENOENT; \"\n"
5066 " \"perhaps target process\\[aq]s syscall was \"\n"
5067 " \"interrupted by a signal?\\[rs]n\");\n"
5068 " else\n"
5069 " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n"
5070 " }\n"
5071 "\\&\n"
5072 " /* If the pathname is just \"/bye\", then the supervisor breaks out\n"
5073 " of the loop and terminates. This allows us to see what happens\n"
5074 " if the target process makes further calls to mkdir(2). */\n"
5075 "\\&\n"
5076 " if (strcmp(path, \"/bye\") == 0)\n"
5077 " break;\n"
5078 " }\n"
5079 "\\&\n"
5080 " free(req);\n"
5081 " free(resp);\n"
5082 " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n"
5083 " exit(EXIT_FAILURE);\n"
5084 "}\n"
5085 "\\&\n"
5086 "/* Implementation of the supervisor process:\n"
5087 "\\&\n"
5088 " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n"
5089 " (2) handles notifications that arrive on that file descriptor. */\n"
5090 "\\&\n"
5091 "static void\n"
5092 "supervisor(int sockPair[2])\n"
5093 "{\n"
5094 " int notifyFd;\n"
5095 "\\&\n"
5096 " notifyFd = recvfd(sockPair[1]);\n"
5097 "\\&\n"
5098 " if (notifyFd == -1)\n"
5099 " err(EXIT_FAILURE, \"recvfd\");\n"
5100 "\\&\n"
5101 " closeSocketPair(sockPair); /* We no longer need the socket pair */\n"
5102 "\\&\n"
5103 " handleNotifications(notifyFd);\n"
5104 "}\n"
5105 "\\&\n"
5106 "int\n"
5107 "main(int argc, char *argv[])\n"
5108 "{\n"
5109 " int sockPair[2];\n"
5110 " struct sigaction sa;\n"
5111 "\\&\n"
5112 " setbuf(stdout, NULL);\n"
5113 "\\&\n"
5114 " if (argc E<lt> 2) {\n"
5115 " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n"
5116 " exit(EXIT_FAILURE);\n"
5117 " }\n"
5118 "\\&\n"
5119 " /* Create a UNIX domain socket that is used to pass the seccomp\n"
5120 " notification file descriptor from the target process to the\n"
5121 " supervisor process. */\n"
5122 "\\&\n"
5123 " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n"
5124 " err(EXIT_FAILURE, \"socketpair\");\n"
5125 "\\&\n"
5126 " /* Create a child process--the \"target\"--that installs seccomp\n"
5127 " filtering. The target process writes the seccomp notification\n"
5128 " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n"
5129 " each directory in the command-line arguments. */\n"
5130 "\\&\n"
5131 " (void) targetProcess(sockPair, &argv[optind]);\n"
5132 "\\&\n"
5133 " /* Catch SIGCHLD when the target terminates, so that the\n"
5134 " supervisor can also terminate. */\n"
5135 "\\&\n"
5136 " sa.sa_handler = sigchldHandler;\n"
5137 " sa.sa_flags = 0;\n"
5138 " sigemptyset(&sa.sa_mask);\n"
5139 " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n"
5140 " err(EXIT_FAILURE, \"sigaction\");\n"
5141 "\\&\n"
5142 " supervisor(sockPair);\n"
5143 "\\&\n"
5144 " exit(EXIT_SUCCESS);\n"
5145 "}\n"
5146 msgstr ""
5147
5148 #. type: TH
5149 #: opensuse-leap-16-1 opensuse-tumbleweed
5150 #, no-wrap
5151 msgid "Linux man-pages (unreleased)"
5152 msgstr ""