Debian Codegraph @

po/ru/man2/seccomp_unotify.2.po

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