| 1 |
# Arabic translation of manpages |
| 2 |
# This file is distributed under the same license as the manpages-l10n package. |
| 3 |
# Copyright © of this file: |
| 4 |
# زايد السعيدي <[email protected]>, 2026. |
| 5 |
msgid "" |
| 6 |
msgstr "" |
| 7 |
"Project-Id-Version: manpages-l10n 4.30.2\n" |
| 8 |
"POT-Creation-Date: 2026-06-05 06:42+0200\n" |
| 9 |
"PO-Revision-Date: 2026-05-17 17:43+0400\n" |
| 10 |
"Last-Translator: Zayed Al-Saidi <[email protected]>\n" |
| 11 |
"Language-Team: Arabic <[email protected]>\n" |
| 12 |
"Language: ar\n" |
| 13 |
"MIME-Version: 1.0\n" |
| 14 |
"Content-Type: text/plain; charset=UTF-8\n" |
| 15 |
"Content-Transfer-Encoding: 8bit\n" |
| 16 |
"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 " |
| 17 |
"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" |
| 18 |
"X-Generator: Lokalize 23.08.5\n" |
| 19 |
|
| 20 |
#. type: TH |
| 21 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 22 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 23 |
#, no-wrap |
| 24 |
msgid "seccomp_unotify" |
| 25 |
msgstr "seccomp_unotify" |
| 26 |
|
| 27 |
#. type: TH |
| 28 |
#: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed |
| 29 |
#, no-wrap |
| 30 |
msgid "2026-02-22" |
| 31 |
msgstr "22 فبراير 2026" |
| 32 |
|
| 33 |
#. type: TH |
| 34 |
#: archlinux debian-unstable |
| 35 |
#, no-wrap |
| 36 |
msgid "Linux man-pages 6.18" |
| 37 |
msgstr "صفحات دليل لينكس 6.18" |
| 38 |
|
| 39 |
#. type: SH |
| 40 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 41 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 42 |
#, no-wrap |
| 43 |
msgid "NAME" |
| 44 |
msgstr "الاسم" |
| 45 |
|
| 46 |
#. type: Plain text |
| 47 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 48 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 49 |
msgid "seccomp_unotify - Seccomp user-space notification mechanism" |
| 50 |
msgstr "seccomp_unotify - آلية إشعار seccomp في فضاء المستخدم" |
| 51 |
|
| 52 |
#. type: SH |
| 53 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 54 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 55 |
#, no-wrap |
| 56 |
msgid "LIBRARY" |
| 57 |
msgstr "المكتبة" |
| 58 |
|
| 59 |
#. type: Plain text |
| 60 |
#: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 61 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 62 |
msgid "Standard C library (I<libc>,\\ I<-lc>)" |
| 63 |
msgstr "مكتبة سي المعيارية (I<libc>،\\ I<-lc>)" |
| 64 |
|
| 65 |
#. type: SH |
| 66 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 67 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 68 |
#, no-wrap |
| 69 |
msgid "SYNOPSIS" |
| 70 |
msgstr "موجز" |
| 71 |
|
| 72 |
#. type: Plain text |
| 73 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 74 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 75 |
#, no-wrap |
| 76 |
msgid "" |
| 77 |
"B<#include E<lt>linux/seccomp.hE<gt>>\n" |
| 78 |
"B<#include E<lt>linux/filter.hE<gt>>\n" |
| 79 |
"B<#include E<lt>linux/audit.hE<gt>>\n" |
| 80 |
msgstr "" |
| 81 |
"B<#include E<lt>linux/seccomp.hE<gt>>\n" |
| 82 |
"B<#include E<lt>linux/filter.hE<gt>>\n" |
| 83 |
"B<#include E<lt>linux/audit.hE<gt>>\n" |
| 84 |
|
| 85 |
#. type: Plain text |
| 86 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 87 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 88 |
#, no-wrap |
| 89 |
msgid "B<int seccomp(unsigned int >I<operation>B<, unsigned int >I<flags>B<, void *>I<args>B<);>\n" |
| 90 |
msgstr "B<int seccomp(unsigned int >I<operation>B<, unsigned int >I<flags>B<, void *>I<args>B<);>\n" |
| 91 |
|
| 92 |
#. type: Plain text |
| 93 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 94 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 95 |
#, no-wrap |
| 96 |
msgid "B<#include E<lt>sys/ioctl.hE<gt>>\n" |
| 97 |
msgstr "B<#include E<lt>sys/ioctl.hE<gt>>\n" |
| 98 |
|
| 99 |
#. type: Plain text |
| 100 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 101 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 102 |
#, no-wrap |
| 103 |
msgid "" |
| 104 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_RECV,>\n" |
| 105 |
"B< struct seccomp_notif *>I<req>B<);>\n" |
| 106 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_SEND,>\n" |
| 107 |
"B< struct seccomp_notif_resp *>I<resp>B<);>\n" |
| 108 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_ID_VALID, __u64 *>I<id>B<);>\n" |
| 109 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_ADDFD,>\n" |
| 110 |
"B< struct seccomp_notif_addfd *>I<addfd>B<);>\n" |
| 111 |
msgstr "" |
| 112 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_RECV,>\n" |
| 113 |
"B< struct seccomp_notif *>I<req>B<);>\n" |
| 114 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_SEND,>\n" |
| 115 |
"B< struct seccomp_notif_resp *>I<resp>B<);>\n" |
| 116 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_ID_VALID, __u64 *>I<id>B<);>\n" |
| 117 |
"B<int ioctl(int >I<fd>B<, SECCOMP_IOCTL_NOTIF_ADDFD,>\n" |
| 118 |
"B< struct seccomp_notif_addfd *>I<addfd>B<);>\n" |
| 119 |
|
| 120 |
#. type: SH |
| 121 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 122 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 123 |
#, no-wrap |
| 124 |
msgid "DESCRIPTION" |
| 125 |
msgstr "الوصف" |
| 126 |
|
| 127 |
#. type: Plain text |
| 128 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 129 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 130 |
msgid "" |
| 131 |
"This page describes the user-space notification mechanism provided by the " |
| 132 |
"Secure Computing (seccomp) facility. As well as the use of the " |
| 133 |
"B<SECCOMP_FILTER_FLAG_NEW_LISTENER> flag, the B<SECCOMP_RET_USER_NOTIF> " |
| 134 |
"action value, and the B<SECCOMP_GET_NOTIF_SIZES> operation described in " |
| 135 |
"B<seccomp>(2), this mechanism involves the use of a number of related " |
| 136 |
"B<ioctl>(2) operations (described below)." |
| 137 |
msgstr "" |
| 138 |
"تصف هذه الصفحة آلية إشعار فضاء المستخدم التي توفرها وسيلة الحوسبة الآمنة " |
| 139 |
"(seccomp). بالإضافة إلى استخدام علامة B<SECCOMP_FILTER_FLAG_NEW_LISTENER>، " |
| 140 |
"وقيمة الإجراء B<SECCOMP_RET_USER_NOTIF>، وعملية B<SECCOMP_GET_NOTIF_SIZES> " |
| 141 |
"الموصوفة في B<seccomp>(2)، تتضمن هذه الآلية استخدام عدد من عمليات " |
| 142 |
"B<ioctl>(2) ذات الصلة (الموصوفة أدناه)." |
| 143 |
|
| 144 |
#. type: SS |
| 145 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 146 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 147 |
#, no-wrap |
| 148 |
msgid "Overview" |
| 149 |
msgstr "نظرة عامة" |
| 150 |
|
| 151 |
#. type: Plain text |
| 152 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 153 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 154 |
msgid "" |
| 155 |
"In conventional usage of a seccomp filter, the decision about how to treat a " |
| 156 |
"system call is made by the filter itself. By contrast, the user-space " |
| 157 |
"notification mechanism allows the seccomp filter to delegate the handling of " |
| 158 |
"the system call to another user-space process. Note that this mechanism is " |
| 159 |
"explicitly B<not> intended as a method implementing security policy; see " |
| 160 |
"NOTES." |
| 161 |
msgstr "" |
| 162 |
"في الاستخدام التقليدي لمرشح seccomp، يُتخذ القرار بشأن كيفية التعامل مع " |
| 163 |
"استدعاء النظام بواسطة المرشح نفسه. على النقيض من ذلك، تسمح آلية إشعار فضاء " |
| 164 |
"المستخدم لمرشح seccomp بتفويض معالجة استدعاء النظام إلى عملية أخرى في فضاء " |
| 165 |
"المستخدم. لاحظ أن هذه الآلية B<ليست> مخصصة صراحةً كطريقة لتنفيذ سياسة أمنية؛ " |
| 166 |
"انظر الملاحظات (NOTES)." |
| 167 |
|
| 168 |
#. type: Plain text |
| 169 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 170 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 171 |
msgid "" |
| 172 |
"In the discussion that follows, the thread(s) on which the seccomp filter is " |
| 173 |
"installed is (are) referred to as the I<target>, and the process that is " |
| 174 |
"notified by the user-space notification mechanism is referred to as the " |
| 175 |
"I<supervisor>." |
| 176 |
msgstr "" |
| 177 |
"في المناقشة التي تلي، يُشار إلى الخيط (أو الخيوط) التي ثُبت عليها مرشح seccomp " |
| 178 |
"باسم I<الهدف> (target)، ويُشار إلى العملية التي تُخطر بواسطة آلية إشعار فضاء " |
| 179 |
"المستخدم باسم I<المشرف> (supervisor)." |
| 180 |
|
| 181 |
#. type: Plain text |
| 182 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 183 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 184 |
msgid "" |
| 185 |
"A suitably privileged supervisor can use the user-space notification " |
| 186 |
"mechanism to perform actions on behalf of the target. The advantage of the " |
| 187 |
"user-space notification mechanism is that the supervisor will usually be " |
| 188 |
"able to retrieve information about the target and the performed system call " |
| 189 |
"that the seccomp filter itself cannot. (A seccomp filter is limited in the " |
| 190 |
"information it can obtain and the actions that it can perform because it is " |
| 191 |
"running on a virtual machine inside the kernel.)" |
| 192 |
msgstr "" |
| 193 |
"يمكن للمشرف الذي يتمتع بامتيازات مناسبة استخدام آلية إشعار فضاء المستخدم " |
| 194 |
"لتنفيذ إجراءات نيابة عن الهدف. تكمن ميزة آلية إشعار فضاء المستخدم في أن " |
| 195 |
"المشرف سيكون قادرًا عادةً على استرجاع معلومات حول الهدف واستدعاء النظام المنفذ " |
| 196 |
"التي لا يستطيع مرشح seccomp نفسه الوصول إليها. (مرشح seccomp محدود في " |
| 197 |
"المعلومات التي يمكنه الحصول عليها والإجراءات التي يمكنه القيام بها لأنه يعمل " |
| 198 |
"على جهاز افتراضي داخل النواة.)" |
| 199 |
|
| 200 |
#. ------------------------------------- |
| 201 |
#. type: Plain text |
| 202 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 203 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 204 |
msgid "" |
| 205 |
"An overview of the steps performed by the target and the supervisor is as " |
| 206 |
"follows:" |
| 207 |
msgstr "نظرة عامة على الخطوات التي يقوم بها كل من الهدف والمشرف هي كما يلي:" |
| 208 |
|
| 209 |
#. type: IP |
| 210 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 211 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 212 |
#, no-wrap |
| 213 |
msgid "(1)" |
| 214 |
msgstr "(1)" |
| 215 |
|
| 216 |
#. type: Plain text |
| 217 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 218 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 219 |
msgid "" |
| 220 |
"The target establishes a seccomp filter in the usual manner, but with two " |
| 221 |
"differences:" |
| 222 |
msgstr "ينشئ الهدف مرشح seccomp بالطريقة المعتادة، ولكن مع اختلافين:" |
| 223 |
|
| 224 |
#. type: IP |
| 225 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 226 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 227 |
#, no-wrap |
| 228 |
msgid "\\[bu]" |
| 229 |
msgstr "\\[bu]" |
| 230 |
|
| 231 |
# |
| 232 |
# |
| 233 |
#. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 234 |
#. FIXME |
| 235 |
#. Is the last sentence above correct? |
| 236 |
#. Kees Cook (25 Oct 2020) notes: |
| 237 |
#. I like this limitation, but I expect that it'll need to change in the |
| 238 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 239 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 240 |
#. now there is only 1 because only container managers are using this |
| 241 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 242 |
#. suddenly it might break if a container manager is trying to listen to it |
| 243 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 244 |
#. type: Plain text |
| 245 |
#. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 246 |
#. FIXME |
| 247 |
#. Is the last sentence above correct? |
| 248 |
#. Kees Cook (25 Oct 2020) notes: |
| 249 |
#. I like this limitation, but I expect that it'll need to change in the |
| 250 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 251 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 252 |
#. now there is only 1 because only container managers are using this |
| 253 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 254 |
#. suddenly it might break if a container manager is trying to listen to it |
| 255 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 256 |
#. type: Plain text |
| 257 |
#. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 258 |
#. FIXME |
| 259 |
#. Is the last sentence above correct? |
| 260 |
#. Kees Cook (25 Oct 2020) notes: |
| 261 |
#. I like this limitation, but I expect that it'll need to change in the |
| 262 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 263 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 264 |
#. now there is only 1 because only container managers are using this |
| 265 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 266 |
#. suddenly it might break if a container manager is trying to listen to it |
| 267 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 268 |
#. type: Plain text |
| 269 |
#. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 270 |
#. FIXME |
| 271 |
#. Is the last sentence above correct? |
| 272 |
#. Kees Cook (25 Oct 2020) notes: |
| 273 |
#. I like this limitation, but I expect that it'll need to change in the |
| 274 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 275 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 276 |
#. now there is only 1 because only container managers are using this |
| 277 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 278 |
#. suddenly it might break if a container manager is trying to listen to it |
| 279 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 280 |
#. type: Plain text |
| 281 |
#. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 282 |
#. FIXME |
| 283 |
#. Is the last sentence above correct? |
| 284 |
#. Kees Cook (25 Oct 2020) notes: |
| 285 |
#. I like this limitation, but I expect that it'll need to change in the |
| 286 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 287 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 288 |
#. now there is only 1 because only container managers are using this |
| 289 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 290 |
#. suddenly it might break if a container manager is trying to listen to it |
| 291 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 292 |
#. type: Plain text |
| 293 |
#. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 294 |
#. FIXME |
| 295 |
#. Is the last sentence above correct? |
| 296 |
#. Kees Cook (25 Oct 2020) notes: |
| 297 |
#. I like this limitation, but I expect that it'll need to change in the |
| 298 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 299 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 300 |
#. now there is only 1 because only container managers are using this |
| 301 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 302 |
#. suddenly it might break if a container manager is trying to listen to it |
| 303 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 304 |
#. type: Plain text |
| 305 |
#. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 306 |
#. FIXME |
| 307 |
#. Is the last sentence above correct? |
| 308 |
#. Kees Cook (25 Oct 2020) notes: |
| 309 |
#. I like this limitation, but I expect that it'll need to change in the |
| 310 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 311 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 312 |
#. now there is only 1 because only container managers are using this |
| 313 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 314 |
#. suddenly it might break if a container manager is trying to listen to it |
| 315 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 316 |
#. type: Plain text |
| 317 |
#. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 318 |
#. FIXME |
| 319 |
#. Is the last sentence above correct? |
| 320 |
#. Kees Cook (25 Oct 2020) notes: |
| 321 |
#. I like this limitation, but I expect that it'll need to change in the |
| 322 |
#. future. Even with LSMs, we see the need for arbitrary stacking, and the |
| 323 |
#. idea of there being only 1 supervisor will eventually break down. Right |
| 324 |
#. now there is only 1 because only container managers are using this |
| 325 |
#. feature. But if some daemon starts using it to isolate some thread, |
| 326 |
#. suddenly it might break if a container manager is trying to listen to it |
| 327 |
#. too, etc. I expect it won't be needed soon, but I do think it'll change. |
| 328 |
#. type: Plain text |
| 329 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 330 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 331 |
msgid "" |
| 332 |
"The B<seccomp>(2) I<flags> argument includes the flag " |
| 333 |
"B<SECCOMP_FILTER_FLAG_NEW_LISTENER>. Consequently, the return value of the " |
| 334 |
"(successful) B<seccomp>(2) call is a new \"listening\" file descriptor " |
| 335 |
"that can be used to receive notifications. Only one \"listening\" seccomp " |
| 336 |
"filter can be installed for a thread." |
| 337 |
msgstr "" |
| 338 |
"تتضمن وسيطة I<flags> في B<seccomp>(2) العلامة " |
| 339 |
"B<SECCOMP_FILTER_FLAG_NEW_LISTENER>. وبناءً على ذلك، تكون القيمة المعادة من " |
| 340 |
"استدعاء B<seccomp>(2) (الناجح) هي واصف ملف \"استماع\" جديد يمكن استخدامه " |
| 341 |
"لتلقي الإشعارات. يمكن تثبيت مرشح seccomp \"مستمع\" واحد فقط لكل خيط." |
| 342 |
|
| 343 |
#. type: Plain text |
| 344 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 345 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 346 |
msgid "" |
| 347 |
"In cases where it is appropriate, the seccomp filter returns the action " |
| 348 |
"value B<SECCOMP_RET_USER_NOTIF>. This return value will trigger a " |
| 349 |
"notification event." |
| 350 |
msgstr "" |
| 351 |
"في الحالات المناسبة، يعيد مرشح seccomp قيمة الإجراء " |
| 352 |
"B<SECCOMP_RET_USER_NOTIF>. ستؤدي هذه القيمة المعادة إلى إطلاق حدث إشعار." |
| 353 |
|
| 354 |
#. type: IP |
| 355 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 356 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 357 |
#, no-wrap |
| 358 |
msgid "(2)" |
| 359 |
msgstr "(2)" |
| 360 |
|
| 361 |
#. Jann Horn: |
| 362 |
#. Instead of using unix domain sockets to send the fd to the |
| 363 |
#. parent, I think you could also use clone3() with |
| 364 |
#. flags==CLONE_FILES|SIGCHLD, dup2() the seccomp fd to an fd |
| 365 |
#. that was reserved in the parent, call unshare(CLONE_FILES) |
| 366 |
#. in the child after setting up the seccomp fd, and wake |
| 367 |
#. up the parent with something like pthread_cond_signal()? |
| 368 |
#. I'm not sure whether that'd look better or worse in the |
| 369 |
#. end though, so maybe just ignore this comment. |
| 370 |
#. ------------------------------------- |
| 371 |
#. type: Plain text |
| 372 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 373 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 374 |
msgid "" |
| 375 |
"In order that the supervisor can obtain notifications using the listening " |
| 376 |
"file descriptor, (a duplicate of) that file descriptor must be passed from " |
| 377 |
"the target to the supervisor. One way in which this could be done is by " |
| 378 |
"passing the file descriptor over a UNIX domain socket connection between the " |
| 379 |
"target and the supervisor (using the B<SCM_RIGHTS> ancillary message type " |
| 380 |
"described in B<unix>(7)). Another way to do this is through the use of " |
| 381 |
"B<pidfd_getfd>(2)." |
| 382 |
msgstr "" |
| 383 |
"لكي يتمكن المشرف من الحصول على الإشعارات باستخدام واصف ملف الاستماع، يجب " |
| 384 |
"تمرير (نسخة من) واصف الملف هذا من الهدف إلى المشرف. إحدى الطرق التي يمكن من " |
| 385 |
"خلالها القيام بذلك هي تمرير واصف الملف عبر اتصال مقبس نطاق يونكس بين الهدف " |
| 386 |
"والمشرف (باستخدام نوع الرسالة الملحقة B<SCM_RIGHTS> الموصوفة في B<unix>(7)). " |
| 387 |
"طريقة أخرى للقيام بذلك هي من خلال استخدام B<pidfd_getfd>(2)." |
| 388 |
|
| 389 |
#. type: IP |
| 390 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 391 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 392 |
#, no-wrap |
| 393 |
msgid "(3)" |
| 394 |
msgstr "(3)" |
| 395 |
|
| 396 |
#. ------------------------------------- |
| 397 |
#. type: Plain text |
| 398 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 399 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 400 |
msgid "" |
| 401 |
"The supervisor will receive notification events on the listening file " |
| 402 |
"descriptor. These events are returned as structures of type " |
| 403 |
"I<seccomp_notif>. Because this structure and its size may evolve over " |
| 404 |
"kernel versions, the supervisor must first determine the size of this " |
| 405 |
"structure using the B<seccomp>(2) B<SECCOMP_GET_NOTIF_SIZES> operation, " |
| 406 |
"which returns a structure of type I<seccomp_notif_sizes>. The supervisor " |
| 407 |
"allocates a buffer of size I<seccomp_notif_sizes.seccomp_notif> bytes to " |
| 408 |
"receive notification events. In addition,the supervisor allocates another " |
| 409 |
"buffer of size I<seccomp_notif_sizes.seccomp_notif_resp> bytes for the " |
| 410 |
"response (a I<struct seccomp_notif_resp> structure) that it will provide to " |
| 411 |
"the kernel (and thus the target)." |
| 412 |
msgstr "" |
| 413 |
"سيتلقى المشرف أحداث الإشعار على واصف ملف الاستماع. تُعاد هذه الأحداث في هيئة " |
| 414 |
"هياكل من نوع I<seccomp_notif>. ولأن هذا الهيكل وحجمه قد يتطوران عبر إصدارات " |
| 415 |
"النواة، يجب على المشرف أولاً تحديد حجم هذا الهيكل باستخدام عملية " |
| 416 |
"B<SECCOMP_GET_NOTIF_SIZES> في B<seccomp>(2)، والتي تعيد هيكلًا من نوع " |
| 417 |
"I<seccomp_notif_sizes>. يخصص المشرف مخزنًا مؤقتًا بحجم I<seccomp_notif_sizes." |
| 418 |
"seccomp_notif> بايت لتلقي أحداث الإشعارات. بالإضافة إلى ذلك، يخصص المشرف " |
| 419 |
"مخزنًا مؤقتًا آخر بحجم I<seccomp_notif_sizes.seccomp_notif_resp> بايت " |
| 420 |
"للاستجابة (هيكل I<struct seccomp_notif_resp>) التي سيقدمها للنواة (وبالتالي " |
| 421 |
"للهدف)." |
| 422 |
|
| 423 |
#. type: IP |
| 424 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 425 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 426 |
#, no-wrap |
| 427 |
msgid "(4)" |
| 428 |
msgstr "(4)" |
| 429 |
|
| 430 |
#. ------------------------------------- |
| 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 target then performs its workload, which includes system calls that will " |
| 436 |
"be controlled by the seccomp filter. Whenever one of these system calls " |
| 437 |
"causes the filter to return the B<SECCOMP_RET_USER_NOTIF> action value, the " |
| 438 |
"kernel does I<not> (yet) execute the system call; instead, execution of the " |
| 439 |
"target is temporarily blocked inside the kernel (in a sleep state that is " |
| 440 |
"interruptible by signals) and a notification event is generated on the " |
| 441 |
"listening file descriptor." |
| 442 |
msgstr "" |
| 443 |
"ثم ينفذ الهدف عبء عمله، والذي يتضمن استدعاءات النظام التي سيتحكم فيها مرشح " |
| 444 |
"seccomp. كلما تسبب أحد استدعاءات النظام هذه في إعادة المرشح لقيمة الإجراء " |
| 445 |
"B<SECCOMP_RET_USER_NOTIF>، فإن النواة I<لا> تنفذ (بعد) استدعاء النظام؛ وبدلاً " |
| 446 |
"من ذلك، يُحجب تنفيذ الهدف مؤقتًا داخل النواة (في حالة نوم قابلة للمقاطعة " |
| 447 |
"بواسطة الإشارات) ويُولد حدث إشعار على واصف ملف الاستماع." |
| 448 |
|
| 449 |
#. type: IP |
| 450 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 451 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 452 |
#, no-wrap |
| 453 |
msgid "(5)" |
| 454 |
msgstr "(5)" |
| 455 |
|
| 456 |
# |
| 457 |
# |
| 458 |
# |
| 459 |
#. FIXME |
| 460 |
#. Christian Brauner: |
| 461 |
#. Do we support O_NONBLOCK with SECCOMP_IOCTL_NOTIF_RECV and if |
| 462 |
#. not should we? |
| 463 |
#. Michael Kerrisk: |
| 464 |
#. A quick test suggests that O_NONBLOCK has no effect on the blocking |
| 465 |
#. behavior of SECCOMP_IOCTL_NOTIF_RECV. |
| 466 |
#. type: Plain text |
| 467 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 468 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 469 |
msgid "" |
| 470 |
"The supervisor can now repeatedly monitor the listening file descriptor for " |
| 471 |
"B<SECCOMP_RET_USER_NOTIF>-triggered events. To do this, the supervisor uses " |
| 472 |
"the B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) operation to read information " |
| 473 |
"about a notification event; this operation blocks until an event is " |
| 474 |
"available. The operation returns a I<seccomp_notif> structure containing " |
| 475 |
"information about the system call that is being attempted by the target. " |
| 476 |
"(As described in NOTES, the file descriptor can also be monitored with " |
| 477 |
"B<select>(2), B<poll>(2), or B<epoll>(7).)" |
| 478 |
msgstr "" |
| 479 |
"يمكن للمشرف الآن مراقبة واصف ملف الاستماع بشكل متكرر للأحداث التي تطلقها " |
| 480 |
"B<SECCOMP_RET_USER_NOTIF>. للقيام بذلك، يستخدم المشرف عملية " |
| 481 |
"B<SECCOMP_IOCTL_NOTIF_RECV> في B<ioctl>(2) لقراءة معلومات حول حدث إشعار؛ " |
| 482 |
"تُحجب هذه العملية حتى يتوفر حدث. تعيد العملية هيكل I<seccomp_notif> يحتوي على " |
| 483 |
"معلومات حول استدعاء النظام الذي يحاول الهدف تنفيذه. (كما هو موضح في " |
| 484 |
"الملاحظات (NOTES)، يمكن أيضًا مراقبة واصف الملف باستخدام B<select>(2) أو " |
| 485 |
"B<poll>(2) أو B<epoll>(7).)" |
| 486 |
|
| 487 |
#. type: IP |
| 488 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 489 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 490 |
#, no-wrap |
| 491 |
msgid "(6)" |
| 492 |
msgstr "(6)" |
| 493 |
|
| 494 |
#. type: Plain text |
| 495 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 496 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 497 |
msgid "" |
| 498 |
"The I<seccomp_notif> structure returned by the B<SECCOMP_IOCTL_NOTIF_RECV> " |
| 499 |
"operation includes the same information (a I<seccomp_data> structure) that " |
| 500 |
"was passed to the seccomp filter. This information allows the supervisor to " |
| 501 |
"discover the system call number and the arguments for the target's system " |
| 502 |
"call. In addition, the notification event contains the ID of the thread " |
| 503 |
"that triggered the notification and a unique cookie value that is used in " |
| 504 |
"subsequent B<SECCOMP_IOCTL_NOTIF_ID_VALID> and B<SECCOMP_IOCTL_NOTIF_SEND> " |
| 505 |
"operations." |
| 506 |
msgstr "" |
| 507 |
"يتضمن هيكل I<seccomp_notif> الذي تعيده عملية B<SECCOMP_IOCTL_NOTIF_RECV> نفس " |
| 508 |
"المعلومات (هيكل I<seccomp_data>) التي مُررت إلى مرشح seccomp. تسمح هذه " |
| 509 |
"المعلومات للمشرف باكتشاف رقم استدعاء النظام ووسائط استدعاء نظام الهدف. " |
| 510 |
"بالإضافة إلى ذلك، يحتوي حدث الإشعار على معرف الخيط الذي أطلق الإشعار وقيمة " |
| 511 |
"\"كعكة\" (cookie) فريدة تُستخدم في عمليتي B<SECCOMP_IOCTL_NOTIF_ID_VALID> و " |
| 512 |
"B<SECCOMP_IOCTL_NOTIF_SEND> اللاحقتين." |
| 513 |
|
| 514 |
#. Tycho Andersen mentioned that there are alternatives to /proc/PID/mem, |
| 515 |
#. such as ptrace() and /proc/PID/map_files |
| 516 |
#. ------------------------------------- |
| 517 |
#. type: Plain text |
| 518 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 519 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 520 |
msgid "" |
| 521 |
"The information in the notification can be used to discover the values of " |
| 522 |
"pointer arguments for the target's system call. (This is something that " |
| 523 |
"can't be done from within a seccomp filter.) One way in which the " |
| 524 |
"supervisor can do this is to open the corresponding I</proc/>tidI</mem> file " |
| 525 |
"(see B<proc>(5)) and read bytes from the location that corresponds to one " |
| 526 |
"of the pointer arguments whose value is supplied in the notification event. " |
| 527 |
"(The supervisor must be careful to avoid a race condition that can occur " |
| 528 |
"when doing this; see the description of the B<SECCOMP_IOCTL_NOTIF_ID_VALID> " |
| 529 |
"B<ioctl>(2) operation below.) In addition, the supervisor can access other " |
| 530 |
"system information that is visible in user space but which is not accessible " |
| 531 |
"from a seccomp filter." |
| 532 |
msgstr "" |
| 533 |
"يمكن استخدام المعلومات الواردة في الإشعار لاكتشاف قيم وسائط المؤشر لاستدعاء " |
| 534 |
"نظام الهدف. (هذا شيء لا يمكن القيام به من داخل مرشح seccomp.) إحدى الطرق " |
| 535 |
"التي يمكن للمشرف من خلالها القيام بذلك هي فتح ملف I</proc/>tidI</mem> " |
| 536 |
"المقابل (انظر B<proc>(5)) وقراءة البايتات من الموقع الذي يقابل أحد وسائط " |
| 537 |
"المؤشر التي زُودت قيمتها في حدث الإشعار. (يجب على المشرف توخي الحذر لتجنب " |
| 538 |
"حالة التسابق التي يمكن أن تحدث عند القيام بذلك؛ انظر وصف عملية " |
| 539 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> في B<ioctl>(2) أدناه.) بالإضافة إلى ذلك، " |
| 540 |
"يمكن للمشرف الوصول إلى معلومات النظام الأخرى التي تظهر في فضاء المستخدم ولكن " |
| 541 |
"لا يمكن الوصول إليها من مرشح seccomp." |
| 542 |
|
| 543 |
#. type: IP |
| 544 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 545 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 546 |
#, no-wrap |
| 547 |
msgid "(7)" |
| 548 |
msgstr "(7)" |
| 549 |
|
| 550 |
#. type: Plain text |
| 551 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 552 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 553 |
msgid "" |
| 554 |
"Having obtained information as per the previous step, the supervisor may " |
| 555 |
"then choose to perform an action in response to the target's system call " |
| 556 |
"(which, as noted above, is not executed when the seccomp filter returns the " |
| 557 |
"B<SECCOMP_RET_USER_NOTIF> action value)." |
| 558 |
msgstr "" |
| 559 |
"بعد الحصول على المعلومات كما في الخطوة السابقة، قد يختار المشرف بعد ذلك " |
| 560 |
"تنفيذ إجراء استجابةً لاستدعاء نظام الهدف (والذي، كما لوحظ أعلاه، لا يُنفذ " |
| 561 |
"عندما يعيد مرشح seccomp قيمة الإجراء B<SECCOMP_RET_USER_NOTIF>)." |
| 562 |
|
| 563 |
#. ------------------------------------- |
| 564 |
#. type: Plain text |
| 565 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 566 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 567 |
msgid "" |
| 568 |
"One example use case here relates to containers. The target may be located " |
| 569 |
"inside a container where it does not have sufficient capabilities to mount a " |
| 570 |
"filesystem in the container's mount namespace. However, the supervisor may " |
| 571 |
"be a more privileged process that does have sufficient capabilities to " |
| 572 |
"perform the mount operation." |
| 573 |
msgstr "" |
| 574 |
"أحد أمثلة حالات الاستخدام هنا يتعلق بالحاويات. قد يكون الهدف موجودًا داخل " |
| 575 |
"حاوية حيث لا يملك قدرات كافية لوصل نظام ملفات في مساحة اسم الوصل الخاصة " |
| 576 |
"بالحاوية. ومع ذلك، قد يكون المشرف عملية ذات امتيازات أعلى تملك القدرات " |
| 577 |
"الكافية لتنفيذ عملية الوصل." |
| 578 |
|
| 579 |
#. type: IP |
| 580 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 581 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 582 |
#, no-wrap |
| 583 |
msgid "(8)" |
| 584 |
msgstr "(8)" |
| 585 |
|
| 586 |
#. type: Plain text |
| 587 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 588 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 589 |
msgid "" |
| 590 |
"The supervisor then sends a response to the notification. The information " |
| 591 |
"in this response is used by the kernel to construct a return value for the " |
| 592 |
"target's system call and provide a value that will be assigned to the " |
| 593 |
"I<errno> variable of the target." |
| 594 |
msgstr "" |
| 595 |
"يرسل المشرف بعد ذلك استجابة للإشعار. تستخدم النواة المعلومات الواردة في هذه " |
| 596 |
"الاستجابة لبناء قيمة معادة لاستدعاء نظام الهدف وتوفير قيمة ستُسند إلى متغير " |
| 597 |
"I<errno> الخاص بالهدف." |
| 598 |
|
| 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 response is sent using the B<SECCOMP_IOCTL_NOTIF_SEND> B<ioctl>(2) " |
| 605 |
"operation, which is used to transmit a I<seccomp_notif_resp> structure to " |
| 606 |
"the kernel. This structure includes a cookie value that the supervisor " |
| 607 |
"obtained in the I<seccomp_notif> structure returned by the " |
| 608 |
"B<SECCOMP_IOCTL_NOTIF_RECV> operation. This cookie value allows the kernel " |
| 609 |
"to associate the response with the target. This structure must include the " |
| 610 |
"cookie value that the supervisor obtained in the I<seccomp_notif> structure " |
| 611 |
"returned by the B<SECCOMP_IOCTL_NOTIF_RECV> operation; the cookie allows the " |
| 612 |
"kernel to associate the response with the target." |
| 613 |
msgstr "" |
| 614 |
"تُرسل الاستجابة باستخدام عملية B<SECCOMP_IOCTL_NOTIF_SEND> في B<ioctl>(2)، " |
| 615 |
"والتي تُستخدم لنقل هيكل I<seccomp_notif_resp> إلى النواة. يتضمن هذا الهيكل " |
| 616 |
"قيمة الكعكة التي حصل عليها المشرف في هيكل I<seccomp_notif> الذي أعادته عملية " |
| 617 |
"B<SECCOMP_IOCTL_NOTIF_RECV>. تسمح قيمة الكعكة هذه للنواة بربط الاستجابة " |
| 618 |
"بالهدف. يجب أن يتضمن هذا الهيكل قيمة الكعكة التي حصل عليها المشرف في هيكل " |
| 619 |
"I<seccomp_notif> الذي أعادته عملية B<SECCOMP_IOCTL_NOTIF_RECV>؛ تسمح الكعكة " |
| 620 |
"للنواة بربط الاستجابة بالهدف." |
| 621 |
|
| 622 |
#. type: IP |
| 623 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 624 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 625 |
#, no-wrap |
| 626 |
msgid "(9)" |
| 627 |
msgstr "(9)" |
| 628 |
|
| 629 |
#. ------------------------------------- |
| 630 |
#. type: Plain text |
| 631 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 632 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 633 |
msgid "" |
| 634 |
"Once the notification has been sent, the system call in the target thread " |
| 635 |
"unblocks, returning the information that was provided by the supervisor in " |
| 636 |
"the notification response." |
| 637 |
msgstr "" |
| 638 |
"بمجرد إرسال الإشعار، يُلغى حجب استدعاء النظام في خيط الهدف، ويعيد المعلومات " |
| 639 |
"التي قدمها المشرف في استجابة الإشعار." |
| 640 |
|
| 641 |
#. type: Plain text |
| 642 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 643 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 644 |
msgid "" |
| 645 |
"As a variation on the last two steps, the supervisor can send a response " |
| 646 |
"that tells the kernel that it should execute the target thread's system " |
| 647 |
"call; see the discussion of B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>, below." |
| 648 |
msgstr "" |
| 649 |
"كبديل للخطوتين الأخيرتين، يمكن للمشرف إرسال استجابة تخبر النواة بوجوب تنفيذ " |
| 650 |
"استدعاء نظام خيط الهدف؛ انظر مناقشة B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> " |
| 651 |
"أدناه." |
| 652 |
|
| 653 |
#. type: SH |
| 654 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 655 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 656 |
#, no-wrap |
| 657 |
msgid "IOCTL OPERATIONS" |
| 658 |
msgstr "عمليات IOCTL" |
| 659 |
|
| 660 |
#. type: Plain text |
| 661 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 662 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 663 |
msgid "" |
| 664 |
"The following B<ioctl>(2) operations are supported by the seccomp user-" |
| 665 |
"space notification file descriptor. For each of these operations, the first " |
| 666 |
"(file descriptor) argument of B<ioctl>(2) is the listening file descriptor " |
| 667 |
"returned by a call to B<seccomp>(2) with the " |
| 668 |
"B<SECCOMP_FILTER_FLAG_NEW_LISTENER> flag." |
| 669 |
msgstr "" |
| 670 |
"عمليات B<ioctl>(2) التالية مدعومة من قبل واصف ملف إشعار فضاء مستخدم seccomp. " |
| 671 |
"لكل من هذه العمليات، تكون الوسيطة الأولى (واصف الملف) لـ B<ioctl>(2) هي واصف " |
| 672 |
"ملف الاستماع الذي أعاده استدعاء B<seccomp>(2) مع علامة " |
| 673 |
"B<SECCOMP_FILTER_FLAG_NEW_LISTENER>." |
| 674 |
|
| 675 |
#. type: SS |
| 676 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 677 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 678 |
#, no-wrap |
| 679 |
msgid "SECCOMP_IOCTL_NOTIF_RECV" |
| 680 |
msgstr "SECCOMP_IOCTL_NOTIF_RECV" |
| 681 |
|
| 682 |
#. type: Plain text |
| 683 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 684 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 685 |
msgid "" |
| 686 |
"The B<SECCOMP_IOCTL_NOTIF_RECV> operation (available since Linux 5.0) is " |
| 687 |
"used to obtain a user-space notification event. If no such event is " |
| 688 |
"currently pending, the operation blocks until an event occurs. The third " |
| 689 |
"B<ioctl>(2) argument is a pointer to a structure of the following form " |
| 690 |
"which contains information about the event. This structure must be zeroed " |
| 691 |
"out before the call." |
| 692 |
msgstr "" |
| 693 |
"تُستخدم عملية B<SECCOMP_IOCTL_NOTIF_RECV> (متوفرة منذ لينكس 5.0) للحصول على " |
| 694 |
"حدث إشعار في فضاء المستخدم. إذا لم يكن هناك مثل هذا الحدث معلقًا حاليًا، تُحجب " |
| 695 |
"العملية حتى يقع حدث. الوسيطة الثالثة لـ B<ioctl>(2) هي مؤشر لهيكل بالشكل " |
| 696 |
"التالي يحتوي على معلومات حول الحدث. يجب تصفير هذا الهيكل قبل الاستدعاء." |
| 697 |
|
| 698 |
#. type: Plain text |
| 699 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 700 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 701 |
#, no-wrap |
| 702 |
msgid "" |
| 703 |
"struct seccomp_notif {\n" |
| 704 |
" __u64 id; /* Cookie */\n" |
| 705 |
" __u32 pid; /* TID of target thread */\n" |
| 706 |
" __u32 flags; /* Currently unused (0) */\n" |
| 707 |
" struct seccomp_data data; /* See seccomp(2) */\n" |
| 708 |
"};\n" |
| 709 |
msgstr "" |
| 710 |
"struct seccomp_notif {\n" |
| 711 |
" __u64 id; /* كعكة */\n" |
| 712 |
" __u32 pid; /* TID لخيط الهدف */\n" |
| 713 |
" __u32 flags; /* غير مستخدم حاليا (0) */\n" |
| 714 |
" struct seccomp_data data; /* انظر seccomp(2) */\n" |
| 715 |
"};\n" |
| 716 |
|
| 717 |
#. type: Plain text |
| 718 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 719 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 720 |
msgid "The fields in this structure are as follows:" |
| 721 |
msgstr "الحقول في هذا الهيكل هي كما يلي:" |
| 722 |
|
| 723 |
#. type: TP |
| 724 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 725 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 726 |
#, no-wrap |
| 727 |
msgid "I<id>" |
| 728 |
msgstr "I<id>" |
| 729 |
|
| 730 |
#. type: Plain text |
| 731 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 732 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 733 |
msgid "" |
| 734 |
"This is a cookie for the notification. Each such cookie is guaranteed to be " |
| 735 |
"unique for the corresponding seccomp filter." |
| 736 |
msgstr "" |
| 737 |
"هذه هي كعكة للإشعار. يُضمن أن تكون كل كعكة من هذا القبيل فريدة لمرشح seccomp " |
| 738 |
"المقابل." |
| 739 |
|
| 740 |
#. type: Plain text |
| 741 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 742 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 743 |
msgid "" |
| 744 |
"The cookie can be used with the B<SECCOMP_IOCTL_NOTIF_ID_VALID> B<ioctl>(2) " |
| 745 |
"operation described below." |
| 746 |
msgstr "" |
| 747 |
"يمكن استخدام الكعكة مع عملية B<SECCOMP_IOCTL_NOTIF_ID_VALID> في B<ioctl>(2) " |
| 748 |
"الموصوفة أدناه." |
| 749 |
|
| 750 |
#. type: Plain text |
| 751 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 752 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 753 |
msgid "" |
| 754 |
"When returning a notification response to the kernel, the supervisor must " |
| 755 |
"include the cookie value in the I<seccomp_notif_resp> structure that is " |
| 756 |
"specified as the argument of the B<SECCOMP_IOCTL_NOTIF_SEND> operation." |
| 757 |
msgstr "" |
| 758 |
"عند إرجاع استجابة إشعار إلى النواة، يجب على المشرف تضمين قيمة الكعكة في هيكل " |
| 759 |
"I<seccomp_notif_resp> المحدد كوسيطة لعملية B<SECCOMP_IOCTL_NOTIF_SEND>." |
| 760 |
|
| 761 |
#. type: TP |
| 762 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 763 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 764 |
#, no-wrap |
| 765 |
msgid "I<pid>" |
| 766 |
msgstr "I<pid>" |
| 767 |
|
| 768 |
#. type: Plain text |
| 769 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 770 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 771 |
msgid "" |
| 772 |
"This is the thread ID of the target thread that triggered the notification " |
| 773 |
"event." |
| 774 |
msgstr "هذا هو معرف الخيط لخيط الهدف الذي أطلق حدث الإشعار." |
| 775 |
|
| 776 |
#. type: TP |
| 777 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 778 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 779 |
#, no-wrap |
| 780 |
msgid "I<flags>" |
| 781 |
msgstr "I<flags>" |
| 782 |
|
| 783 |
#. type: Plain text |
| 784 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 785 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 786 |
msgid "" |
| 787 |
"This is a bit mask of flags providing further information on the event. In " |
| 788 |
"the current implementation, this field is always zero." |
| 789 |
msgstr "" |
| 790 |
"هذا قناع بتات للعلامات التي توفر معلومات إضافية حول الحدث. في التنفيذ " |
| 791 |
"الحالي، هذا الحقل دائمًا صفر." |
| 792 |
|
| 793 |
#. type: TP |
| 794 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 795 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 796 |
#, no-wrap |
| 797 |
msgid "I<data>" |
| 798 |
msgstr "I<data>" |
| 799 |
|
| 800 |
#. type: Plain text |
| 801 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 802 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 803 |
msgid "" |
| 804 |
"This is a I<seccomp_data> structure containing information about the system " |
| 805 |
"call that triggered the notification. This is the same structure that is " |
| 806 |
"passed to the seccomp filter. See B<seccomp>(2) for details of this " |
| 807 |
"structure." |
| 808 |
msgstr "" |
| 809 |
"هذا هيكل I<seccomp_data> يحتوي على معلومات حول استدعاء النظام الذي أطلق " |
| 810 |
"الإشعار. هذا هو نفس الهيكل الذي يُمرر إلى مرشح seccomp. انظر B<seccomp>(2) " |
| 811 |
"للحصول على تفاصيل حول هذا الهيكل." |
| 812 |
|
| 813 |
#. type: Plain text |
| 814 |
#: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 815 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 816 |
msgid "" |
| 817 |
"On success, this operation returns 0; on failure, -1 is returned, and " |
| 818 |
"I<errno> is set to indicate the error. This operation can fail with the " |
| 819 |
"following errors:" |
| 820 |
msgstr "" |
| 821 |
"عند النجاح، تعيد هذه العملية 0؛ وعند الفشل، تُعاد -1، ويُضبط I<errno> للإشارة " |
| 822 |
"إلى الخطأ. يمكن أن تفشل هذه العملية بالأخطاء التالية:" |
| 823 |
|
| 824 |
#. type: TP |
| 825 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 826 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 827 |
#, no-wrap |
| 828 |
msgid "B<EINVAL> (since Linux 5.5)" |
| 829 |
msgstr "B<EINVAL> (منذ لينكس 5.5)" |
| 830 |
|
| 831 |
#. commit 2882d53c9c6f3b8311d225062522f03772cf0179 |
| 832 |
#. type: Plain text |
| 833 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 834 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 835 |
msgid "" |
| 836 |
"The I<seccomp_notif> structure that was passed to the call contained nonzero " |
| 837 |
"fields." |
| 838 |
msgstr "هيكل I<seccomp_notif> الذي مُرر إلى الاستدعاء احتوى على حقول غير صفرية." |
| 839 |
|
| 840 |
#. type: TP |
| 841 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 842 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 843 |
#, no-wrap |
| 844 |
msgid "B<ENOENT>" |
| 845 |
msgstr "B<ENOENT>" |
| 846 |
|
| 847 |
# |
| 848 |
# |
| 849 |
# |
| 850 |
# |
| 851 |
# |
| 852 |
#. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 853 |
#. FIXME |
| 854 |
#. From my experiments, |
| 855 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 856 |
#. the target thread terminates, then the ioctl() simply |
| 857 |
#. blocks (rather than returning an error to indicate that the |
| 858 |
#. target no longer exists). |
| 859 |
#. I found that surprising, and it required some contortions in |
| 860 |
#. the example program. It was not possible to code my SIGCHLD |
| 861 |
#. handler (which reaps the zombie when the worker/target |
| 862 |
#. terminates) to simply set a flag checked in the main |
| 863 |
#. handleNotifications() loop, since this created an |
| 864 |
#. unavoidable race where the child might terminate just after |
| 865 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 866 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 867 |
#. the signal handler to simply call _exit(2) in order to |
| 868 |
#. terminate the parent process (the supervisor). |
| 869 |
#. Is this expected behavior? It seems to me rather |
| 870 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 871 |
#. if the target has terminated. |
| 872 |
#. Jann posted a patch to rectify this, but there was no response |
| 873 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 874 |
#. this issue. (I've tried building with the patch, but encountered |
| 875 |
#. an issue with the target process entering D state after a signal.) |
| 876 |
#. For now, this behavior is documented in BUGS. |
| 877 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 878 |
#. type: Plain text |
| 879 |
#. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 880 |
#. FIXME |
| 881 |
#. From my experiments, |
| 882 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 883 |
#. the target thread terminates, then the ioctl() simply |
| 884 |
#. blocks (rather than returning an error to indicate that the |
| 885 |
#. target no longer exists). |
| 886 |
#. I found that surprising, and it required some contortions in |
| 887 |
#. the example program. It was not possible to code my SIGCHLD |
| 888 |
#. handler (which reaps the zombie when the worker/target |
| 889 |
#. terminates) to simply set a flag checked in the main |
| 890 |
#. handleNotifications() loop, since this created an |
| 891 |
#. unavoidable race where the child might terminate just after |
| 892 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 893 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 894 |
#. the signal handler to simply call _exit(2) in order to |
| 895 |
#. terminate the parent process (the supervisor). |
| 896 |
#. Is this expected behavior? It seems to me rather |
| 897 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 898 |
#. if the target has terminated. |
| 899 |
#. Jann posted a patch to rectify this, but there was no response |
| 900 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 901 |
#. this issue. (I've tried building with the patch, but encountered |
| 902 |
#. an issue with the target process entering D state after a signal.) |
| 903 |
#. For now, this behavior is documented in BUGS. |
| 904 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 905 |
#. type: Plain text |
| 906 |
#. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 907 |
#. FIXME |
| 908 |
#. From my experiments, |
| 909 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 910 |
#. the target thread terminates, then the ioctl() simply |
| 911 |
#. blocks (rather than returning an error to indicate that the |
| 912 |
#. target no longer exists). |
| 913 |
#. I found that surprising, and it required some contortions in |
| 914 |
#. the example program. It was not possible to code my SIGCHLD |
| 915 |
#. handler (which reaps the zombie when the worker/target |
| 916 |
#. terminates) to simply set a flag checked in the main |
| 917 |
#. handleNotifications() loop, since this created an |
| 918 |
#. unavoidable race where the child might terminate just after |
| 919 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 920 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 921 |
#. the signal handler to simply call _exit(2) in order to |
| 922 |
#. terminate the parent process (the supervisor). |
| 923 |
#. Is this expected behavior? It seems to me rather |
| 924 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 925 |
#. if the target has terminated. |
| 926 |
#. Jann posted a patch to rectify this, but there was no response |
| 927 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 928 |
#. this issue. (I've tried building with the patch, but encountered |
| 929 |
#. an issue with the target process entering D state after a signal.) |
| 930 |
#. For now, this behavior is documented in BUGS. |
| 931 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 932 |
#. type: Plain text |
| 933 |
#. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 934 |
#. FIXME |
| 935 |
#. From my experiments, |
| 936 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 937 |
#. the target thread terminates, then the ioctl() simply |
| 938 |
#. blocks (rather than returning an error to indicate that the |
| 939 |
#. target no longer exists). |
| 940 |
#. I found that surprising, and it required some contortions in |
| 941 |
#. the example program. It was not possible to code my SIGCHLD |
| 942 |
#. handler (which reaps the zombie when the worker/target |
| 943 |
#. terminates) to simply set a flag checked in the main |
| 944 |
#. handleNotifications() loop, since this created an |
| 945 |
#. unavoidable race where the child might terminate just after |
| 946 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 947 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 948 |
#. the signal handler to simply call _exit(2) in order to |
| 949 |
#. terminate the parent process (the supervisor). |
| 950 |
#. Is this expected behavior? It seems to me rather |
| 951 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 952 |
#. if the target has terminated. |
| 953 |
#. Jann posted a patch to rectify this, but there was no response |
| 954 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 955 |
#. this issue. (I've tried building with the patch, but encountered |
| 956 |
#. an issue with the target process entering D state after a signal.) |
| 957 |
#. For now, this behavior is documented in BUGS. |
| 958 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 959 |
#. type: Plain text |
| 960 |
#. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 961 |
#. FIXME |
| 962 |
#. From my experiments, |
| 963 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 964 |
#. the target thread terminates, then the ioctl() simply |
| 965 |
#. blocks (rather than returning an error to indicate that the |
| 966 |
#. target no longer exists). |
| 967 |
#. I found that surprising, and it required some contortions in |
| 968 |
#. the example program. It was not possible to code my SIGCHLD |
| 969 |
#. handler (which reaps the zombie when the worker/target |
| 970 |
#. terminates) to simply set a flag checked in the main |
| 971 |
#. handleNotifications() loop, since this created an |
| 972 |
#. unavoidable race where the child might terminate just after |
| 973 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 974 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 975 |
#. the signal handler to simply call _exit(2) in order to |
| 976 |
#. terminate the parent process (the supervisor). |
| 977 |
#. Is this expected behavior? It seems to me rather |
| 978 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 979 |
#. if the target has terminated. |
| 980 |
#. Jann posted a patch to rectify this, but there was no response |
| 981 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 982 |
#. this issue. (I've tried building with the patch, but encountered |
| 983 |
#. an issue with the target process entering D state after a signal.) |
| 984 |
#. For now, this behavior is documented in BUGS. |
| 985 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 986 |
#. type: Plain text |
| 987 |
#. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 988 |
#. FIXME |
| 989 |
#. From my experiments, |
| 990 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 991 |
#. the target thread terminates, then the ioctl() simply |
| 992 |
#. blocks (rather than returning an error to indicate that the |
| 993 |
#. target no longer exists). |
| 994 |
#. I found that surprising, and it required some contortions in |
| 995 |
#. the example program. It was not possible to code my SIGCHLD |
| 996 |
#. handler (which reaps the zombie when the worker/target |
| 997 |
#. terminates) to simply set a flag checked in the main |
| 998 |
#. handleNotifications() loop, since this created an |
| 999 |
#. unavoidable race where the child might terminate just after |
| 1000 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 1001 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 1002 |
#. the signal handler to simply call _exit(2) in order to |
| 1003 |
#. terminate the parent process (the supervisor). |
| 1004 |
#. Is this expected behavior? It seems to me rather |
| 1005 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 1006 |
#. if the target has terminated. |
| 1007 |
#. Jann posted a patch to rectify this, but there was no response |
| 1008 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 1009 |
#. this issue. (I've tried building with the patch, but encountered |
| 1010 |
#. an issue with the target process entering D state after a signal.) |
| 1011 |
#. For now, this behavior is documented in BUGS. |
| 1012 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 1013 |
#. type: Plain text |
| 1014 |
#. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1015 |
#. FIXME |
| 1016 |
#. From my experiments, |
| 1017 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 1018 |
#. the target thread terminates, then the ioctl() simply |
| 1019 |
#. blocks (rather than returning an error to indicate that the |
| 1020 |
#. target no longer exists). |
| 1021 |
#. I found that surprising, and it required some contortions in |
| 1022 |
#. the example program. It was not possible to code my SIGCHLD |
| 1023 |
#. handler (which reaps the zombie when the worker/target |
| 1024 |
#. terminates) to simply set a flag checked in the main |
| 1025 |
#. handleNotifications() loop, since this created an |
| 1026 |
#. unavoidable race where the child might terminate just after |
| 1027 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 1028 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 1029 |
#. the signal handler to simply call _exit(2) in order to |
| 1030 |
#. terminate the parent process (the supervisor). |
| 1031 |
#. Is this expected behavior? It seems to me rather |
| 1032 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 1033 |
#. if the target has terminated. |
| 1034 |
#. Jann posted a patch to rectify this, but there was no response |
| 1035 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 1036 |
#. this issue. (I've tried building with the patch, but encountered |
| 1037 |
#. an issue with the target process entering D state after a signal.) |
| 1038 |
#. For now, this behavior is documented in BUGS. |
| 1039 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 1040 |
#. type: Plain text |
| 1041 |
#. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1042 |
#. FIXME |
| 1043 |
#. From my experiments, |
| 1044 |
#. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after |
| 1045 |
#. the target thread terminates, then the ioctl() simply |
| 1046 |
#. blocks (rather than returning an error to indicate that the |
| 1047 |
#. target no longer exists). |
| 1048 |
#. I found that surprising, and it required some contortions in |
| 1049 |
#. the example program. It was not possible to code my SIGCHLD |
| 1050 |
#. handler (which reaps the zombie when the worker/target |
| 1051 |
#. terminates) to simply set a flag checked in the main |
| 1052 |
#. handleNotifications() loop, since this created an |
| 1053 |
#. unavoidable race where the child might terminate just after |
| 1054 |
#. I had checked the flag, but before I blocked (forever!) in the |
| 1055 |
#. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code |
| 1056 |
#. the signal handler to simply call _exit(2) in order to |
| 1057 |
#. terminate the parent process (the supervisor). |
| 1058 |
#. Is this expected behavior? It seems to me rather |
| 1059 |
#. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error |
| 1060 |
#. if the target has terminated. |
| 1061 |
#. Jann posted a patch to rectify this, but there was no response |
| 1062 |
#. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing |
| 1063 |
#. this issue. (I've tried building with the patch, but encountered |
| 1064 |
#. an issue with the target process entering D state after a signal.) |
| 1065 |
#. For now, this behavior is documented in BUGS. |
| 1066 |
#. Kees Cook commented: Let's change [this] ASAP! |
| 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 |
"The target thread was killed by a signal as the notification information was " |
| 1072 |
"being generated, or the target's (blocked) system call was interrupted by a " |
| 1073 |
"signal handler." |
| 1074 |
msgstr "" |
| 1075 |
"قُتل خيط الهدف بواسطة إشارة أثناء إنشاء معلومات الإشعار، أو قوطع استدعاء نظام " |
| 1076 |
"الهدف (المحجوب) بواسطة معالج إشارة." |
| 1077 |
|
| 1078 |
#. type: SS |
| 1079 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1080 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1081 |
#, no-wrap |
| 1082 |
msgid "SECCOMP_IOCTL_NOTIF_ID_VALID" |
| 1083 |
msgstr "SECCOMP_IOCTL_NOTIF_ID_VALID" |
| 1084 |
|
| 1085 |
#. type: Plain text |
| 1086 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1087 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1088 |
msgid "" |
| 1089 |
"The B<SECCOMP_IOCTL_NOTIF_ID_VALID> operation (available since Linux 5.0) is " |
| 1090 |
"used to check that a notification ID returned by an earlier " |
| 1091 |
"B<SECCOMP_IOCTL_NOTIF_RECV> operation is still valid (i.e., that the target " |
| 1092 |
"still exists and its system call is still blocked waiting for a response)." |
| 1093 |
msgstr "" |
| 1094 |
"تُستخدم عملية B<SECCOMP_IOCTL_NOTIF_ID_VALID> (متوفرة منذ لينكس 5.0) للتحقق " |
| 1095 |
"من أن معرف الإشعار الذي أعادته عملية B<SECCOMP_IOCTL_NOTIF_RECV> سابقة لا " |
| 1096 |
"يزال صالحًا (أي أن الهدف لا يزال موجودًا واستدعاء نظامه لا يزال محجوبًا في " |
| 1097 |
"انتظار استجابة)." |
| 1098 |
|
| 1099 |
#. type: Plain text |
| 1100 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1101 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1102 |
msgid "" |
| 1103 |
"The third B<ioctl>(2) argument is a pointer to the cookie (I<id>) returned " |
| 1104 |
"by the B<SECCOMP_IOCTL_NOTIF_RECV> operation." |
| 1105 |
msgstr "" |
| 1106 |
"الوسيطة الثالثة لـ B<ioctl>(2) هي مؤشر للكعكة (I<id>) التي أعادتها عملية " |
| 1107 |
"B<SECCOMP_IOCTL_NOTIF_RECV>." |
| 1108 |
|
| 1109 |
#. type: Plain text |
| 1110 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1111 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1112 |
msgid "" |
| 1113 |
"This operation is necessary to avoid race conditions that can occur when the " |
| 1114 |
"I<pid> returned by the B<SECCOMP_IOCTL_NOTIF_RECV> operation terminates, and " |
| 1115 |
"that process ID is reused by another process. An example of this kind of " |
| 1116 |
"race is the following" |
| 1117 |
msgstr "" |
| 1118 |
"هذه العملية ضرورية لتجنب حالات التسابق التي يمكن أن تحدث عندما ينتهي الـ " |
| 1119 |
"I<pid> الذي أعادته عملية B<SECCOMP_IOCTL_NOTIF_RECV>، ويُعاد استخدام معرف " |
| 1120 |
"العملية هذا بواسطة عملية أخرى. مثال على هذا النوع من التسابق هو ما يلي" |
| 1121 |
|
| 1122 |
#. type: Plain text |
| 1123 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1124 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1125 |
msgid "" |
| 1126 |
"A notification is generated on the listening file descriptor. The returned " |
| 1127 |
"I<seccomp_notif> contains the TID of the target thread (in the I<pid> field " |
| 1128 |
"of the structure)." |
| 1129 |
msgstr "" |
| 1130 |
"يُنشأ إشعار على واصف ملف الاستماع. يحتوي هيكل I<seccomp_notif> المُرجع على " |
| 1131 |
"معرف الخيط (TID) للخيط الهدف (في حقل I<pid> الخاص بالهيكل)." |
| 1132 |
|
| 1133 |
#. type: Plain text |
| 1134 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1135 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1136 |
msgid "The target terminates." |
| 1137 |
msgstr "ينتهي الهدف." |
| 1138 |
|
| 1139 |
#. type: Plain text |
| 1140 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1141 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1142 |
msgid "" |
| 1143 |
"Another thread or process is created on the system that by chance reuses the " |
| 1144 |
"TID that was freed when the target terminated." |
| 1145 |
msgstr "" |
| 1146 |
"يُنشأ خيط أو عملية أخرى على النظام تُعيد استخدام TID الذي حُرّر عند انتهاء الهدف " |
| 1147 |
"عن طريق المصادفة." |
| 1148 |
|
| 1149 |
#. type: Plain text |
| 1150 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1151 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1152 |
msgid "" |
| 1153 |
"The supervisor B<open>(2)s the I</proc/>tidI</mem> file for the TID obtained " |
| 1154 |
"in step 1, with the intention of (say) inspecting the memory location(s) " |
| 1155 |
"that containing the argument(s) of the system call that triggered the " |
| 1156 |
"notification in step 1." |
| 1157 |
msgstr "" |
| 1158 |
"يفتح المشرف عبر B<open>(2) ملف I</proc/>tidI</mem> لـ TID الذي حُصل عليه في " |
| 1159 |
"الخطوة 1، بقصد فحص مواقع الذاكرة التي تحتوي على وسيط (أو وسائط) استدعاء " |
| 1160 |
"النظام الذي أطلق الإشعار في الخطوة 1." |
| 1161 |
|
| 1162 |
#. Jann Horn: |
| 1163 |
#. the PID can be reused, but the /proc/$pid directory is |
| 1164 |
#. internally not associated with the numeric PID, but, |
| 1165 |
#. conceptually speaking, with a specific incarnation of the |
| 1166 |
#. PID, or something like that. (Actually, it is associated |
| 1167 |
#. with the "struct pid", which is not reused, instead of the |
| 1168 |
#. numeric PID. |
| 1169 |
#. type: Plain text |
| 1170 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1171 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1172 |
msgid "" |
| 1173 |
"In the above scenario, the risk is that the supervisor may try to access the " |
| 1174 |
"memory of a process other than the target. This race can be avoided by " |
| 1175 |
"following the call to B<open>(2) with a B<SECCOMP_IOCTL_NOTIF_ID_VALID> " |
| 1176 |
"operation to verify that the process that generated the notification is " |
| 1177 |
"still alive. (Note that if the target terminates after the latter step, a " |
| 1178 |
"subsequent B<read>(2) from the file descriptor may return 0, indicating end " |
| 1179 |
"of file.)" |
| 1180 |
msgstr "" |
| 1181 |
"في السيناريو أعلاه، يكمن الخطر في أن المشرف قد يحاول الوصول إلى ذاكرة عملية " |
| 1182 |
"أخرى غير الهدف. يمكن تجنب حالة السباق هذه بإتباع استدعاء B<open>(2) بعملية " |
| 1183 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> للتحقق من أن العملية التي أنشأت الإشعار لا " |
| 1184 |
"تزال حية. (لاحظ أنه إذا انتهى الهدف بعد الخطوة الأخيرة، فإن أي B<read>(2) " |
| 1185 |
"لاحقة من واصف الملف قد تُرجع 0، مما يشير إلى نهاية الملف)." |
| 1186 |
|
| 1187 |
#. type: Plain text |
| 1188 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1189 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1190 |
msgid "" |
| 1191 |
"See NOTES for a discussion of other cases where " |
| 1192 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> checks must be performed." |
| 1193 |
msgstr "" |
| 1194 |
"انظر الملاحظات لمناقشة الحالات الأخرى التي يجب فيها إجراء فحوصات " |
| 1195 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID>." |
| 1196 |
|
| 1197 |
#. type: Plain text |
| 1198 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1199 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1200 |
msgid "" |
| 1201 |
"On success (i.e., the notification ID is still valid), this operation " |
| 1202 |
"returns 0. On failure (i.e., the notification ID is no longer valid), -1 is " |
| 1203 |
"returned, and I<errno> is set to B<ENOENT>." |
| 1204 |
msgstr "" |
| 1205 |
"عند النجاح (أي أن معرف الإشعار لا يزال صالحاً)، تُرجع هذه العملية 0. وعند " |
| 1206 |
"الفشل (أي أن معرف الإشعار لم يعد صالحاً)، يُرجع -1، ويُضبط I<errno> على " |
| 1207 |
"B<ENOENT>." |
| 1208 |
|
| 1209 |
#. type: SS |
| 1210 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1211 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1212 |
#, no-wrap |
| 1213 |
msgid "SECCOMP_IOCTL_NOTIF_SEND" |
| 1214 |
msgstr "SECCOMP_IOCTL_NOTIF_SEND" |
| 1215 |
|
| 1216 |
#. type: Plain text |
| 1217 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1218 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1219 |
msgid "" |
| 1220 |
"The B<SECCOMP_IOCTL_NOTIF_SEND> operation (available since Linux 5.0) is " |
| 1221 |
"used to send a notification response back to the kernel. The third " |
| 1222 |
"B<ioctl>(2) argument of this structure is a pointer to a structure of the " |
| 1223 |
"following form:" |
| 1224 |
msgstr "" |
| 1225 |
"تُستخدم عملية B<SECCOMP_IOCTL_NOTIF_SEND> (المتوفرة منذ لينكس 5.0) لإرسال رد " |
| 1226 |
"إشعار إلى النواة. وسيط B<ioctl>(2) الثالث لهذا الهيكل هو مؤشر إلى هيكل " |
| 1227 |
"بالشكل التالي:" |
| 1228 |
|
| 1229 |
#. type: Plain text |
| 1230 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1231 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1232 |
#, no-wrap |
| 1233 |
msgid "" |
| 1234 |
"struct seccomp_notif_resp {\n" |
| 1235 |
" __u64 id; /* Cookie value */\n" |
| 1236 |
" __s64 val; /* Success return value */\n" |
| 1237 |
" __s32 error; /* 0 (success) or negative error number */\n" |
| 1238 |
" __u32 flags; /* See below */\n" |
| 1239 |
"};\n" |
| 1240 |
msgstr "" |
| 1241 |
"struct seccomp_notif_resp {\n" |
| 1242 |
" __u64 id; /* قيمة الكوكيز */\n" |
| 1243 |
" __s64 val; /* قيمة النجاح المرجعة */\n" |
| 1244 |
" __s32 error; /* 0 (نجاح) أو رقم خطأ سالب */\n" |
| 1245 |
" __u32 flags; /* انظر أدناه */\n" |
| 1246 |
"};\n" |
| 1247 |
|
| 1248 |
#. type: Plain text |
| 1249 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1250 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1251 |
msgid "The fields of this structure are as follows:" |
| 1252 |
msgstr "حقول هذا الهيكل هي كالتالي:" |
| 1253 |
|
| 1254 |
#. type: Plain text |
| 1255 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1256 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1257 |
msgid "" |
| 1258 |
"This is the cookie value that was obtained using the " |
| 1259 |
"B<SECCOMP_IOCTL_NOTIF_RECV> operation. This cookie value allows the kernel " |
| 1260 |
"to correctly associate this response with the system call that triggered the " |
| 1261 |
"user-space notification." |
| 1262 |
msgstr "" |
| 1263 |
"هذه هي قيمة الكوكيز التي حُصل عليها باستخدام عملية " |
| 1264 |
"B<SECCOMP_IOCTL_NOTIF_RECV>. تسمح قيمة الكوكيز هذه للنواة بربط هذا الرد بشكل " |
| 1265 |
"صحيح مع استدعاء النظام الذي أطلق إشعار مساحة المستخدم." |
| 1266 |
|
| 1267 |
#. type: TP |
| 1268 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1269 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1270 |
#, no-wrap |
| 1271 |
msgid "I<val>" |
| 1272 |
msgstr "I<val>" |
| 1273 |
|
| 1274 |
#. type: Plain text |
| 1275 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1276 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1277 |
msgid "" |
| 1278 |
"This is the value that will be used for a spoofed success return for the " |
| 1279 |
"target's system call; see below." |
| 1280 |
msgstr "" |
| 1281 |
"هذه هي القيمة التي ستُستخدم لرد نجاح زائف لاستدعاء نظام الهدف؛ انظر أدناه." |
| 1282 |
|
| 1283 |
#. type: TP |
| 1284 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1285 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1286 |
#, no-wrap |
| 1287 |
msgid "I<error>" |
| 1288 |
msgstr "I<error>" |
| 1289 |
|
| 1290 |
#. type: Plain text |
| 1291 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1292 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1293 |
msgid "" |
| 1294 |
"This is the value that will be used as the error number (I<errno>) for a " |
| 1295 |
"spoofed error return for the target's system call; see below." |
| 1296 |
msgstr "" |
| 1297 |
"هذه هي القيمة التي ستُستخدم كرقم خطأ (I<errno>) لرد خطأ زائف لاستدعاء نظام " |
| 1298 |
"الهدف؛ انظر أدناه." |
| 1299 |
|
| 1300 |
#. type: Plain text |
| 1301 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1302 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1303 |
msgid "This is a bit mask that includes zero or more of the following flags:" |
| 1304 |
msgstr "هذا قناع بتات يتضمن صفراً أو أكثر من اللصائق التالية:" |
| 1305 |
|
| 1306 |
#. type: TP |
| 1307 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1308 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1309 |
#, no-wrap |
| 1310 |
msgid "B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> (since Linux 5.5)" |
| 1311 |
msgstr "B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> (منذ لينكس 5.5)" |
| 1312 |
|
| 1313 |
#. commit fb3c5386b382d4097476ce9647260fc89b34afdb |
| 1314 |
#. type: Plain text |
| 1315 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1316 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1317 |
msgid "Tell the kernel to execute the target's system call." |
| 1318 |
msgstr "إخبار النواة بتنفيذ استدعاء نظام الهدف." |
| 1319 |
|
| 1320 |
#. type: Plain text |
| 1321 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1322 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1323 |
msgid "Two kinds of response are possible:" |
| 1324 |
msgstr "يوجد نوعان ممكنان من الردود:" |
| 1325 |
|
| 1326 |
#. type: Plain text |
| 1327 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1328 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1329 |
msgid "" |
| 1330 |
"A response to the kernel telling it to execute the target's system call. In " |
| 1331 |
"this case, the I<flags> field includes B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> " |
| 1332 |
"and the I<error> and I<val> fields must be zero." |
| 1333 |
msgstr "" |
| 1334 |
"رد للنواة يخبرها بتنفيذ استدعاء نظام الهدف. في هذه الحالة، يتضمن حقل " |
| 1335 |
"I<flags> العلامة B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> ويجب أن يكون الحقلان " |
| 1336 |
"I<error> و I<val> صفرين." |
| 1337 |
|
| 1338 |
#. type: Plain text |
| 1339 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1340 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1341 |
msgid "" |
| 1342 |
"This kind of response can be useful in cases where the supervisor needs to " |
| 1343 |
"do deeper analysis of the target's system call than is possible from a " |
| 1344 |
"seccomp filter (e.g., examining the values of pointer arguments), and, " |
| 1345 |
"having decided that the system call does not require emulation by the " |
| 1346 |
"supervisor, the supervisor wants the system call to be executed normally in " |
| 1347 |
"the target." |
| 1348 |
msgstr "" |
| 1349 |
"هذا النوع من الردود يكون مفيداً في الحالات التي يحتاج فيها المشرف إلى إجراء " |
| 1350 |
"تحليل أعمق لاستدعاء نظام الهدف مما هو ممكن من مرشح seccomp (مثل فحص قيم " |
| 1351 |
"وسائط المؤشرات)، وبعد أن يقرر المشرف أن استدعاء النظام لا يتطلب محاكاة، يريد " |
| 1352 |
"المشرف تنفيذ استدعاء النظام بشكل طبيعي في الهدف." |
| 1353 |
|
| 1354 |
#. type: Plain text |
| 1355 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1356 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1357 |
msgid "" |
| 1358 |
"The B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> flag should be used with caution; " |
| 1359 |
"see NOTES." |
| 1360 |
msgstr "" |
| 1361 |
"يجب استخدام وسم B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> بحذر؛ انظر الملاحظات." |
| 1362 |
|
| 1363 |
#. type: Plain text |
| 1364 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1365 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1366 |
msgid "" |
| 1367 |
"A spoofed return value for the target's system call. In this case, the " |
| 1368 |
"kernel does not execute the target's system call, instead causing the system " |
| 1369 |
"call to return a spoofed value as specified by fields of the " |
| 1370 |
"I<seccomp_notif_resp> structure. The supervisor should set the fields of " |
| 1371 |
"this structure as follows:" |
| 1372 |
msgstr "" |
| 1373 |
"قيمة مرجعة زائفة لاستدعاء نظام الهدف. في هذه الحالة، لا تنفذ النواة استدعاء " |
| 1374 |
"نظام الهدف، وبدلاً من ذلك تجعل استدعاء النظام يُرجع قيمة زائفة كما هو محدد في " |
| 1375 |
"حقول هيكل I<seccomp_notif_resp>. يجب على المشرف ضبط حقول هذا الهيكل كما يلي:" |
| 1376 |
|
| 1377 |
#. type: Plain text |
| 1378 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1379 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1380 |
msgid "I<flags> does not contain B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>." |
| 1381 |
msgstr "لا يحتوي I<flags> على B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>." |
| 1382 |
|
| 1383 |
#. type: Plain text |
| 1384 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1385 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1386 |
msgid "" |
| 1387 |
"I<error> is set either to 0 for a spoofed \"success\" return or to a " |
| 1388 |
"negative error number for a spoofed \"failure\" return. In the former case, " |
| 1389 |
"the kernel causes the target's system call to return the value specified in " |
| 1390 |
"the I<val> field. In the latter case, the kernel causes the target's system " |
| 1391 |
"call to return -1, and I<errno> is assigned the negated I<error> value." |
| 1392 |
msgstr "" |
| 1393 |
"يُضبط I<error> إما على 0 لرد \"نجاح\" زائف أو على رقم خطأ سالب لرد \"فشل\" " |
| 1394 |
"زائف. في الحالة الأولى، تجعل النواة استدعاء نظام الهدف يُرجع القيمة المحددة " |
| 1395 |
"في حقل I<val>. وفي الحالة الثانية، تجعل النواة استدعاء نظام الهدف يُرجع -1، " |
| 1396 |
"ويُسند إلى I<errno> قيمة I<error> المنفية." |
| 1397 |
|
| 1398 |
# |
| 1399 |
# |
| 1400 |
# |
| 1401 |
#. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1402 |
#. FIXME |
| 1403 |
#. Kees Cook suggested: |
| 1404 |
#. Strictly speaking, this is architecture specific, but |
| 1405 |
#. all architectures do it this way. Should seccomp enforce |
| 1406 |
#. val == 0 when err != 0 ? |
| 1407 |
#. Christian Brauner |
| 1408 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1409 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1410 |
#. pointed out correctly above). |
| 1411 |
#. type: Plain text |
| 1412 |
#. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1413 |
#. FIXME |
| 1414 |
#. Kees Cook suggested: |
| 1415 |
#. Strictly speaking, this is architecture specific, but |
| 1416 |
#. all architectures do it this way. Should seccomp enforce |
| 1417 |
#. val == 0 when err != 0 ? |
| 1418 |
#. Christian Brauner |
| 1419 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1420 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1421 |
#. pointed out correctly above). |
| 1422 |
#. type: Plain text |
| 1423 |
#. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1424 |
#. FIXME |
| 1425 |
#. Kees Cook suggested: |
| 1426 |
#. Strictly speaking, this is architecture specific, but |
| 1427 |
#. all architectures do it this way. Should seccomp enforce |
| 1428 |
#. val == 0 when err != 0 ? |
| 1429 |
#. Christian Brauner |
| 1430 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1431 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1432 |
#. pointed out correctly above). |
| 1433 |
#. type: Plain text |
| 1434 |
#. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1435 |
#. FIXME |
| 1436 |
#. Kees Cook suggested: |
| 1437 |
#. Strictly speaking, this is architecture specific, but |
| 1438 |
#. all architectures do it this way. Should seccomp enforce |
| 1439 |
#. val == 0 when err != 0 ? |
| 1440 |
#. Christian Brauner |
| 1441 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1442 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1443 |
#. pointed out correctly above). |
| 1444 |
#. type: Plain text |
| 1445 |
#. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1446 |
#. FIXME |
| 1447 |
#. Kees Cook suggested: |
| 1448 |
#. Strictly speaking, this is architecture specific, but |
| 1449 |
#. all architectures do it this way. Should seccomp enforce |
| 1450 |
#. val == 0 when err != 0 ? |
| 1451 |
#. Christian Brauner |
| 1452 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1453 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1454 |
#. pointed out correctly above). |
| 1455 |
#. type: Plain text |
| 1456 |
#. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1457 |
#. FIXME |
| 1458 |
#. Kees Cook suggested: |
| 1459 |
#. Strictly speaking, this is architecture specific, but |
| 1460 |
#. all architectures do it this way. Should seccomp enforce |
| 1461 |
#. val == 0 when err != 0 ? |
| 1462 |
#. Christian Brauner |
| 1463 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1464 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1465 |
#. pointed out correctly above). |
| 1466 |
#. type: Plain text |
| 1467 |
#. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1468 |
#. FIXME |
| 1469 |
#. Kees Cook suggested: |
| 1470 |
#. Strictly speaking, this is architecture specific, but |
| 1471 |
#. all architectures do it this way. Should seccomp enforce |
| 1472 |
#. val == 0 when err != 0 ? |
| 1473 |
#. Christian Brauner |
| 1474 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1475 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1476 |
#. pointed out correctly above). |
| 1477 |
#. type: Plain text |
| 1478 |
#. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 1479 |
#. FIXME |
| 1480 |
#. Kees Cook suggested: |
| 1481 |
#. Strictly speaking, this is architecture specific, but |
| 1482 |
#. all architectures do it this way. Should seccomp enforce |
| 1483 |
#. val == 0 when err != 0 ? |
| 1484 |
#. Christian Brauner |
| 1485 |
#. Feels like it should, at least for the SEND ioctl where we already |
| 1486 |
#. verify that val and err are both 0 when CONTINUE is specified (as you |
| 1487 |
#. pointed out correctly above). |
| 1488 |
#. type: Plain text |
| 1489 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1490 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1491 |
msgid "" |
| 1492 |
"I<val> is set to a value that will be used as the return value for a spoofed " |
| 1493 |
"\"success\" return for the target's system call. The value in this field is " |
| 1494 |
"ignored if the I<error> field contains a nonzero value." |
| 1495 |
msgstr "" |
| 1496 |
"يُضبط I<val> على قيمة ستُستخدم كقيمة مرجعة لرد \"نجاح\" زائف لاستدعاء نظام " |
| 1497 |
"الهدف. تُتجاهل القيمة في هذا الحقل إذا احتوى حقل I<error> على قيمة غير صفرية." |
| 1498 |
|
| 1499 |
#. type: TP |
| 1500 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1501 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1502 |
#, no-wrap |
| 1503 |
msgid "B<EINPROGRESS>" |
| 1504 |
msgstr "B<EINPROGRESS>" |
| 1505 |
|
| 1506 |
#. type: Plain text |
| 1507 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1508 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1509 |
msgid "A response to this notification has already been sent." |
| 1510 |
msgstr "أُرسل رد على هذا الإشعار بالفعل." |
| 1511 |
|
| 1512 |
#. type: TP |
| 1513 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1514 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1515 |
#, no-wrap |
| 1516 |
msgid "B<EINVAL>" |
| 1517 |
msgstr "B<EINVAL>" |
| 1518 |
|
| 1519 |
#. type: Plain text |
| 1520 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1521 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1522 |
msgid "An invalid value was specified in the I<flags field.>" |
| 1523 |
msgstr "حُددت قيمة غير صالحة في حقل I<flags>." |
| 1524 |
|
| 1525 |
#. type: Plain text |
| 1526 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1527 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1528 |
msgid "" |
| 1529 |
"The I<flags> field contained B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>, and the " |
| 1530 |
"I<error> or I<val> field was not zero." |
| 1531 |
msgstr "" |
| 1532 |
"احتوى حقل I<flags> على B<SECCOMP_USER_NOTIF_FLAG_CONTINUE>، ولم يكن حقل " |
| 1533 |
"I<error> أو I<val> صفراً." |
| 1534 |
|
| 1535 |
#. type: Plain text |
| 1536 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1537 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1538 |
msgid "" |
| 1539 |
"The blocked system call in the target has been interrupted by a signal " |
| 1540 |
"handler or the target has terminated." |
| 1541 |
msgstr "" |
| 1542 |
"قوطع استدعاء النظام المحجوب في الهدف بواسطة معالج إشارة أو أن الهدف قد انتهى." |
| 1543 |
|
| 1544 |
#. type: SS |
| 1545 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1546 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1547 |
#, no-wrap |
| 1548 |
msgid "SECCOMP_IOCTL_NOTIF_ADDFD" |
| 1549 |
msgstr "SECCOMP_IOCTL_NOTIF_ADDFD" |
| 1550 |
|
| 1551 |
#. type: Plain text |
| 1552 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1553 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1554 |
msgid "" |
| 1555 |
"The B<SECCOMP_IOCTL_NOTIF_ADDFD> operation (available since Linux 5.9) " |
| 1556 |
"allows the supervisor to install a file descriptor into the target's file " |
| 1557 |
"descriptor table. Much like the use of B<SCM_RIGHTS> messages described in " |
| 1558 |
"B<unix>(7), this operation is semantically equivalent to duplicating a file " |
| 1559 |
"descriptor from the supervisor's file descriptor table into the target's " |
| 1560 |
"file descriptor table." |
| 1561 |
msgstr "" |
| 1562 |
"تسمح عملية B<SECCOMP_IOCTL_NOTIF_ADDFD> (المتوفرة منذ لينكس 5.9) للمشرف " |
| 1563 |
"بتثبيت واصف ملف في جدول واصفات ملفات الهدف. تشبه هذه العملية إلى حد كبير " |
| 1564 |
"استخدام رسائل B<SCM_RIGHTS> الموصوفة في B<unix>(7)، وهي مكافئة دلالياً لنسخ " |
| 1565 |
"واصف ملف من جدول واصفات ملفات المشرف إلى جدول واصفات ملفات الهدف." |
| 1566 |
|
| 1567 |
#. type: Plain text |
| 1568 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1569 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1570 |
msgid "" |
| 1571 |
"The B<SECCOMP_IOCTL_NOTIF_ADDFD> operation permits the supervisor to emulate " |
| 1572 |
"a target system call (such as B<socket>(2) or B<openat>(2)) that generates " |
| 1573 |
"a file descriptor. The supervisor can perform the system call that " |
| 1574 |
"generates the file descriptor (and associated open file description) and " |
| 1575 |
"then use this operation to allocate a file descriptor that refers to the " |
| 1576 |
"same open file description in the target. (For an explanation of open file " |
| 1577 |
"descriptions, see B<open>(2).)" |
| 1578 |
msgstr "" |
| 1579 |
"تسمح عملية B<SECCOMP_IOCTL_NOTIF_ADDFD> للمشرف بمحاكاة استدعاء نظام للهدف " |
| 1580 |
"(مثل B<socket>(2) أو B<openat>(2)) الذي يُولد واصف ملف. يمكن للمشرف تنفيذ " |
| 1581 |
"استدعاء النظام الذي يُولد واصف الملف (ووصف الملف المفتوح المرتبط به) ثم " |
| 1582 |
"استخدام هذه العملية لتخصيص واصف ملف يشير إلى نفس وصف الملف المفتوح في الهدف. " |
| 1583 |
"(لشرح أوصاف الملفات المفتوحة، انظر B<open>(2))." |
| 1584 |
|
| 1585 |
#. type: Plain text |
| 1586 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1587 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1588 |
msgid "" |
| 1589 |
"Once this operation has been performed, the supervisor can close its copy of " |
| 1590 |
"the file descriptor." |
| 1591 |
msgstr "بمجرد تنفيذ هذه العملية، يمكن للمشرف إغلاق نسخته من واصف الملف." |
| 1592 |
|
| 1593 |
#. type: Plain text |
| 1594 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1595 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1596 |
msgid "" |
| 1597 |
"In the target, the received file descriptor is subject to the same Linux " |
| 1598 |
"Security Module (LSM) checks as are applied to a file descriptor that is " |
| 1599 |
"received in an B<SCM_RIGHTS> ancillary message. If the file descriptor " |
| 1600 |
"refers to a socket, it inherits the cgroup version 1 network controller " |
| 1601 |
"settings (I<classid> and I<netprioidx>) of the target." |
| 1602 |
msgstr "" |
| 1603 |
"في الهدف، يخضع واصف الملف المستلم لنفس فحوصات وحدة أمن لينكس (LSM) التي تُطبق " |
| 1604 |
"على واصف ملف مستلم في رسالة B<SCM_RIGHTS> إضافية. إذا كان واصف الملف يشير " |
| 1605 |
"إلى مقبس، فإنه يرث إعدادات متحكم الشبكة للمجموعة التقسيمية (cgroup) الإصدار " |
| 1606 |
"1 (I<classid> و I<netprioidx>) الخاصة بالهدف." |
| 1607 |
|
| 1608 |
#. type: Plain text |
| 1609 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1610 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1611 |
msgid "" |
| 1612 |
"The third B<ioctl>(2) argument is a pointer to a structure of the following " |
| 1613 |
"form:" |
| 1614 |
msgstr "وسيط B<ioctl>(2) الثالث هو مؤشر إلى هيكل بالشكل التالي:" |
| 1615 |
|
| 1616 |
#. type: Plain text |
| 1617 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1618 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1619 |
#, no-wrap |
| 1620 |
msgid "" |
| 1621 |
"struct seccomp_notif_addfd {\n" |
| 1622 |
" __u64 id; /* Cookie value */\n" |
| 1623 |
" __u32 flags; /* Flags */\n" |
| 1624 |
" __u32 srcfd; /* Local file descriptor number */\n" |
| 1625 |
" __u32 newfd; /* 0 or desired file descriptor\n" |
| 1626 |
" number in target */\n" |
| 1627 |
" __u32 newfd_flags; /* Flags to set on target file\n" |
| 1628 |
" descriptor */\n" |
| 1629 |
"};\n" |
| 1630 |
msgstr "" |
| 1631 |
"struct seccomp_notif_addfd {\n" |
| 1632 |
" __u64 id; /* قيمة الكوكيز */\n" |
| 1633 |
" __u32 flags; /* اللصائق */\n" |
| 1634 |
" __u32 srcfd; /* رقم واصف الملف المحلي */\n" |
| 1635 |
" __u32 newfd; /* 0 أو رقم واصف الملف المطلوب\n" |
| 1636 |
" في الهدف */\n" |
| 1637 |
" __u32 newfd_flags; /* اللصائق المراد ضبطها على واصف ملف\n" |
| 1638 |
" الهدف */\n" |
| 1639 |
"};\n" |
| 1640 |
|
| 1641 |
#. type: Plain text |
| 1642 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1643 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1644 |
msgid "" |
| 1645 |
"This field should be set to the notification ID (cookie value) that was " |
| 1646 |
"obtained via B<SECCOMP_IOCTL_NOTIF_RECV>." |
| 1647 |
msgstr "" |
| 1648 |
"يجب ضبط هذا الحقل على معرف الإشعار (قيمة الكوكيز) التي حُصل عليها عبر " |
| 1649 |
"B<SECCOMP_IOCTL_NOTIF_RECV>." |
| 1650 |
|
| 1651 |
#. type: Plain text |
| 1652 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1653 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1654 |
msgid "" |
| 1655 |
"This field is a bit mask of flags that modify the behavior of the " |
| 1656 |
"operation. Currently, only one flag is supported:" |
| 1657 |
msgstr "" |
| 1658 |
"هذا الحقل عبارة عن قناع بتات من اللصائق التي تعدل سلوك العملية. حالياً، تُدعم " |
| 1659 |
"لصيقة واحدة فقط:" |
| 1660 |
|
| 1661 |
#. type: TP |
| 1662 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1663 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1664 |
#, no-wrap |
| 1665 |
msgid "B<SECCOMP_ADDFD_FLAG_SETFD>" |
| 1666 |
msgstr "B<SECCOMP_ADDFD_FLAG_SETFD>" |
| 1667 |
|
| 1668 |
#. type: Plain text |
| 1669 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1670 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1671 |
msgid "" |
| 1672 |
"When allocating the file descriptor in the target, use the file descriptor " |
| 1673 |
"number specified in the I<newfd> field." |
| 1674 |
msgstr "" |
| 1675 |
"عند تخصيص واصف الملف في الهدف، استخدم رقم واصف الملف المحدد في حقل I<newfd>." |
| 1676 |
|
| 1677 |
#. type: TP |
| 1678 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1679 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1680 |
#, no-wrap |
| 1681 |
msgid "B<SECCOMP_ADDFD_FLAG_SEND> (since Linux 5.14)" |
| 1682 |
msgstr "B<SECCOMP_ADDFD_FLAG_SEND> (منذ لينكس 5.14)" |
| 1683 |
|
| 1684 |
#. commit 0ae71c7720e3ae3aabd2e8a072d27f7bd173d25c |
| 1685 |
#. type: Plain text |
| 1686 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1687 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1688 |
msgid "" |
| 1689 |
"Perform the equivalent of B<SECCOMP_IOCTL_NOTIF_ADDFD> plus " |
| 1690 |
"B<SECCOMP_IOCTL_NOTIF_SEND> as an atomic operation. On successful " |
| 1691 |
"invocation, the target process's I<errno> will be 0 and the return value " |
| 1692 |
"will be the file descriptor number that was allocated in the target. If " |
| 1693 |
"allocating the file descriptor in the target fails, the target's system call " |
| 1694 |
"continues to be blocked until a successful response is sent." |
| 1695 |
msgstr "" |
| 1696 |
"تنفيذ ما يعادل B<SECCOMP_IOCTL_NOTIF_ADDFD> بالإضافة إلى " |
| 1697 |
"B<SECCOMP_IOCTL_NOTIF_SEND> كعملية ذرية. عند الاستدعاء الناجح، سيكون " |
| 1698 |
"I<errno> لعملية الهدف 0 وستكون القيمة المرجعة هي رقم واصف الملف الذي خُصص في " |
| 1699 |
"الهدف. إذا فشل تخصيص واصف الملف في الهدف، يستمر حجب استدعاء نظام الهدف حتى " |
| 1700 |
"يُرسل رد ناجح." |
| 1701 |
|
| 1702 |
#. type: TP |
| 1703 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1704 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1705 |
#, no-wrap |
| 1706 |
msgid "I<srcfd>" |
| 1707 |
msgstr "I<srcfd>" |
| 1708 |
|
| 1709 |
#. type: Plain text |
| 1710 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1711 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1712 |
msgid "" |
| 1713 |
"This field should be set to the number of the file descriptor in the " |
| 1714 |
"supervisor that is to be duplicated." |
| 1715 |
msgstr "يجب ضبط هذا الحقل على رقم واصف الملف في المشرف المراد نسخه." |
| 1716 |
|
| 1717 |
#. type: TP |
| 1718 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1719 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1720 |
#, no-wrap |
| 1721 |
msgid "I<newfd>" |
| 1722 |
msgstr "I<newfd>" |
| 1723 |
|
| 1724 |
#. type: Plain text |
| 1725 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1726 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1727 |
msgid "" |
| 1728 |
"This field determines which file descriptor number is allocated in the " |
| 1729 |
"target. If the B<SECCOMP_ADDFD_FLAG_SETFD> flag is set, then this field " |
| 1730 |
"specifies which file descriptor number should be allocated. If this file " |
| 1731 |
"descriptor number is already open in the target, it is atomically closed and " |
| 1732 |
"reused. If the descriptor duplication fails due to an LSM check, or if " |
| 1733 |
"I<srcfd> is not a valid file descriptor, the file descriptor I<newfd> will " |
| 1734 |
"not be closed in the target process." |
| 1735 |
msgstr "" |
| 1736 |
"يحدد هذا الحقل رقم واصف الملف الذي يُخصص في الهدف. إذا ضُبطت الوسم " |
| 1737 |
"B<SECCOMP_ADDFD_FLAG_SETFD>، فإن هذا الحقل يحدد رقم واصف الملف الذي يجب " |
| 1738 |
"تخصيصه. إذا كان رقم واصف الملف هذا مفتوحاً بالفعل في الهدف، فسيُغلق ويُعاد " |
| 1739 |
"استخدامه ذرياً. إذا فشل نسخ الواصف بسبب فحص LSM، أو إذا لم يكن I<srcfd> واصف " |
| 1740 |
"ملف صالحاً، فلن يُغلق واصف الملف I<newfd> في عملية الهدف." |
| 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 |
"If the B<SECCOMP_ADDFD_FLAG_SETFD> flag it not set, then this field must be " |
| 1747 |
"0, and the kernel allocates the lowest unused file descriptor number in the " |
| 1748 |
"target." |
| 1749 |
msgstr "" |
| 1750 |
"إذا لم تُضبط الوسم B<SECCOMP_ADDFD_FLAG_SETFD>، فيجب أن يكون هذا الحقل 0، " |
| 1751 |
"وتقوم النواة بتخصيص أقل رقم واصف ملف غير مستخدم في الهدف." |
| 1752 |
|
| 1753 |
#. type: TP |
| 1754 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1755 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1756 |
#, no-wrap |
| 1757 |
msgid "I<newfd_flags>" |
| 1758 |
msgstr "I<newfd_flags>" |
| 1759 |
|
| 1760 |
#. type: Plain text |
| 1761 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1762 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1763 |
msgid "" |
| 1764 |
"This field is a bit mask specifying flags that should be set on the file " |
| 1765 |
"descriptor that is received in the target process. Currently, only the " |
| 1766 |
"following flag is implemented:" |
| 1767 |
msgstr "" |
| 1768 |
"هذا الحقل عبارة عن قناع بتات يحدد اللصائق التي يجب ضبطها على واصف الملف " |
| 1769 |
"المستلم في عملية الهدف. حالياً، تُنفذ اللصيقة التالية فقط:" |
| 1770 |
|
| 1771 |
#. type: TP |
| 1772 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1773 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1774 |
#, no-wrap |
| 1775 |
msgid "B<O_CLOEXEC>" |
| 1776 |
msgstr "B<O_CLOEXEC>" |
| 1777 |
|
| 1778 |
#. type: Plain text |
| 1779 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1780 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1781 |
msgid "Set the close-on-exec flag on the received file descriptor." |
| 1782 |
msgstr "ضبط وسم الغلق عند التنفيذ على واصف الملف المستلم." |
| 1783 |
|
| 1784 |
#. type: Plain text |
| 1785 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1786 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1787 |
msgid "" |
| 1788 |
"On success, this B<ioctl>(2) call returns the number of the file descriptor " |
| 1789 |
"that was allocated in the target. Assuming that the emulated system call is " |
| 1790 |
"one that returns a file descriptor as its function result (e.g., " |
| 1791 |
"B<socket>(2)), this value can be used as the return value (I<resp.val>) " |
| 1792 |
"that is supplied in the response that is subsequently sent with the " |
| 1793 |
"B<SECCOMP_IOCTL_NOTIF_SEND> operation." |
| 1794 |
msgstr "" |
| 1795 |
"عند النجاح، يُرجع استدعاء B<ioctl>(2) هذا رقم واصف الملف الذي خُصص في الهدف. " |
| 1796 |
"بافتراض أن استدعاء النظام الذي تمت محاكاته هو استدعاء يُرجع واصف ملف كتيجة " |
| 1797 |
"لدالته (مثل B<socket>(2))، يمكن استخدام هذه القيمة كقيمة مرجعة (I<resp.val>) " |
| 1798 |
"التي تُوفر في الرد الذي يُرسل لاحقًا بعملية B<SECCOMP_IOCTL_NOTIF_SEND>." |
| 1799 |
|
| 1800 |
#. type: Plain text |
| 1801 |
#: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 1802 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 1803 |
msgid "On error, -1 is returned and I<errno> is set to indicate the error." |
| 1804 |
msgstr "عند حدوث خطأ، يُرجع -1 ويُضبط I<errno> للإشارة إلى الخطأ." |
| 1805 |
|
| 1806 |
#. type: Plain text |
| 1807 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1808 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1809 |
msgid "This operation can fail with the following errors:" |
| 1810 |
msgstr "يمكن أن تفشل هذه العملية بالأخطاء التالية:" |
| 1811 |
|
| 1812 |
#. type: TP |
| 1813 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1814 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1815 |
#, no-wrap |
| 1816 |
msgid "B<EBADF>" |
| 1817 |
msgstr "B<EBADF>" |
| 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 |
"Allocating the file descriptor in the target would cause the target's " |
| 1824 |
"B<RLIMIT_NOFILE> limit to be exceeded (see B<getrlimit>(2))." |
| 1825 |
msgstr "" |
| 1826 |
"سيؤدي تخصيص واصف الملف في الهدف إلى تجاوز حد B<RLIMIT_NOFILE> للهدف (انظر " |
| 1827 |
"B<getrlimit>(2))." |
| 1828 |
|
| 1829 |
#. type: TP |
| 1830 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1831 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1832 |
#, no-wrap |
| 1833 |
msgid "B<EBUSY>" |
| 1834 |
msgstr "B<EBUSY>" |
| 1835 |
|
| 1836 |
#. type: Plain text |
| 1837 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1838 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1839 |
msgid "" |
| 1840 |
"If the flag B<SECCOMP_IOCTL_NOTIF_SEND> is used, this means the operation " |
| 1841 |
"can't proceed until other B<SECCOMP_IOCTL_NOTIF_ADDFD> requests are " |
| 1842 |
"processed." |
| 1843 |
msgstr "" |
| 1844 |
"إذا استُخدمت اللصيقة B<SECCOMP_IOCTL_NOTIF_SEND>، فهذا يعني أن العملية لا " |
| 1845 |
"يمكن أن تستمر حتى تُعالج طلبات B<SECCOMP_IOCTL_NOTIF_ADDFD> الأخرى." |
| 1846 |
|
| 1847 |
#. type: Plain text |
| 1848 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1849 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1850 |
msgid "" |
| 1851 |
"The user-space notification specified in the I<id> field exists but has not " |
| 1852 |
"yet been fetched (by a B<SECCOMP_IOCTL_NOTIF_RECV>) or has already been " |
| 1853 |
"responded to (by a B<SECCOMP_IOCTL_NOTIF_SEND>)." |
| 1854 |
msgstr "" |
| 1855 |
"إشعار مساحة المستخدم المحدد في حقل I<id> موجود ولكنه لم يُجلب بعد (بواسطة " |
| 1856 |
"B<SECCOMP_IOCTL_NOTIF_RECV>) أو تم الرد عليه بالفعل (بواسطة " |
| 1857 |
"B<SECCOMP_IOCTL_NOTIF_SEND>)." |
| 1858 |
|
| 1859 |
#. type: Plain text |
| 1860 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1861 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1862 |
msgid "" |
| 1863 |
"An invalid flag was specified in the I<flags> or I<newfd_flags> field, or " |
| 1864 |
"the I<newfd> field is nonzero and the B<SECCOMP_ADDFD_FLAG_SETFD> flag was " |
| 1865 |
"not specified in the I<flags> field." |
| 1866 |
msgstr "" |
| 1867 |
"حُددت لصيقة غير صالحة في حقل I<flags> أو I<newfd_flags>، أو أن حقل I<newfd> " |
| 1868 |
"غير صفري ولم تُحدد اللصيقة B<SECCOMP_ADDFD_FLAG_SETFD> في حقل I<flags>." |
| 1869 |
|
| 1870 |
#. type: TP |
| 1871 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1872 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1873 |
#, no-wrap |
| 1874 |
msgid "B<EMFILE>" |
| 1875 |
msgstr "B<EMFILE>" |
| 1876 |
|
| 1877 |
#. type: Plain text |
| 1878 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1879 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1880 |
msgid "" |
| 1881 |
"The file descriptor number specified in I<newfd> exceeds the limit specified " |
| 1882 |
"in I</proc/sys/fs/nr_open>." |
| 1883 |
msgstr "" |
| 1884 |
"يتجاوز رقم واصف الملف المحدد في I<newfd> الحد المحدد في I</proc/sys/fs/" |
| 1885 |
"nr_open>." |
| 1886 |
|
| 1887 |
#. type: Plain text |
| 1888 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1889 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1890 |
msgid "" |
| 1891 |
"Here is some sample code (with error handling omitted) that uses the " |
| 1892 |
"B<SECCOMP_ADDFD_FLAG_SETFD> operation (here, to emulate a call to " |
| 1893 |
"B<openat>(2)):" |
| 1894 |
msgstr "" |
| 1895 |
"إليك بعض التعليمات البرمجية النموذجية (مع حذف معالجة الأخطاء) التي تستخدم " |
| 1896 |
"عملية B<SECCOMP_ADDFD_FLAG_SETFD> (هنا، لمحاكاة استدعاء لـ B<openat>(2)):" |
| 1897 |
|
| 1898 |
#. type: Plain text |
| 1899 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 1900 |
#: opensuse-tumbleweed |
| 1901 |
#, no-wrap |
| 1902 |
msgid "" |
| 1903 |
"int fd, removeFd;\n" |
| 1904 |
"\\&\n" |
| 1905 |
"fd = openat(req-E<gt>data.args[0], path, req-E<gt>data.args[2],\n" |
| 1906 |
" req-E<gt>data.args[3]);\n" |
| 1907 |
"\\&\n" |
| 1908 |
"struct seccomp_notif_addfd addfd;\n" |
| 1909 |
"addfd.id = req-E<gt>id; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n" |
| 1910 |
"addfd.srcfd = fd;\n" |
| 1911 |
"addfd.newfd = 0;\n" |
| 1912 |
"addfd.flags = 0;\n" |
| 1913 |
"addfd.newfd_flags = O_CLOEXEC;\n" |
| 1914 |
"\\&\n" |
| 1915 |
"targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" |
| 1916 |
"\\&\n" |
| 1917 |
"close(fd); /* No longer needed in supervisor */\n" |
| 1918 |
"\\&\n" |
| 1919 |
"struct seccomp_notif_resp *resp;\n" |
| 1920 |
" /* Code to allocate 'resp' omitted */\n" |
| 1921 |
"resp-E<gt>id = req-E<gt>id;\n" |
| 1922 |
"resp-E<gt>error = 0; /* \"Success\" */\n" |
| 1923 |
"resp-E<gt>val = targetFd;\n" |
| 1924 |
"resp-E<gt>flags = 0;\n" |
| 1925 |
"ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" |
| 1926 |
msgstr "" |
| 1927 |
"int fd, removeFd;\n" |
| 1928 |
"\\&\n" |
| 1929 |
"fd = openat(req-E<gt>data.args[0], path, req-E<gt>data.args[2],\n" |
| 1930 |
" req-E<gt>data.args[3]);\n" |
| 1931 |
"\\&\n" |
| 1932 |
"struct seccomp_notif_addfd addfd;\n" |
| 1933 |
"addfd.id = req-E<gt>id; /* الكوكيز من SECCOMP_IOCTL_NOTIF_RECV */\n" |
| 1934 |
"addfd.srcfd = fd;\n" |
| 1935 |
"addfd.newfd = 0;\n" |
| 1936 |
"addfd.flags = 0;\n" |
| 1937 |
"addfd.newfd_flags = O_CLOEXEC;\n" |
| 1938 |
"\\&\n" |
| 1939 |
"targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" |
| 1940 |
"\\&\n" |
| 1941 |
"close(fd); /* لم تعد هناك حاجة إليه في المشرف */\n" |
| 1942 |
"\\&\n" |
| 1943 |
"struct seccomp_notif_resp *resp;\n" |
| 1944 |
" /* كود تخصيص 'resp' محذوف */\n" |
| 1945 |
"resp-E<gt>id = req-E<gt>id;\n" |
| 1946 |
"resp-E<gt>error = 0; /* \"نجاح\" */\n" |
| 1947 |
"resp-E<gt>val = targetFd;\n" |
| 1948 |
"resp-E<gt>flags = 0;\n" |
| 1949 |
"ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" |
| 1950 |
|
| 1951 |
#. type: SH |
| 1952 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1953 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1954 |
#, no-wrap |
| 1955 |
msgid "NOTES" |
| 1956 |
msgstr "ملاحظات" |
| 1957 |
|
| 1958 |
#. type: Plain text |
| 1959 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1960 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1961 |
msgid "" |
| 1962 |
"One example use case for the user-space notification mechanism is to allow a " |
| 1963 |
"container manager (a process which is typically running with more privilege " |
| 1964 |
"than the processes inside the container) to mount block devices or create " |
| 1965 |
"device nodes for the container. The mount use case provides an example of " |
| 1966 |
"where the B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> B<ioctl>(2) operation is " |
| 1967 |
"useful. Upon receiving a notification for the B<mount>(2) system call, the " |
| 1968 |
"container manager (the \"supervisor\") can distinguish a request to mount a " |
| 1969 |
"block filesystem (which would not be possible for a \"target\" process " |
| 1970 |
"inside the container) and mount that file system. If, on the other hand, " |
| 1971 |
"the container manager detects that the operation could be performed by the " |
| 1972 |
"process inside the container (e.g., a mount of a B<tmpfs>(5) filesystem), " |
| 1973 |
"it can notify the kernel that the target process's B<mount>(2) system call " |
| 1974 |
"can continue." |
| 1975 |
msgstr "" |
| 1976 |
"أحد الأمثلة على حالة استخدام آلية إشعار مساحة المستخدم هو السماح لمدير " |
| 1977 |
"الحاوية (عملية تعمل عادةً بامتيازات أكثر من العمليات داخل الحاوية) بوصل " |
| 1978 |
"الأجهزة الكتلية أو إنشاء عقد الأجهزة للحاوية. توفر حالة استخدام الوصل مثالاً " |
| 1979 |
"على فائدة عملية B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> B<ioctl>(2). عند استلام " |
| 1980 |
"إشعار لاستدعاء النظام B<mount>(2)، يمكن لمدير الحاوية (\"المشرف\") التمييز " |
| 1981 |
"بين طلب لوصل نظام ملفات كتلي (والذي لن يكون ممكناً لعملية \"هدف\" داخل " |
| 1982 |
"الحاوية) ووصل نظام الملفات هذا. ومن ناحية أخرى، إذا اكتشف مدير الحاوية أن " |
| 1983 |
"العملية يمكن تنفيذها بواسطة العملية داخل الحاوية (على سبيل المثال، وصل نظام " |
| 1984 |
"ملفات B<tmpfs>(5))، فيمكنه إخطار النواة بأن استدعاء نظام B<mount>(2) لعملية " |
| 1985 |
"الهدف يمكن أن يستمر." |
| 1986 |
|
| 1987 |
#. type: SS |
| 1988 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1989 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1990 |
#, no-wrap |
| 1991 |
msgid "select()/poll()/epoll semantics" |
| 1992 |
msgstr "دلالات select()/poll()/epoll" |
| 1993 |
|
| 1994 |
#. type: Plain text |
| 1995 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1996 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1997 |
msgid "" |
| 1998 |
"The file descriptor returned when B<seccomp>(2) is employed with the " |
| 1999 |
"B<SECCOMP_FILTER_FLAG_NEW_LISTENER> flag can be monitored using B<poll>(2), " |
| 2000 |
"B<epoll>(7), and B<select>(2). These interfaces indicate that the file " |
| 2001 |
"descriptor is ready as follows:" |
| 2002 |
msgstr "" |
| 2003 |
"يمكن مراقبة واصف الملف المعاد عندما يُوظف B<seccomp>(2) مع العلم " |
| 2004 |
"B<SECCOMP_FILTER_FLAG_NEW_LISTENER> باستخدام B<poll>(2) و B<epoll>(7) و " |
| 2005 |
"B<select>(2). تشير هذه الواجهات إلى أن واصف الملف جاهز كما يلي:" |
| 2006 |
|
| 2007 |
#. type: Plain text |
| 2008 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2009 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2010 |
msgid "" |
| 2011 |
"When a notification is pending, these interfaces indicate that the file " |
| 2012 |
"descriptor is readable. Following such an indication, a subsequent " |
| 2013 |
"B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) will not block, returning either " |
| 2014 |
"information about a notification or else failing with the error B<EINTR> if " |
| 2015 |
"the target has been killed by a signal or its system call has been " |
| 2016 |
"interrupted by a signal handler." |
| 2017 |
msgstr "" |
| 2018 |
"عندما يكون الإشعار معلقاً، تشير هذه الواجهات إلى أن واصف الملف قابل للقراءة. " |
| 2019 |
"وعقب هذا المؤشر، لن تحظر عملية B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) " |
| 2020 |
"اللاحقة، حيث ستعيد إما معلومات حول الإشعار أو تفشل مع الخطأ B<EINTR> إذا قُتل " |
| 2021 |
"الهدف بواسطة إشارة أو قوطع استدعاء النظام الخاص به بواسطة معالج إشارة." |
| 2022 |
|
| 2023 |
#. type: Plain text |
| 2024 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2025 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2026 |
msgid "" |
| 2027 |
"After the notification has been received (i.e., by the " |
| 2028 |
"B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) operation), these interfaces " |
| 2029 |
"indicate that the file descriptor is writable, meaning that a notification " |
| 2030 |
"response can be sent using the B<SECCOMP_IOCTL_NOTIF_SEND> B<ioctl>(2) " |
| 2031 |
"operation." |
| 2032 |
msgstr "" |
| 2033 |
"بعد تلقي الإشعار (أي بواسطة عملية B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2))، " |
| 2034 |
"تشير هذه الواجهات إلى أن واصف الملف قابل للكتابة، مما يعني أنه يمكن إرسال " |
| 2035 |
"استجابة إشعار باستخدام عملية B<SECCOMP_IOCTL_NOTIF_SEND> B<ioctl>(2)." |
| 2036 |
|
| 2037 |
#. type: Plain text |
| 2038 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2039 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2040 |
msgid "" |
| 2041 |
"After the last thread using the filter has terminated and been reaped using " |
| 2042 |
"B<waitpid>(2) (or similar), the file descriptor indicates an end-of-file " |
| 2043 |
"condition (readable in B<select>(2); B<POLLHUP>/B<EPOLLHUP> in B<poll>(2)/ " |
| 2044 |
"B<epoll_wait>(2))." |
| 2045 |
msgstr "" |
| 2046 |
"بعد إنهاء آخر خيط يستخدم المرشح وحصده باستخدام B<waitpid>(2) (أو ما شابه)، " |
| 2047 |
"يشير واصف الملف إلى حالة نهاية الملف (قابل للقراءة في B<select>(2)؛ و " |
| 2048 |
"B<POLLHUP>/B<EPOLLHUP> في B<poll>(2)/ B<epoll_wait>(2))." |
| 2049 |
|
| 2050 |
#. type: SS |
| 2051 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2052 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2053 |
#, no-wrap |
| 2054 |
msgid "Design goals; use of SECCOMP_USER_NOTIF_FLAG_CONTINUE" |
| 2055 |
msgstr "أهداف التصميم؛ استخدام SECCOMP_USER_NOTIF_FLAG_CONTINUE" |
| 2056 |
|
| 2057 |
#. type: Plain text |
| 2058 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2059 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2060 |
msgid "" |
| 2061 |
"The intent of the user-space notification feature is to allow system calls " |
| 2062 |
"to be performed on behalf of the target. The target's system call should " |
| 2063 |
"either be handled by the supervisor or allowed to continue normally in the " |
| 2064 |
"kernel (where standard security policies will be applied)." |
| 2065 |
msgstr "" |
| 2066 |
"الغرض من ميزة إشعار مساحة المستخدم هو السماح بإجراء استدعاءات النظام نيابة " |
| 2067 |
"عن الهدف. ينبغي إما أن يتولى المشرف معالجة استدعاء نظام الهدف أو يُسمح له " |
| 2068 |
"بالاستمرار بشكل طبيعي في النواة (حيث ستُطبق سياسات الأمان القياسية)." |
| 2069 |
|
| 2070 |
#. type: Plain text |
| 2071 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2072 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2073 |
msgid "" |
| 2074 |
"B<Note well>: this mechanism must not be used to make security policy " |
| 2075 |
"decisions about the system call, which would be inherently race-prone for " |
| 2076 |
"reasons described next." |
| 2077 |
msgstr "" |
| 2078 |
"B<ملاحظة هامة>: يجب عدم استخدام هذه الآلية لاتخاذ قرارات سياسة الأمان بشأن " |
| 2079 |
"استدعاء النظام، وهو ما سيكون عرضة لسباق البيانات بطبيعته لأسباب موصوفة لاحقًا." |
| 2080 |
|
| 2081 |
#. type: Plain text |
| 2082 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2083 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2084 |
msgid "" |
| 2085 |
"The B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> flag must be used with caution. If " |
| 2086 |
"set by the supervisor, the target's system call will continue. However, " |
| 2087 |
"there is a time-of-check, time-of-use race here, since an attacker could " |
| 2088 |
"exploit the interval of time where the target is blocked waiting on the " |
| 2089 |
"\"continue\" response to do things such as rewriting the system call " |
| 2090 |
"arguments." |
| 2091 |
msgstr "" |
| 2092 |
"يجب استخدام العلم B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> بحذر. إذا ضبطه المشرف، " |
| 2093 |
"فسيستمر استدعاء نظام الهدف. ومع ذلك، يوجد سباق \"وقت التحقق مقابل وقت " |
| 2094 |
"الاستخدام\" هنا، حيث يمكن لمهاجم استغلال الفاصل الزمني الذي يكون فيه الهدف " |
| 2095 |
"محظوراً بانتظار استجابة \"الاستمرار\" للقيام بأمور مثل إعادة كتابة وسائط " |
| 2096 |
"استدعاء النظام." |
| 2097 |
|
| 2098 |
#. type: Plain text |
| 2099 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2100 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2101 |
msgid "" |
| 2102 |
"Note furthermore that a user-space notifier can be bypassed if the existing " |
| 2103 |
"filters allow the use of B<seccomp>(2) or B<prctl>(2) to install a filter " |
| 2104 |
"that returns an action value with a higher precedence than " |
| 2105 |
"B<SECCOMP_RET_USER_NOTIF> (see B<seccomp>(2))." |
| 2106 |
msgstr "" |
| 2107 |
"لاحظ علاوة على ذلك أنه يمكن تجاوز مُخطِر مساحة المستخدم إذا سمحت المرشحات " |
| 2108 |
"الحالية باستخدام B<seccomp>(2) أو B<prctl>(2) لتثبيت مرشح يعيد قيمة إجراء " |
| 2109 |
"ذات أسبقية أعلى من B<SECCOMP_RET_USER_NOTIF> (راجع B<seccomp>(2))." |
| 2110 |
|
| 2111 |
#. type: Plain text |
| 2112 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2113 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2114 |
msgid "" |
| 2115 |
"It should thus be absolutely clear that the seccomp user-space notification " |
| 2116 |
"mechanism B<can not> be used to implement a security policy! It should only " |
| 2117 |
"ever be used in scenarios where a more privileged process supervises the " |
| 2118 |
"system calls of a lesser privileged target to get around kernel-enforced " |
| 2119 |
"security restrictions when the supervisor deems this safe. In other words, " |
| 2120 |
"in order to continue a system call, the supervisor should be sure that " |
| 2121 |
"another security mechanism or the kernel itself will sufficiently block the " |
| 2122 |
"system call if its arguments are rewritten to something unsafe." |
| 2123 |
msgstr "" |
| 2124 |
"لذا ينبغي أن يكون واضحاً تماماً أن آلية إشعار مساحة مستخدم seccomp B<لا يمكن> " |
| 2125 |
"استخدامها لتنفيذ سياسة أمان! يجب استخدامها فقط في السيناريوهات التي تتوفر " |
| 2126 |
"فيها عملية أكثر امتيازاً تشرف على استدعاءات نظام هدف أقل امتيازاً للالتفاف على " |
| 2127 |
"قيود الأمان التي تفرضها النواة عندما يرى المشرف أن هذا آمن. وبعبارة أخرى، من " |
| 2128 |
"أجل مواصلة استدعاء نظام، يجب أن يتأكد المشرف من أن آلية أمان أخرى أو النواة " |
| 2129 |
"نفسها ستحظر استدعاء النظام بشكل كافٍ إذا أُعيدت كتابة وسائطه إلى شيء غير آمن." |
| 2130 |
|
| 2131 |
#. type: SS |
| 2132 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2133 |
#: opensuse-tumbleweed |
| 2134 |
#, no-wrap |
| 2135 |
msgid "Caveats regarding the use of" |
| 2136 |
msgstr "تحذيرات بشأن استخدام" |
| 2137 |
|
| 2138 |
#. type: Plain text |
| 2139 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2140 |
#: opensuse-tumbleweed |
| 2141 |
msgid "" |
| 2142 |
"I</proc/>tidI</mem> The discussion above noted the need to use the " |
| 2143 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> B<ioctl>(2) when opening the I</proc/>tidI</" |
| 2144 |
"mem> file of the target to avoid the possibility of accessing the memory of " |
| 2145 |
"the wrong process in the event that the target terminates and its ID is " |
| 2146 |
"recycled by another (unrelated) thread. However, the use of this " |
| 2147 |
"B<ioctl>(2) operation is also necessary in other situations, as explained " |
| 2148 |
"in the following paragraphs." |
| 2149 |
msgstr "" |
| 2150 |
"أشار النقاش أعلاه في I</proc/>tidI</mem> إلى الحاجة لاستخدام B<ioctl>(2) " |
| 2151 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> عند فتح ملف I</proc/>tidI</mem> الخاص بالهدف " |
| 2152 |
"لتجنب إمكانية الوصول إلى ذاكرة العملية الخاطئة في حال انتهاء الهدف وإعادة " |
| 2153 |
"تدوير معرفه بواسطة خيط آخر (غير ذي صلة). ومع ذلك، فإن استخدام عملية " |
| 2154 |
"B<ioctl>(2) هذه ضروري أيضًا في مواقف أخرى، كما هو موضح في الفقرات التالية." |
| 2155 |
|
| 2156 |
#. type: Plain text |
| 2157 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2158 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2159 |
msgid "" |
| 2160 |
"Consider the following scenario, where the supervisor tries to read the " |
| 2161 |
"pathname argument of a target's blocked B<mount>(2) system call:" |
| 2162 |
msgstr "" |
| 2163 |
"تأمل السيناريو التالي، حيث يحاول المشرف قراءة وسيط مسار استدعاء نظام " |
| 2164 |
"B<mount>(2) المحظور للهدف:" |
| 2165 |
|
| 2166 |
#. type: Plain text |
| 2167 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2168 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2169 |
msgid "" |
| 2170 |
"From one of its functions (I<func()>), the target calls B<mount>(2), which " |
| 2171 |
"triggers a user-space notification and causes the target to block." |
| 2172 |
msgstr "" |
| 2173 |
"من إحدى وظائفه (I<func()>)، يستدعي الهدف B<mount>(2)، مما يطلق إشعار مساحة " |
| 2174 |
"مستخدم ويتسبب في حظر الهدف." |
| 2175 |
|
| 2176 |
#. type: Plain text |
| 2177 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2178 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2179 |
msgid "" |
| 2180 |
"The supervisor receives the notification, opens I</proc/>tidI</mem>, and " |
| 2181 |
"(successfully) performs the B<SECCOMP_IOCTL_NOTIF_ID_VALID> check." |
| 2182 |
msgstr "" |
| 2183 |
"يتلقى المشرف الإشعار، ويفتح I</proc/>tidI</mem>، ويجري فحص " |
| 2184 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> (بنجاح)." |
| 2185 |
|
| 2186 |
#. type: Plain text |
| 2187 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2188 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2189 |
msgid "The target receives a signal, which causes the B<mount>(2) to abort." |
| 2190 |
msgstr "يتلقى الهدف إشارة، مما يتسبب في إجهاض B<mount>(2)." |
| 2191 |
|
| 2192 |
#. type: Plain text |
| 2193 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2194 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2195 |
msgid "The signal handler executes in the target, and returns." |
| 2196 |
msgstr "يُنفذ معالج الإشارة في الهدف، ثم يعود." |
| 2197 |
|
| 2198 |
#. type: Plain text |
| 2199 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2200 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2201 |
msgid "" |
| 2202 |
"Upon return from the handler, the execution of I<func()> resumes, and it " |
| 2203 |
"returns (and perhaps other functions are called, overwriting the memory that " |
| 2204 |
"had been used for the stack frame of I<func()>)." |
| 2205 |
msgstr "" |
| 2206 |
"عند العودة من المعالج، يُستأنف تنفيذ I<func()>)، وتعود (وربما تُستدعى وظائف " |
| 2207 |
"أخرى، مما يعيد الكتابة فوق الذاكرة التي كانت تُستخدم لإطار مكدس I<func()>)." |
| 2208 |
|
| 2209 |
#. type: Plain text |
| 2210 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2211 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2212 |
msgid "" |
| 2213 |
"Using the address provided in the notification information, the supervisor " |
| 2214 |
"reads from the target's memory location that used to contain the pathname." |
| 2215 |
msgstr "" |
| 2216 |
"باستخدام العنوان الموفر في معلومات الإشعار، يقرأ المشرف من موقع ذاكرة الهدف " |
| 2217 |
"الذي كان يحتوي على المسار." |
| 2218 |
|
| 2219 |
#. type: Plain text |
| 2220 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2221 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2222 |
msgid "" |
| 2223 |
"The supervisor now calls B<mount>(2) with some arbitrary bytes obtained in " |
| 2224 |
"the previous step." |
| 2225 |
msgstr "" |
| 2226 |
"يستدعي المشرف الآن B<mount>(2) مع بعض البايتات العشوائية التي حُصل عليها في " |
| 2227 |
"الخطوة السابقة." |
| 2228 |
|
| 2229 |
#. type: Plain text |
| 2230 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2231 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2232 |
msgid "" |
| 2233 |
"The conclusion from the above scenario is this: since the target's blocked " |
| 2234 |
"system call may be interrupted by a signal handler, the supervisor must be " |
| 2235 |
"written to expect that the target may abandon its system call at B<any> " |
| 2236 |
"time; in such an event, any information that the supervisor obtained from " |
| 2237 |
"the target's memory must be considered invalid." |
| 2238 |
msgstr "" |
| 2239 |
"الاستنتاج من السيناريو أعلاه هو كالتالي: بما أن استدعاء نظام الهدف المحظور " |
| 2240 |
"قد يقاطعه معالج إشارة، يجب كتابة المشرف ليتوقع أن الهدف قد يتخلى عن استدعاء " |
| 2241 |
"النظام الخاص به في B<أي> وقت؛ وفي مثل هذه الحالة، يجب اعتبار أي معلومات حصل " |
| 2242 |
"عليها المشرف من ذاكرة الهدف غير صالحة." |
| 2243 |
|
| 2244 |
#. type: Plain text |
| 2245 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2246 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2247 |
msgid "" |
| 2248 |
"To prevent such scenarios, every read from the target's memory must be " |
| 2249 |
"separated from use of the bytes so obtained by a " |
| 2250 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> check. In the above example, the check " |
| 2251 |
"would be placed between the two final steps. An example of such a check is " |
| 2252 |
"shown in EXAMPLES." |
| 2253 |
msgstr "" |
| 2254 |
"لمنع مثل هذه السيناريوهات، يجب فصل كل عملية قراءة من ذاكرة الهدف عن استخدام " |
| 2255 |
"البايتات التي حُصل عليها بفحص B<SECCOMP_IOCTL_NOTIF_ID_VALID>. وفي المثال " |
| 2256 |
"أعلاه، سيوضع الفحص بين الخطوتين الأخيرتين. يظهر مثال على هذا الفحص في قسم " |
| 2257 |
"\"أمثلة\"." |
| 2258 |
|
| 2259 |
#. type: Plain text |
| 2260 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2261 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2262 |
msgid "" |
| 2263 |
"Following on from the above, it should be clear that a write by the " |
| 2264 |
"supervisor into the target's memory can B<never> be considered safe." |
| 2265 |
msgstr "" |
| 2266 |
"بناءً على ما سبق، ينبغي أن يكون واضحاً أن الكتابة بواسطة المشرف في ذاكرة الهدف " |
| 2267 |
"لا يمكن B<أبداً> اعتبارها آمنة." |
| 2268 |
|
| 2269 |
#. type: SS |
| 2270 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2271 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2272 |
#, no-wrap |
| 2273 |
msgid "Caveats regarding blocking system calls" |
| 2274 |
msgstr "تحذيرات بشأن حظر استدعاءات النظام" |
| 2275 |
|
| 2276 |
#. type: Plain text |
| 2277 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2278 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2279 |
msgid "" |
| 2280 |
"Suppose that the target performs a blocking system call (e.g., " |
| 2281 |
"B<accept>(2)) that the supervisor should handle. The supervisor might then " |
| 2282 |
"in turn execute the same blocking system call." |
| 2283 |
msgstr "" |
| 2284 |
"افترض أن الهدف يجري استدعاء نظام حاصراً (مثل B<accept>(2)) ينبغي أن يعالجه " |
| 2285 |
"المشرف. قد ينفذ المشرف بدوره نفس استدعاء النظام الحاصر." |
| 2286 |
|
| 2287 |
#. type: Plain text |
| 2288 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2289 |
#: opensuse-tumbleweed |
| 2290 |
msgid "" |
| 2291 |
"In this scenario, it is important to note that if the target's system call " |
| 2292 |
"is now interrupted by a signal, the supervisor is I<not> informed of this. " |
| 2293 |
"If the supervisor does not take suitable steps to actively discover that the " |
| 2294 |
"target's system call has been canceled, various difficulties can occur. " |
| 2295 |
"Taking the example of B<accept>(2), the supervisor might remain blocked in " |
| 2296 |
"its B<accept>(2) holding a port number that the target (which, after the " |
| 2297 |
"interruption by the signal handler, perhaps closed its listening socket) " |
| 2298 |
"might expect to be able to reuse in a B<bind>(2) call." |
| 2299 |
msgstr "" |
| 2300 |
"في هذا السيناريو، من المهم ملاحظة أنه إذا قوطع استدعاء نظام الهدف الآن " |
| 2301 |
"بواسطة إشارة، فإن المشرف I<لا> يُخطر بذلك. وإذا لم يتخذ المشرف خطوات مناسبة " |
| 2302 |
"لاكتشاف إلغاء استدعاء نظام الهدف بنشاط، فقد تحدث صعوبات مختلفة. وبالأخذ " |
| 2303 |
"بمثال B<accept>(2)، قد يظل المشرف محظوراً في B<accept>(2) الخاص به ممسكاً برقم " |
| 2304 |
"منفذ قد يتوقع الهدف (الذي ربما أغلق مقبس الاستماع الخاص به بعد مقاطعته من " |
| 2305 |
"معالج الإشارة) أن يتمكن من إعادة استخدامه في استدعاء B<bind>(2)." |
| 2306 |
|
| 2307 |
#. type: Plain text |
| 2308 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2309 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2310 |
msgid "" |
| 2311 |
"Therefore, when the supervisor wishes to emulate a blocking system call, it " |
| 2312 |
"must do so in such a way that it gets informed if the target's system call " |
| 2313 |
"is interrupted by a signal handler. For example, if the supervisor itself " |
| 2314 |
"executes the same blocking system call, then it could employ a separate " |
| 2315 |
"thread that uses the B<SECCOMP_IOCTL_NOTIF_ID_VALID> operation to check if " |
| 2316 |
"the target is still blocked in its system call. Alternatively, in the " |
| 2317 |
"B<accept>(2) example, the supervisor might use B<poll>(2) to monitor both " |
| 2318 |
"the notification file descriptor (so as to discover when the target's " |
| 2319 |
"B<accept>(2) call has been interrupted) and the listening file descriptor " |
| 2320 |
"(so as to know when a connection is available)." |
| 2321 |
msgstr "" |
| 2322 |
"لذلك، عندما يرغب المشرف في محاكاة استدعاء نظام حاصر، يجب أن يفعل ذلك بطريقة " |
| 2323 |
"تجعله يُخطر إذا قوطع استدعاء نظام الهدف بواسطة معالج إشارة. على سبيل المثال، " |
| 2324 |
"إذا نفذ المشرف نفسه نفس استدعاء النظام الحاصر، فيمكنه حينئذٍ توظيف خيط منفصل " |
| 2325 |
"يستخدم عملية B<SECCOMP_IOCTL_NOTIF_ID_VALID> للتحقق مما إذا كان الهدف لا " |
| 2326 |
"يزال محظوراً في استدعاء النظام الخاص به. وبدلاً من ذلك، في مثال B<accept>(2)، " |
| 2327 |
"قد يستخدم المشرف B<poll>(2) لمراقبة كل من واصف ملف الإشعار (لاكتشاف وقت " |
| 2328 |
"مقاطعة استدعاء B<accept>(2) للهدف) وواصف ملف الاستماع (لمعرفة وقت توفر " |
| 2329 |
"اتصال)." |
| 2330 |
|
| 2331 |
#. type: Plain text |
| 2332 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2333 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2334 |
msgid "" |
| 2335 |
"If the target's system call is interrupted, the supervisor must take care to " |
| 2336 |
"release resources (e.g., file descriptors) that it acquired on behalf of " |
| 2337 |
"the target." |
| 2338 |
msgstr "" |
| 2339 |
"إذا قوطع استدعاء نظام الهدف، يجب على المشرف توخي الحذر لتحرير الموارد (مثل " |
| 2340 |
"واصفات الملفات) التي حصل عليها نيابة عن الهدف." |
| 2341 |
|
| 2342 |
#. type: SS |
| 2343 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2344 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2345 |
#, no-wrap |
| 2346 |
msgid "Interaction with SA_RESTART signal handlers" |
| 2347 |
msgstr "التفاعل مع معالجات إشارة SA_RESTART" |
| 2348 |
|
| 2349 |
#. type: Plain text |
| 2350 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2351 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2352 |
msgid "Consider the following scenario:" |
| 2353 |
msgstr "تأمل السيناريو التالي:" |
| 2354 |
|
| 2355 |
#. type: Plain text |
| 2356 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2357 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2358 |
msgid "" |
| 2359 |
"The target process has used B<sigaction>(2) to install a signal handler " |
| 2360 |
"with the B<SA_RESTART> flag." |
| 2361 |
msgstr "" |
| 2362 |
"استخدمت العملية الهدف B<sigaction>(2) لتثبيت معالج إشارة مع العلم " |
| 2363 |
"B<SA_RESTART>." |
| 2364 |
|
| 2365 |
#. type: Plain text |
| 2366 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2367 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2368 |
msgid "" |
| 2369 |
"The target has made a system call that triggered a seccomp user-space " |
| 2370 |
"notification and the target is currently blocked until the supervisor sends " |
| 2371 |
"a notification response." |
| 2372 |
msgstr "" |
| 2373 |
"أجرى الهدف استدعاء نظام أطلق إشعار مساحة مستخدم seccomp، والهدف محظور حالياً " |
| 2374 |
"حتى يرسل المشرف استجابة إشعار." |
| 2375 |
|
| 2376 |
#. type: Plain text |
| 2377 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2378 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2379 |
msgid "A signal is delivered to the target and the signal handler is executed." |
| 2380 |
msgstr "سُلّمت إشارة إلى الهدف ونُفذ معالج الإشارة." |
| 2381 |
|
| 2382 |
#. type: Plain text |
| 2383 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2384 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2385 |
msgid "" |
| 2386 |
"When (if) the supervisor attempts to send a notification response, the " |
| 2387 |
"B<SECCOMP_IOCTL_NOTIF_SEND> B<ioctl>(2)) operation will fail with the " |
| 2388 |
"B<ENOENT> error." |
| 2389 |
msgstr "" |
| 2390 |
"عندما (إذا) حاول المشرف إرسال استجابة إشعار، ستفشل عملية B<ioctl>(2) " |
| 2391 |
"B<SECCOMP_IOCTL_NOTIF_SEND> مع الخطأ B<ENOENT>." |
| 2392 |
|
| 2393 |
#. type: Plain text |
| 2394 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2395 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2396 |
msgid "" |
| 2397 |
"In this scenario, the kernel will restart the target's system call. " |
| 2398 |
"Consequently, the supervisor will receive another user-space notification. " |
| 2399 |
"Thus, depending on how many times the blocked system call is interrupted by " |
| 2400 |
"a signal handler, the supervisor may receive multiple notifications for the " |
| 2401 |
"same instance of a system call in the target." |
| 2402 |
msgstr "" |
| 2403 |
"في هذا السيناريو، ستعيد النواة تشغيل استدعاء نظام الهدف. وبناءً على ذلك، " |
| 2404 |
"سيتلقى المشرف إشعاراً آخر في مساحة المستخدم. وهكذا، اعتماداً على عدد مرات " |
| 2405 |
"مقاطعة استدعاء النظام المحظور بواسطة معالج إشارة، قد يتلقى المشرف إشعارات " |
| 2406 |
"متعددة لنفس نسخة استدعاء النظام في الهدف." |
| 2407 |
|
| 2408 |
# |
| 2409 |
# |
| 2410 |
#. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2411 |
#. FIXME |
| 2412 |
#. About the above, Kees Cook commented: |
| 2413 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2414 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2415 |
#. EINTR normally? |
| 2416 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2417 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2418 |
#. regard. :( |
| 2419 |
#. type: Plain text |
| 2420 |
#. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2421 |
#. FIXME |
| 2422 |
#. About the above, Kees Cook commented: |
| 2423 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2424 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2425 |
#. EINTR normally? |
| 2426 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2427 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2428 |
#. regard. :( |
| 2429 |
#. type: Plain text |
| 2430 |
#. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2431 |
#. FIXME |
| 2432 |
#. About the above, Kees Cook commented: |
| 2433 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2434 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2435 |
#. EINTR normally? |
| 2436 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2437 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2438 |
#. regard. :( |
| 2439 |
#. type: Plain text |
| 2440 |
#. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2441 |
#. FIXME |
| 2442 |
#. About the above, Kees Cook commented: |
| 2443 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2444 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2445 |
#. EINTR normally? |
| 2446 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2447 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2448 |
#. regard. :( |
| 2449 |
#. type: Plain text |
| 2450 |
#. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2451 |
#. FIXME |
| 2452 |
#. About the above, Kees Cook commented: |
| 2453 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2454 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2455 |
#. EINTR normally? |
| 2456 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2457 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2458 |
#. regard. :( |
| 2459 |
#. type: Plain text |
| 2460 |
#. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2461 |
#. FIXME |
| 2462 |
#. About the above, Kees Cook commented: |
| 2463 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2464 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2465 |
#. EINTR normally? |
| 2466 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2467 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2468 |
#. regard. :( |
| 2469 |
#. type: Plain text |
| 2470 |
#. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2471 |
#. FIXME |
| 2472 |
#. About the above, Kees Cook commented: |
| 2473 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2474 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2475 |
#. EINTR normally? |
| 2476 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2477 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2478 |
#. regard. :( |
| 2479 |
#. type: Plain text |
| 2480 |
#. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2481 |
#. FIXME |
| 2482 |
#. About the above, Kees Cook commented: |
| 2483 |
#. Does this need fixing? I imagine the correct behavior for this case |
| 2484 |
#. would be a response to _SEND of EINPROGRESS and the target would see |
| 2485 |
#. EINTR normally? |
| 2486 |
#. I mean, it's not like seccomp doesn't already expose weirdness with |
| 2487 |
#. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this |
| 2488 |
#. regard. :( |
| 2489 |
#. type: Plain text |
| 2490 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2491 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2492 |
msgid "" |
| 2493 |
"One oddity is that system call restarting as described in this scenario will " |
| 2494 |
"occur even for the blocking system calls listed in B<signal>(7) that would " |
| 2495 |
"B<never> normally be restarted by the B<SA_RESTART> flag." |
| 2496 |
msgstr "" |
| 2497 |
"من الأمور الغريبة أن إعادة تشغيل استدعاء النظام كما هو موضح في هذا السيناريو " |
| 2498 |
"ستحدث حتى بالنسبة لاستدعاءات النظام الحاصرة المدرجة في B<signal>(7) والتي لا " |
| 2499 |
"يُعاد تشغيلها B<أبداً> في العادة بواسطة العلم B<SA_RESTART>." |
| 2500 |
|
| 2501 |
#. type: Plain text |
| 2502 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2503 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2504 |
msgid "" |
| 2505 |
"Furthermore, if the supervisor response is a file descriptor added with " |
| 2506 |
"B<SECCOMP_IOCTL_NOTIF_ADDFD>, then the flag B<SECCOMP_ADDFD_FLAG_SEND> can " |
| 2507 |
"be used to atomically add the file descriptor and return that value, making " |
| 2508 |
"sure no file descriptors are inadvertently leaked into the target." |
| 2509 |
msgstr "" |
| 2510 |
"علاوة على ذلك، إذا كانت استجابة المشرف هي واصف ملف أُضيف باستخدام " |
| 2511 |
"B<SECCOMP_IOCTL_NOTIF_ADDFD>، فيمكن حينئذٍ استخدام العلم " |
| 2512 |
"B<SECCOMP_ADDFD_FLAG_SEND> لإضافة واصف الملف وإعادة تلك القيمة ذرياً، مما " |
| 2513 |
"يضمن عدم تسرب أي واصفات ملفات عن غير قصد إلى الهدف." |
| 2514 |
|
| 2515 |
#. type: SH |
| 2516 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2517 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2518 |
#, no-wrap |
| 2519 |
msgid "BUGS" |
| 2520 |
msgstr "العلل" |
| 2521 |
|
| 2522 |
# |
| 2523 |
#. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2524 |
#. or a poll/epoll/select |
| 2525 |
#. FIXME |
| 2526 |
#. Comment from Kees Cook: |
| 2527 |
#. I want this fixed. It caused me no end of pain when building the |
| 2528 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2529 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2530 |
#. way to deal with this, but now I think we're close. |
| 2531 |
#. type: Plain text |
| 2532 |
#. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2533 |
#. or a poll/epoll/select |
| 2534 |
#. FIXME |
| 2535 |
#. Comment from Kees Cook: |
| 2536 |
#. I want this fixed. It caused me no end of pain when building the |
| 2537 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2538 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2539 |
#. way to deal with this, but now I think we're close. |
| 2540 |
#. type: Plain text |
| 2541 |
#. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2542 |
#. or a poll/epoll/select |
| 2543 |
#. FIXME |
| 2544 |
#. Comment from Kees Cook: |
| 2545 |
#. I want this fixed. It caused me no end of pain when building the |
| 2546 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2547 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2548 |
#. way to deal with this, but now I think we're close. |
| 2549 |
#. type: Plain text |
| 2550 |
#. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2551 |
#. or a poll/epoll/select |
| 2552 |
#. FIXME |
| 2553 |
#. Comment from Kees Cook: |
| 2554 |
#. I want this fixed. It caused me no end of pain when building the |
| 2555 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2556 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2557 |
#. way to deal with this, but now I think we're close. |
| 2558 |
#. type: Plain text |
| 2559 |
#. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2560 |
#. or a poll/epoll/select |
| 2561 |
#. FIXME |
| 2562 |
#. Comment from Kees Cook: |
| 2563 |
#. I want this fixed. It caused me no end of pain when building the |
| 2564 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2565 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2566 |
#. way to deal with this, but now I think we're close. |
| 2567 |
#. type: Plain text |
| 2568 |
#. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2569 |
#. or a poll/epoll/select |
| 2570 |
#. FIXME |
| 2571 |
#. Comment from Kees Cook: |
| 2572 |
#. I want this fixed. It caused me no end of pain when building the |
| 2573 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2574 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2575 |
#. way to deal with this, but now I think we're close. |
| 2576 |
#. type: Plain text |
| 2577 |
#. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2578 |
#. or a poll/epoll/select |
| 2579 |
#. FIXME |
| 2580 |
#. Comment from Kees Cook: |
| 2581 |
#. I want this fixed. It caused me no end of pain when building the |
| 2582 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2583 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2584 |
#. way to deal with this, but now I think we're close. |
| 2585 |
#. type: Plain text |
| 2586 |
#. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# |
| 2587 |
#. or a poll/epoll/select |
| 2588 |
#. FIXME |
| 2589 |
#. Comment from Kees Cook: |
| 2590 |
#. I want this fixed. It caused me no end of pain when building the |
| 2591 |
#. selftests, and ended up spawning my implementing a global test timeout |
| 2592 |
#. in kselftest. :P Before the usage counter refactor, there was no sane |
| 2593 |
#. way to deal with this, but now I think we're close. |
| 2594 |
#. type: Plain text |
| 2595 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2596 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2597 |
msgid "" |
| 2598 |
"If a B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) operation is performed after " |
| 2599 |
"the target terminates, then the B<ioctl>(2) call simply blocks (rather than " |
| 2600 |
"returning an error to indicate that the target no longer exists)." |
| 2601 |
msgstr "" |
| 2602 |
"إذا أُجريت عملية B<SECCOMP_IOCTL_NOTIF_RECV> B<ioctl>(2) بعد انتهاء الهدف، " |
| 2603 |
"فإن استدعاء B<ioctl>(2) يحظر ببساطة (بدلاً من إعادة خطأ يشير إلى أن الهدف لم " |
| 2604 |
"يعد موجوداً)." |
| 2605 |
|
| 2606 |
#. type: SH |
| 2607 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2608 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2609 |
#, no-wrap |
| 2610 |
msgid "EXAMPLES" |
| 2611 |
msgstr "أمثلة" |
| 2612 |
|
| 2613 |
#. type: Plain text |
| 2614 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2615 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2616 |
msgid "" |
| 2617 |
"The (somewhat contrived) program shown below demonstrates the use of the " |
| 2618 |
"interfaces described in this page. The program creates a child process that " |
| 2619 |
"serves as the \"target\" process. The child process installs a seccomp " |
| 2620 |
"filter that returns the B<SECCOMP_RET_USER_NOTIF> action value if a call is " |
| 2621 |
"made to B<mkdir>(2). The child process then calls B<mkdir>(2) once for " |
| 2622 |
"each of the supplied command-line arguments, and reports the result returned " |
| 2623 |
"by the call. After processing all arguments, the child process terminates." |
| 2624 |
msgstr "" |
| 2625 |
"يوضح البرنامج الموضح أدناه (المصمم لغرض العرض) استخدام الواجهات الموصوفة في " |
| 2626 |
"هذه الصفحة. ينشئ البرنامج عملية ابنة تعمل كعملية \"هدف\". تثبت العملية " |
| 2627 |
"الابنة مرشح seccomp يعيد قيمة إجراء B<SECCOMP_RET_USER_NOTIF> إذا أُجري " |
| 2628 |
"استدعاء لـ B<mkdir>(2). ثم تستدعي العملية الابنة B<mkdir>(2) مرة واحدة لكل " |
| 2629 |
"وسيط من وسائط سطر الأوامر الموفرة، وتبلغ عن النتيجة التي أعادها الاستدعاء. " |
| 2630 |
"وبعد معالجة كافة الوسائط، تنتهي العملية الابنة." |
| 2631 |
|
| 2632 |
#. type: Plain text |
| 2633 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2634 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2635 |
msgid "" |
| 2636 |
"The parent process acts as the supervisor, listening for the notifications " |
| 2637 |
"that are generated when the target process calls B<mkdir>(2). When such a " |
| 2638 |
"notification occurs, the supervisor examines the memory of the target " |
| 2639 |
"process (using I</proc/>pidI</mem>) to discover the pathname argument that " |
| 2640 |
"was supplied to the B<mkdir>(2) call, and performs one of the following " |
| 2641 |
"actions:" |
| 2642 |
msgstr "" |
| 2643 |
"تعمل العملية الأب كمشرف، حيث تستمع للإشعارات التي تُولّد عندما تستدعي العملية " |
| 2644 |
"الهدف B<mkdir>(2). وعند حدوث مثل هذا الإشعار، يفحص المشرف ذاكرة العملية " |
| 2645 |
"الهدف (باستخدام I</proc/>pidI</mem>) لاكتشاف وسيط المسار الذي وُفر لاستدعاء " |
| 2646 |
"B<mkdir>(2)، وينفذ أحد الإجراءات التالية:" |
| 2647 |
|
| 2648 |
#. type: Plain text |
| 2649 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2650 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2651 |
msgid "" |
| 2652 |
"If the pathname begins with the prefix \"/tmp/\", then the supervisor " |
| 2653 |
"attempts to create the specified directory, and then spoofs a return for the " |
| 2654 |
"target process based on the return value of the supervisor's B<mkdir>(2) " |
| 2655 |
"call. In the event that that call succeeds, the spoofed success return " |
| 2656 |
"value is the length of the pathname." |
| 2657 |
msgstr "" |
| 2658 |
"إذا بدأ المسار بالبادئة \"/tmp/\"، يحاول المشرف إنشاء الدليل المحدد، ثم يزيف " |
| 2659 |
"عودة للعملية الهدف بناءً على القيمة المعادة من استدعاء B<mkdir>(2) الخاص " |
| 2660 |
"بالمشرف. وفي حال نجاح ذلك الاستدعاء، تكون قيمة العودة الناجحة المزيفة هي طول " |
| 2661 |
"المسار." |
| 2662 |
|
| 2663 |
#. type: Plain text |
| 2664 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2665 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2666 |
msgid "" |
| 2667 |
"If the pathname begins with \"./\" (i.e., it is a relative pathname), the " |
| 2668 |
"supervisor sends a B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> response to the " |
| 2669 |
"kernel to say that the kernel should execute the target process's " |
| 2670 |
"B<mkdir>(2) call." |
| 2671 |
msgstr "" |
| 2672 |
"إذا بدأ المسار بـ \"./\" (أي أنه مسار نسبي)، يرسل المشرف استجابة " |
| 2673 |
"B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> إلى النواة للإشارة إلى أنه يجب على " |
| 2674 |
"النواة تنفيذ استدعاء B<mkdir>(2) للعملية الهدف." |
| 2675 |
|
| 2676 |
#. type: Plain text |
| 2677 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2678 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2679 |
msgid "" |
| 2680 |
"If the pathname begins with some other prefix, the supervisor spoofs an " |
| 2681 |
"error return for the target process, so that the target process's " |
| 2682 |
"B<mkdir>(2) call appears to fail with the error B<EOPNOTSUPP> (\"Operation " |
| 2683 |
"not supported\"). Additionally, if the specified pathname is exactly \"/" |
| 2684 |
"bye\", then the supervisor terminates." |
| 2685 |
msgstr "" |
| 2686 |
"إذا بدأ المسار ببادئة أخرى، يزيف المشرف عودة خطأ للعملية الهدف، لكي يبدو أن " |
| 2687 |
"استدعاء B<mkdir>(2) للعملية الهدف قد فشل مع الخطأ B<EOPNOTSUPP> (\"العملية " |
| 2688 |
"غير مدعومة\"). بالإضافة إلى ذلك، إذا كان المسار المحدد هو \"/bye\" بالضبط، " |
| 2689 |
"فينتهي المشرف." |
| 2690 |
|
| 2691 |
#. type: Plain text |
| 2692 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2693 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2694 |
msgid "" |
| 2695 |
"This program can be used to demonstrate various aspects of the behavior of " |
| 2696 |
"the seccomp user-space notification mechanism. To help aid such " |
| 2697 |
"demonstrations, the program logs various messages to show the operation of " |
| 2698 |
"the target process (lines prefixed \"T:\") and the supervisor (indented " |
| 2699 |
"lines prefixed \"S:\")." |
| 2700 |
msgstr "" |
| 2701 |
"يمكن استخدام هذا البرنامج لتوضيح جوانب مختلفة من سلوك آلية إشعار مساحة " |
| 2702 |
"مستخدم seccomp. وللمساعدة في مثل هذه العروض التوضيحية، يسجل البرنامج رسائل " |
| 2703 |
"متنوعة لإظهار عملية العملية الهدف (السطور المسبوقة بـ \"T:\") والمشرف " |
| 2704 |
"(السطور المزاحة والمسبوقة بـ \"S:\")." |
| 2705 |
|
| 2706 |
#. type: Plain text |
| 2707 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2708 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2709 |
msgid "" |
| 2710 |
"In the following example, the target attempts to create the directory I</tmp/" |
| 2711 |
"x>. Upon receiving the notification, the supervisor creates the directory " |
| 2712 |
"on the target's behalf, and spoofs a success return to be received by the " |
| 2713 |
"target process's B<mkdir>(2) call." |
| 2714 |
msgstr "" |
| 2715 |
"في المثال التالي، يحاول الهدف إنشاء الدليل I</tmp/x>. وعند تلقي الإشعار، " |
| 2716 |
"ينشئ المشرف الدليل نيابة عن الهدف، ويزيف عودة ناجحة ليتلقاها استدعاء " |
| 2717 |
"B<mkdir>(2) للعملية الهدف." |
| 2718 |
|
| 2719 |
#. type: Plain text |
| 2720 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2721 |
#: opensuse-tumbleweed |
| 2722 |
#, no-wrap |
| 2723 |
msgid "" |
| 2724 |
"$B< ./seccomp_unotify /tmp/x>;\n" |
| 2725 |
"T: PID = 23168\n" |
| 2726 |
"\\&\n" |
| 2727 |
"T: about to mkdir(\"/tmp/x\")\n" |
| 2728 |
" S: got notification (ID 0x17445c4a0f4e0e3c) for PID 23168\n" |
| 2729 |
" S: executing: mkdir(\"/tmp/x\", 0700)\n" |
| 2730 |
" S: success! spoofed return = 6\n" |
| 2731 |
" S: sending response (flags = 0; val = 6; error = 0)\n" |
| 2732 |
"T: SUCCESS: mkdir(2) returned 6\n" |
| 2733 |
"\\&\n" |
| 2734 |
"T: terminating\n" |
| 2735 |
" S: target has terminated; bye\n" |
| 2736 |
msgstr "" |
| 2737 |
"$B< ./seccomp_unotify /tmp/x>;\n" |
| 2738 |
"T: PID = 23168\n" |
| 2739 |
"\\&\n" |
| 2740 |
"T: على وشك إجراء mkdir(\"/tmp/x\")\n" |
| 2741 |
" S: جُلب إشعار (ID 0x17445c4a0f4e0e3c) لـ PID 23168\n" |
| 2742 |
" S: جارِ تنفيذ: mkdir(\"/tmp/x\", 0700)\n" |
| 2743 |
" S: نجاح! عودة مزيفة = 6\n" |
| 2744 |
" S: جارِ إرسال استجابة (flags = 0; val = 6; error = 0)\n" |
| 2745 |
"T: نجاح: mkdir(2) أعاد 6\n" |
| 2746 |
"\\&\n" |
| 2747 |
"T: جارِ الإنهاء\n" |
| 2748 |
" S: انتهى الهدف؛ وداعاً\n" |
| 2749 |
|
| 2750 |
#. type: Plain text |
| 2751 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2752 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2753 |
msgid "" |
| 2754 |
"In the above output, note that the spoofed return value seen by the target " |
| 2755 |
"process is 6 (the length of the pathname I</tmp/x>), whereas a normal " |
| 2756 |
"B<mkdir>(2) call returns 0 on success." |
| 2757 |
msgstr "" |
| 2758 |
"في المخرجات أعلاه، لاحظ أن قيمة العودة المزيفة التي تراها العملية الهدف هي 6 " |
| 2759 |
"(طول المسار I</tmp/x>)، بينما يعيد استدعاء B<mkdir>(2) العادي 0 عند النجاح." |
| 2760 |
|
| 2761 |
#. type: Plain text |
| 2762 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2763 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2764 |
msgid "" |
| 2765 |
"In the next example, the target attempts to create a directory using the " |
| 2766 |
"relative pathname I<./sub>. Since this pathname starts with \"./\", the " |
| 2767 |
"supervisor sends a B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> response to the " |
| 2768 |
"kernel, and the kernel then (successfully) executes the target process's " |
| 2769 |
"B<mkdir>(2) call." |
| 2770 |
msgstr "" |
| 2771 |
"في المثال التالي، يحاول الهدف إنشاء دليل باستخدام المسار النسبي I<./sub>. " |
| 2772 |
"وبما أن هذا المسار يبدأ بـ \"./\"، يرسل المشرف استجابة " |
| 2773 |
"B<SECCOMP_USER_NOTIF_FLAG_CONTINUE> إلى النواة، وتنفذ النواة حينئذٍ (بنجاح) " |
| 2774 |
"استدعاء B<mkdir>(2) للعملية الهدف." |
| 2775 |
|
| 2776 |
#. type: Plain text |
| 2777 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2778 |
#: opensuse-tumbleweed |
| 2779 |
#, no-wrap |
| 2780 |
msgid "" |
| 2781 |
"$B< ./seccomp_unotify ./sub>;\n" |
| 2782 |
"T: PID = 23204\n" |
| 2783 |
"\\&\n" |
| 2784 |
"T: about to mkdir(\"./sub\")\n" |
| 2785 |
" S: got notification (ID 0xddb16abe25b4c12) for PID 23204\n" |
| 2786 |
" S: target can execute system call\n" |
| 2787 |
" S: sending response (flags = 0x1; val = 0; error = 0)\n" |
| 2788 |
"T: SUCCESS: mkdir(2) returned 0\n" |
| 2789 |
"\\&\n" |
| 2790 |
"T: terminating\n" |
| 2791 |
" S: target has terminated; bye\n" |
| 2792 |
msgstr "" |
| 2793 |
"$B< ./seccomp_unotify ./sub>;\n" |
| 2794 |
"T: PID = 23204\n" |
| 2795 |
"\\&\n" |
| 2796 |
"T: على وشك إجراء mkdir(\"./sub\")\n" |
| 2797 |
" S: جُلب إشعار (ID 0xddb16abe25b4c12) لـ PID 23204\n" |
| 2798 |
" S: يمكن للهدف تنفيذ استدعاء النظام\n" |
| 2799 |
" S: جارِ إرسال استجابة (flags = 0x1; val = 0; error = 0)\n" |
| 2800 |
"T: نجاح: mkdir(2) أعاد 0\n" |
| 2801 |
"\\&\n" |
| 2802 |
"T: جارِ الإنهاء\n" |
| 2803 |
" S: انتهى الهدف؛ وداعاً\n" |
| 2804 |
|
| 2805 |
#. type: Plain text |
| 2806 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2807 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2808 |
msgid "" |
| 2809 |
"If the target process attempts to create a directory with a pathname that " |
| 2810 |
"doesn't start with \".\" and doesn't begin with the prefix \"/tmp/\", then " |
| 2811 |
"the supervisor spoofs an error return (B<EOPNOTSUPP>, \"Operation not " |
| 2812 |
"supported\") for the target's B<mkdir>(2) call (which is not executed):" |
| 2813 |
msgstr "" |
| 2814 |
"إذا حاولت العملية الهدف إنشاء دليل بمسار لا يبدأ بـ \".\" ولا يبدأ بالبادئة " |
| 2815 |
"\"/tmp/\"، فإن المشرف يزيف عودة خطأ (B<EOPNOTSUPP>، \"العملية غير مدعومة\") " |
| 2816 |
"لاستدعاء B<mkdir>(2) للهدف (الذي لا يُنفذ):" |
| 2817 |
|
| 2818 |
#. type: Plain text |
| 2819 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2820 |
#: opensuse-tumbleweed |
| 2821 |
#, no-wrap |
| 2822 |
msgid "" |
| 2823 |
"$B< ./seccomp_unotify /xxx>;\n" |
| 2824 |
"T: PID = 23178\n" |
| 2825 |
"\\&\n" |
| 2826 |
"T: about to mkdir(\"/xxx\")\n" |
| 2827 |
" S: got notification (ID 0xe7dc095d1c524e80) for PID 23178\n" |
| 2828 |
" S: spoofing error response (Operation not supported)\n" |
| 2829 |
" S: sending response (flags = 0; val = 0; error = -95)\n" |
| 2830 |
"T: ERROR: mkdir(2): Operation not supported\n" |
| 2831 |
"\\&\n" |
| 2832 |
"T: terminating\n" |
| 2833 |
" S: target has terminated; bye\n" |
| 2834 |
msgstr "" |
| 2835 |
"$B< ./seccomp_unotify /xxx>;\n" |
| 2836 |
"T: PID = 23178\n" |
| 2837 |
"\\&\n" |
| 2838 |
"T: على وشك إجراء mkdir(\"/xxx\")\n" |
| 2839 |
" S: جُلب إشعار (ID 0xe7dc095d1c524e80) لـ PID 23178\n" |
| 2840 |
" S: جارِ تزييف استجابة خطأ (العملية غير مدعومة)\n" |
| 2841 |
" S: جارِ إرسال استجابة (flags = 0; val = 0; error = -95)\n" |
| 2842 |
"T: خطأ: mkdir(2): العملية غير مدعومة\n" |
| 2843 |
"\\&\n" |
| 2844 |
"T: جارِ الإنهاء\n" |
| 2845 |
" S: انتهى الهدف؛ وداعاً\n" |
| 2846 |
|
| 2847 |
#. type: Plain text |
| 2848 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2849 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2850 |
msgid "" |
| 2851 |
"In the next example, the target process attempts to create a directory with " |
| 2852 |
"the pathname B</tmp/nosuchdir/b>. Upon receiving the notification, the " |
| 2853 |
"supervisor attempts to create that directory, but the B<mkdir>(2) call " |
| 2854 |
"fails because the directory B</tmp/nosuchdir> does not exist. Consequently, " |
| 2855 |
"the supervisor spoofs an error return that passes the error that it received " |
| 2856 |
"back to the target process's B<mkdir>(2) call." |
| 2857 |
msgstr "" |
| 2858 |
"في المثال التالي، تحاول العملية الهدف إنشاء دليل بالمسار B</tmp/nosuchdir/" |
| 2859 |
"b>. وعند تلقي الإشعار، يحاول المشرف إنشاء ذلك الدليل، ولكن يفشل استدعاء " |
| 2860 |
"B<mkdir>(2) لأن الدليل B</tmp/nosuchdir> غير موجود. وبناءً على ذلك، يزيف " |
| 2861 |
"المشرف عودة خطأ تمرر الخطأ الذي تلقاه مرة أخرى إلى استدعاء B<mkdir>(2) " |
| 2862 |
"للعملية الهدف." |
| 2863 |
|
| 2864 |
#. type: Plain text |
| 2865 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2866 |
#: opensuse-tumbleweed |
| 2867 |
#, no-wrap |
| 2868 |
msgid "" |
| 2869 |
"$B< ./seccomp_unotify /tmp/nosuchdir/b>;\n" |
| 2870 |
"T: PID = 23199\n" |
| 2871 |
"\\&\n" |
| 2872 |
"T: about to mkdir(\"/tmp/nosuchdir/b\")\n" |
| 2873 |
" S: got notification (ID 0x8744454293506046) for PID 23199\n" |
| 2874 |
" S: executing: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" |
| 2875 |
" S: failure! (errno = 2; No such file or directory)\n" |
| 2876 |
" S: sending response (flags = 0; val = 0; error = -2)\n" |
| 2877 |
"T: ERROR: mkdir(2): No such file or directory\n" |
| 2878 |
"\\&\n" |
| 2879 |
"T: terminating\n" |
| 2880 |
" S: target has terminated; bye\n" |
| 2881 |
msgstr "" |
| 2882 |
"$B< ./seccomp_unotify /tmp/nosuchdir/b>;\n" |
| 2883 |
"T: PID = 23199\n" |
| 2884 |
"\\&\n" |
| 2885 |
"T: على وشك إجراء mkdir(\"/tmp/nosuchdir/b\")\n" |
| 2886 |
" S: جُلب إشعار (ID 0x8744454293506046) لـ PID 23199\n" |
| 2887 |
" S: جارِ تنفيذ: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" |
| 2888 |
" S: فشل! (errno = 2; لا يوجد ملف أو دليل كهذا)\n" |
| 2889 |
" S: جارِ إرسال استجابة (flags = 0; val = 0; error = -2)\n" |
| 2890 |
"T: خطأ: mkdir(2): لا يوجد ملف أو دليل كهذا\n" |
| 2891 |
"\\&\n" |
| 2892 |
"T: جارِ الإنهاء\n" |
| 2893 |
" S: انتهى الهدف؛ وداعاً\n" |
| 2894 |
|
| 2895 |
#. type: Plain text |
| 2896 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2897 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2898 |
msgid "" |
| 2899 |
"If the supervisor receives a notification and sees that the argument of the " |
| 2900 |
"target's B<mkdir>(2) is the string \"/bye\", then (as well as spoofing an " |
| 2901 |
"B<EOPNOTSUPP> error), the supervisor terminates. If the target process " |
| 2902 |
"subsequently executes another B<mkdir>(2) that triggers its seccomp filter " |
| 2903 |
"to return the B<SECCOMP_RET_USER_NOTIF> action value, then the kernel causes " |
| 2904 |
"the target process's system call to fail with the error B<ENOSYS> " |
| 2905 |
"(\"Function not implemented\"). This is demonstrated by the following " |
| 2906 |
"example:" |
| 2907 |
msgstr "" |
| 2908 |
"إذا تلقى المشرف إشعارًا ورأى أن وسيط B<mkdir>(2) الخاص بالهدف هو السلسلة \"/" |
| 2909 |
"bye\"، فحينئذٍ ينهي المشرف عمله (بالإضافة إلى تزييف خطأ B<EOPNOTSUPP>). وإذا " |
| 2910 |
"نفذت عملية الهدف لاحقًا B<mkdir>(2) أخرى تحفز مرشح seccomp الخاص بها ليعيد " |
| 2911 |
"قيمة الإجراء B<SECCOMP_RET_USER_NOTIF>، فتتسبب النواة في فشل استدعاء النظام " |
| 2912 |
"لعملية الهدف بخطأ B<ENOSYS> (\"الوظيفة غير مفعلة\"). ويُوضح ذلك في المثال " |
| 2913 |
"التالي:" |
| 2914 |
|
| 2915 |
#. type: Plain text |
| 2916 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 2917 |
#: opensuse-tumbleweed |
| 2918 |
#, no-wrap |
| 2919 |
msgid "" |
| 2920 |
"$B< ./seccomp_unotify /bye /tmp/y>;\n" |
| 2921 |
"T: PID = 23185\n" |
| 2922 |
"\\&\n" |
| 2923 |
"T: about to mkdir(\"/bye\")\n" |
| 2924 |
" S: got notification (ID 0xa81236b1d2f7b0f4) for PID 23185\n" |
| 2925 |
" S: spoofing error response (Operation not supported)\n" |
| 2926 |
" S: sending response (flags = 0; val = 0; error = -95)\n" |
| 2927 |
" S: terminating **********\n" |
| 2928 |
"T: ERROR: mkdir(2): Operation not supported\n" |
| 2929 |
"\\&\n" |
| 2930 |
"T: about to mkdir(\"/tmp/y\")\n" |
| 2931 |
"T: ERROR: mkdir(2): Function not implemented\n" |
| 2932 |
"\\&\n" |
| 2933 |
"T: terminating\n" |
| 2934 |
msgstr "" |
| 2935 |
"$B< ./seccomp_unotify /bye /tmp/y>;\n" |
| 2936 |
"T: PID = 23185\n" |
| 2937 |
"\\&\n" |
| 2938 |
"T: على وشك إجراء mkdir(\"/bye\")\n" |
| 2939 |
" S: جُلب إشعار (ID 0xa81236b1d2f7b0f4) لـ PID 23185\n" |
| 2940 |
" S: جارِ تزييف استجابة خطأ (العملية غير مدعومة)\n" |
| 2941 |
" S: جارِ إرسال استجابة (flags = 0; val = 0; error = -95)\n" |
| 2942 |
" S: جارِ الإنهاء **********\n" |
| 2943 |
"T: خطأ: mkdir(2): العملية غير مدعومة\n" |
| 2944 |
"\\&\n" |
| 2945 |
"T: على وشك إجراء mkdir(\"/tmp/y\")\n" |
| 2946 |
"T: خطأ: mkdir(2): الوظيفة غير منفذة\n" |
| 2947 |
"\\&\n" |
| 2948 |
"T: جارِ الإنهاء\n" |
| 2949 |
|
| 2950 |
#. type: SS |
| 2951 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 2952 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 2953 |
#, no-wrap |
| 2954 |
msgid "Program source" |
| 2955 |
msgstr "مصدر البرنامج" |
| 2956 |
|
| 2957 |
#. type: Plain text |
| 2958 |
#: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed |
| 2959 |
#, no-wrap |
| 2960 |
msgid "" |
| 2961 |
"#define _GNU_SOURCE\n" |
| 2962 |
"#include E<lt>err.hE<gt>\n" |
| 2963 |
"#include E<lt>errno.hE<gt>\n" |
| 2964 |
"#include E<lt>fcntl.hE<gt>\n" |
| 2965 |
"#include E<lt>limits.hE<gt>\n" |
| 2966 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 2967 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 2968 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 2969 |
"#include E<lt>signal.hE<gt>\n" |
| 2970 |
"#include E<lt>stdbool.hE<gt>\n" |
| 2971 |
"#include E<lt>stdcountof.hE<gt>\n" |
| 2972 |
"#include E<lt>stddef.hE<gt>\n" |
| 2973 |
"#include E<lt>stdint.hE<gt>\n" |
| 2974 |
"#include E<lt>stdio.hE<gt>\n" |
| 2975 |
"#include E<lt>stdlib.hE<gt>\n" |
| 2976 |
"#include E<lt>string.hE<gt>\n" |
| 2977 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 2978 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 2979 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 2980 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 2981 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 2982 |
"#include E<lt>sys/types.hE<gt>\n" |
| 2983 |
"#include E<lt>sys/un.hE<gt>\n" |
| 2984 |
"#include E<lt>unistd.hE<gt>\n" |
| 2985 |
"\\&\n" |
| 2986 |
"#define streq(...) (strcmp(__VA_ARGS__) == 0)\n" |
| 2987 |
"\\&\n" |
| 2988 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 2989 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 2990 |
"\\&\n" |
| 2991 |
"static int\n" |
| 2992 |
"sendfd(int sockfd, int fd)\n" |
| 2993 |
"{\n" |
| 2994 |
" int data;\n" |
| 2995 |
" struct iovec iov;\n" |
| 2996 |
" struct msghdr msgh;\n" |
| 2997 |
" struct cmsghdr *cmsgp;\n" |
| 2998 |
"\\&\n" |
| 2999 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 3000 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 3001 |
" union to ensure that it is suitably aligned. */\n" |
| 3002 |
" union {\n" |
| 3003 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 3004 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 3005 |
" struct cmsghdr align;\n" |
| 3006 |
" } controlMsg;\n" |
| 3007 |
"\\&\n" |
| 3008 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 3009 |
" destination socket when sending a datagram. However, we do not\n" |
| 3010 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 3011 |
"\\&\n" |
| 3012 |
" msgh.msg_name = NULL;\n" |
| 3013 |
" msgh.msg_namelen = 0;\n" |
| 3014 |
"\\&\n" |
| 3015 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 3016 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 3017 |
" whose value is ignored by recvfd(). */\n" |
| 3018 |
"\\&\n" |
| 3019 |
" msgh.msg_iov = &iov;\n" |
| 3020 |
" msgh.msg_iovlen = 1;\n" |
| 3021 |
" iov.iov_base = &data;\n" |
| 3022 |
" iov.iov_len = sizeof(int);\n" |
| 3023 |
" data = 12345;\n" |
| 3024 |
"\\&\n" |
| 3025 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 3026 |
"\\&\n" |
| 3027 |
" msgh.msg_control = controlMsg.buf;\n" |
| 3028 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 3029 |
"\\&\n" |
| 3030 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 3031 |
"\\&\n" |
| 3032 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 3033 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 3034 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 3035 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 3036 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 3037 |
"\\&\n" |
| 3038 |
" /* Send real plus ancillary data */\n" |
| 3039 |
"\\&\n" |
| 3040 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 3041 |
" return -1;\n" |
| 3042 |
"\\&\n" |
| 3043 |
" return 0;\n" |
| 3044 |
"}\n" |
| 3045 |
"\\&\n" |
| 3046 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 3047 |
" the received file descriptor on success, or -1 on error. */\n" |
| 3048 |
"\\&\n" |
| 3049 |
"static int\n" |
| 3050 |
"recvfd(int sockfd)\n" |
| 3051 |
"{\n" |
| 3052 |
" int data, fd;\n" |
| 3053 |
" ssize_t nr;\n" |
| 3054 |
" struct iovec iov;\n" |
| 3055 |
" struct msghdr msgh;\n" |
| 3056 |
"\\&\n" |
| 3057 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 3058 |
" in sendfd() */\n" |
| 3059 |
" union {\n" |
| 3060 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 3061 |
" struct cmsghdr align;\n" |
| 3062 |
" } controlMsg;\n" |
| 3063 |
" struct cmsghdr *cmsgp;\n" |
| 3064 |
"\\&\n" |
| 3065 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 3066 |
" sending socket. However, we do not need this information. */\n" |
| 3067 |
"\\&\n" |
| 3068 |
" msgh.msg_name = NULL;\n" |
| 3069 |
" msgh.msg_namelen = 0;\n" |
| 3070 |
"\\&\n" |
| 3071 |
" /* Specify buffer for receiving real data */\n" |
| 3072 |
"\\&\n" |
| 3073 |
" msgh.msg_iov = &iov;\n" |
| 3074 |
" msgh.msg_iovlen = 1;\n" |
| 3075 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 3076 |
" iov.iov_len = sizeof(int);\n" |
| 3077 |
"\\&\n" |
| 3078 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 3079 |
"\\&\n" |
| 3080 |
" msgh.msg_control = controlMsg.buf;\n" |
| 3081 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 3082 |
"\\&\n" |
| 3083 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 3084 |
"\\&\n" |
| 3085 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 3086 |
" if (nr == -1)\n" |
| 3087 |
" return -1;\n" |
| 3088 |
"\\&\n" |
| 3089 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 3090 |
"\\&\n" |
| 3091 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 3092 |
"\\&\n" |
| 3093 |
" if (cmsgp == NULL\n" |
| 3094 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 3095 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 3096 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 3097 |
" {\n" |
| 3098 |
" errno = EINVAL;\n" |
| 3099 |
" return -1;\n" |
| 3100 |
" }\n" |
| 3101 |
"\\&\n" |
| 3102 |
" /* Return the received file descriptor to our caller */\n" |
| 3103 |
"\\&\n" |
| 3104 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 3105 |
" return fd;\n" |
| 3106 |
"}\n" |
| 3107 |
"\\&\n" |
| 3108 |
"static void\n" |
| 3109 |
"sigchldHandler(int sig)\n" |
| 3110 |
"{\n" |
| 3111 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 3112 |
"\\&\n" |
| 3113 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 3114 |
" _exit(EXIT_SUCCESS);\n" |
| 3115 |
"}\n" |
| 3116 |
"\\&\n" |
| 3117 |
"static int\n" |
| 3118 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 3119 |
"{\n" |
| 3120 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 3121 |
"}\n" |
| 3122 |
"\\&\n" |
| 3123 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 3124 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 3125 |
" completion of these instructions, the accumulator contains the system\n" |
| 3126 |
" call number. */\n" |
| 3127 |
"\\&\n" |
| 3128 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 3129 |
"\\&\n" |
| 3130 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 3131 |
"\\&\n" |
| 3132 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 3133 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 3134 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 3135 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 3136 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 3137 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 3138 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 3139 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 3140 |
"\\&\n" |
| 3141 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 3142 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 3143 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 3144 |
"\\&\n" |
| 3145 |
" The function return value is a file descriptor from which the\n" |
| 3146 |
" user-space notifications can be fetched. */\n" |
| 3147 |
"\\&\n" |
| 3148 |
"static int\n" |
| 3149 |
"installNotifyFilter(void)\n" |
| 3150 |
"{\n" |
| 3151 |
" int notifyFd;\n" |
| 3152 |
"\\&\n" |
| 3153 |
" struct sock_filter filter[] = {\n" |
| 3154 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 3155 |
"\\&\n" |
| 3156 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 3157 |
"\\&\n" |
| 3158 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 3159 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 3160 |
"\\&\n" |
| 3161 |
" /* Every other system call is allowed */\n" |
| 3162 |
"\\&\n" |
| 3163 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 3164 |
" };\n" |
| 3165 |
"\\&\n" |
| 3166 |
" struct sock_fprog prog = {\n" |
| 3167 |
" .len = countof(filter),\n" |
| 3168 |
" .filter = filter,\n" |
| 3169 |
" };\n" |
| 3170 |
"\\&\n" |
| 3171 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 3172 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 3173 |
"\\&\n" |
| 3174 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 3175 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 3176 |
" if (notifyFd == -1)\n" |
| 3177 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 3178 |
"\\&\n" |
| 3179 |
" return notifyFd;\n" |
| 3180 |
"}\n" |
| 3181 |
"\\&\n" |
| 3182 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 3183 |
"\\&\n" |
| 3184 |
"static void\n" |
| 3185 |
"closeSocketPair(int sockPair[2])\n" |
| 3186 |
"{\n" |
| 3187 |
" if (close(sockPair[0]) == -1)\n" |
| 3188 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 3189 |
" if (close(sockPair[1]) == -1)\n" |
| 3190 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 3191 |
"}\n" |
| 3192 |
"\\&\n" |
| 3193 |
"/* Implementation of the target process. Create a child process that:\n" |
| 3194 |
"\\&\n" |
| 3195 |
" (1) installs a seccomp filter with the\n" |
| 3196 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 3197 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 3198 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 3199 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 3200 |
"\\&\n" |
| 3201 |
" The function return value in the parent is the PID of the child\n" |
| 3202 |
" process; the child does not return from this function. */\n" |
| 3203 |
"\\&\n" |
| 3204 |
"static pid_t\n" |
| 3205 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 3206 |
"{\n" |
| 3207 |
" int notifyFd, s;\n" |
| 3208 |
" pid_t targetPid;\n" |
| 3209 |
"\\&\n" |
| 3210 |
" targetPid = fork();\n" |
| 3211 |
"\\&\n" |
| 3212 |
" if (targetPid == -1)\n" |
| 3213 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 3214 |
"\\&\n" |
| 3215 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 3216 |
" return targetPid;\n" |
| 3217 |
"\\&\n" |
| 3218 |
" /* Child falls through to here */\n" |
| 3219 |
"\\&\n" |
| 3220 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 3221 |
"\\&\n" |
| 3222 |
" /* Install seccomp filter(s) */\n" |
| 3223 |
"\\&\n" |
| 3224 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 3225 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 3226 |
"\\&\n" |
| 3227 |
" notifyFd = installNotifyFilter();\n" |
| 3228 |
"\\&\n" |
| 3229 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 3230 |
" a UNIX domain socket */\n" |
| 3231 |
"\\&\n" |
| 3232 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 3233 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 3234 |
"\\&\n" |
| 3235 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 3236 |
"\\&\n" |
| 3237 |
" if (close(notifyFd) == -1)\n" |
| 3238 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 3239 |
"\\&\n" |
| 3240 |
" closeSocketPair(sockPair);\n" |
| 3241 |
"\\&\n" |
| 3242 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 3243 |
"\\&\n" |
| 3244 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 3245 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 3246 |
"\\&\n" |
| 3247 |
" s = mkdir(*ap, 0700);\n" |
| 3248 |
" if (s == -1)\n" |
| 3249 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 3250 |
" else\n" |
| 3251 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 3252 |
" }\n" |
| 3253 |
"\\&\n" |
| 3254 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 3255 |
" exit(EXIT_SUCCESS);\n" |
| 3256 |
"}\n" |
| 3257 |
"\\&\n" |
| 3258 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 3259 |
" operation is still valid. It will no longer be valid if the target\n" |
| 3260 |
" process has terminated or is no longer blocked in the system call that\n" |
| 3261 |
" generated the notification (because it was interrupted by a signal).\n" |
| 3262 |
"\\&\n" |
| 3263 |
" This operation can be used when doing such things as accessing\n" |
| 3264 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 3265 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 3266 |
" terminates and is reused by another process. */\n" |
| 3267 |
"\\&\n" |
| 3268 |
"static bool\n" |
| 3269 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 3270 |
"{\n" |
| 3271 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 3272 |
"}\n" |
| 3273 |
"\\&\n" |
| 3274 |
"/* Access the memory of the target process in order to fetch the\n" |
| 3275 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 3276 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 3277 |
" a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" |
| 3278 |
"\\&\n" |
| 3279 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 3280 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 3281 |
"\\&\n" |
| 3282 |
"static bool\n" |
| 3283 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 3284 |
" int argNum, char *path, size_t size)\n" |
| 3285 |
"{\n" |
| 3286 |
" int procMemFd;\n" |
| 3287 |
" char procMemPath[PATH_MAX];\n" |
| 3288 |
" ssize_t nread;\n" |
| 3289 |
"\\&\n" |
| 3290 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 3291 |
"\\&\n" |
| 3292 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 3293 |
" if (procMemFd == -1)\n" |
| 3294 |
" return false;\n" |
| 3295 |
"\\&\n" |
| 3296 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 3297 |
" and blocked in the system call that caused the notification.\n" |
| 3298 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 3299 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 3300 |
" descriptor that we opened corresponded to the process for which we\n" |
| 3301 |
" received a notification. If that process subsequently terminates,\n" |
| 3302 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 3303 |
"\\&\n" |
| 3304 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 3305 |
" close(procMemFd);\n" |
| 3306 |
" return false;\n" |
| 3307 |
" }\n" |
| 3308 |
"\\&\n" |
| 3309 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 3310 |
"\\&\n" |
| 3311 |
" nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n" |
| 3312 |
"\\&\n" |
| 3313 |
" close(procMemFd);\n" |
| 3314 |
"\\&\n" |
| 3315 |
" if (nread E<lt>= 0)\n" |
| 3316 |
" return false;\n" |
| 3317 |
"\\&\n" |
| 3318 |
" /* Once again check that the notification ID is still valid. The\n" |
| 3319 |
" case we are particularly concerned about here is that just\n" |
| 3320 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 3321 |
" call was interrupted by a signal handler, and after the handler\n" |
| 3322 |
" returned, the target carried on execution (past the interrupted\n" |
| 3323 |
" system call). In that case, we have no guarantees about what we\n" |
| 3324 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 3325 |
" changed by subsequent operations. */\n" |
| 3326 |
"\\&\n" |
| 3327 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 3328 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 3329 |
" return false;\n" |
| 3330 |
" }\n" |
| 3331 |
"\\&\n" |
| 3332 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 3333 |
" we have no guarantees about what was in the memory of the target\n" |
| 3334 |
" process. (The memory may have been modified by another thread, or\n" |
| 3335 |
" even by an external attacking process.) We therefore treat the\n" |
| 3336 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 3337 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 3338 |
" error for the target process. */\n" |
| 3339 |
"\\&\n" |
| 3340 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 3341 |
" return true;\n" |
| 3342 |
"\\&\n" |
| 3343 |
" return false;\n" |
| 3344 |
"}\n" |
| 3345 |
"\\&\n" |
| 3346 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 3347 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 3348 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 3349 |
"\\&\n" |
| 3350 |
"static void\n" |
| 3351 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 3352 |
" struct seccomp_notif_resp **resp,\n" |
| 3353 |
" struct seccomp_notif_sizes *sizes)\n" |
| 3354 |
"{\n" |
| 3355 |
" size_t resp_size;\n" |
| 3356 |
"\\&\n" |
| 3357 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 3358 |
" notifications and send notification responses, and allocate\n" |
| 3359 |
" buffers of those sizes. */\n" |
| 3360 |
"\\&\n" |
| 3361 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 3362 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 3363 |
"\\&\n" |
| 3364 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 3365 |
" if (*req == NULL)\n" |
| 3366 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 3367 |
"\\&\n" |
| 3368 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 3369 |
" that the user-space binary may have been built with user-space\n" |
| 3370 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 3371 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 3372 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 3373 |
" ensures that if the supervisor places bytes into the response\n" |
| 3374 |
" structure that are past the response size that the kernel expects,\n" |
| 3375 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 3376 |
"\\&\n" |
| 3377 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 3378 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 3379 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 3380 |
"\\&\n" |
| 3381 |
" *resp = malloc(resp_size);\n" |
| 3382 |
" if (*resp == NULL)\n" |
| 3383 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 3384 |
"\\&\n" |
| 3385 |
"}\n" |
| 3386 |
"\\&\n" |
| 3387 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 3388 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 3389 |
"\\&\n" |
| 3390 |
"static void\n" |
| 3391 |
"handleNotifications(int notifyFd)\n" |
| 3392 |
"{\n" |
| 3393 |
" bool pathOK;\n" |
| 3394 |
" char path[PATH_MAX];\n" |
| 3395 |
" struct seccomp_notif *req;\n" |
| 3396 |
" struct seccomp_notif_resp *resp;\n" |
| 3397 |
" struct seccomp_notif_sizes sizes;\n" |
| 3398 |
"\\&\n" |
| 3399 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 3400 |
"\\&\n" |
| 3401 |
" /* Loop handling notifications */\n" |
| 3402 |
"\\&\n" |
| 3403 |
" for (;;) {\n" |
| 3404 |
"\\&\n" |
| 3405 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 3406 |
"\\&\n" |
| 3407 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 3408 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 3409 |
" if (errno == EINTR)\n" |
| 3410 |
" continue;\n" |
| 3411 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 3412 |
" }\n" |
| 3413 |
"\\&\n" |
| 3414 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 3415 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 3416 |
"\\&\n" |
| 3417 |
" /* The only system call that can generate a notification event\n" |
| 3418 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 3419 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 3420 |
" code in case the seccomp filter is later modified to\n" |
| 3421 |
" generate notifications for other system calls. */\n" |
| 3422 |
"\\&\n" |
| 3423 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 3424 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 3425 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 3426 |
" exit(EXIT_FAILURE);\n" |
| 3427 |
" }\n" |
| 3428 |
"\\&\n" |
| 3429 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 3430 |
"\\&\n" |
| 3431 |
" /* Prepopulate some fields of the response */\n" |
| 3432 |
"\\&\n" |
| 3433 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 3434 |
" resp-E<gt>flags = 0;\n" |
| 3435 |
" resp-E<gt>val = 0;\n" |
| 3436 |
"\\&\n" |
| 3437 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 3438 |
" response (sending this response may yield an error if the\n" |
| 3439 |
" failure occurred because the notification ID was no longer\n" |
| 3440 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 3441 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 3442 |
" kernel to let the target process execute the mkdir();\n" |
| 3443 |
" otherwise, give an error for a directory pathname in any other\n" |
| 3444 |
" location. */\n" |
| 3445 |
"\\&\n" |
| 3446 |
" if (!pathOK) {\n" |
| 3447 |
" resp-E<gt>error = -EINVAL;\n" |
| 3448 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 3449 |
" strerror(-resp-E<gt>error));\n" |
| 3450 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 3451 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 3452 |
" path, req-E<gt>data.args[1]);\n" |
| 3453 |
"\\&\n" |
| 3454 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 3455 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 3456 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 3457 |
" mkdir() in target */\n" |
| 3458 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 3459 |
" resp-E<gt>val);\n" |
| 3460 |
" } else {\n" |
| 3461 |
"\\&\n" |
| 3462 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 3463 |
" back to the target */\n" |
| 3464 |
"\\&\n" |
| 3465 |
" resp-E<gt>error = -errno;\n" |
| 3466 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 3467 |
" strerror(errno));\n" |
| 3468 |
" }\n" |
| 3469 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 3470 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 3471 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 3472 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 3473 |
" } else {\n" |
| 3474 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 3475 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 3476 |
" strerror(-resp-E<gt>error));\n" |
| 3477 |
" }\n" |
| 3478 |
"\\&\n" |
| 3479 |
" /* Send a response to the notification */\n" |
| 3480 |
"\\&\n" |
| 3481 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 3482 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 3483 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 3484 |
"\\&\n" |
| 3485 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 3486 |
" if (errno == ENOENT)\n" |
| 3487 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 3488 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 3489 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 3490 |
" else\n" |
| 3491 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 3492 |
" }\n" |
| 3493 |
"\\&\n" |
| 3494 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 3495 |
" of the loop and terminates. This allows us to see what happens\n" |
| 3496 |
" if the target process makes further calls to mkdir(2). */\n" |
| 3497 |
"\\&\n" |
| 3498 |
" if (streq(path, \"/bye\"))\n" |
| 3499 |
" break;\n" |
| 3500 |
" }\n" |
| 3501 |
"\\&\n" |
| 3502 |
" free(req);\n" |
| 3503 |
" free(resp);\n" |
| 3504 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 3505 |
" exit(EXIT_FAILURE);\n" |
| 3506 |
"}\n" |
| 3507 |
"\\&\n" |
| 3508 |
"/* Implementation of the supervisor process:\n" |
| 3509 |
"\\&\n" |
| 3510 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 3511 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 3512 |
"\\&\n" |
| 3513 |
"static void\n" |
| 3514 |
"supervisor(int sockPair[2])\n" |
| 3515 |
"{\n" |
| 3516 |
" int notifyFd;\n" |
| 3517 |
"\\&\n" |
| 3518 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 3519 |
"\\&\n" |
| 3520 |
" if (notifyFd == -1)\n" |
| 3521 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 3522 |
"\\&\n" |
| 3523 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 3524 |
"\\&\n" |
| 3525 |
" handleNotifications(notifyFd);\n" |
| 3526 |
"}\n" |
| 3527 |
"\\&\n" |
| 3528 |
"int\n" |
| 3529 |
"main(int argc, char *argv[])\n" |
| 3530 |
"{\n" |
| 3531 |
" int sockPair[2];\n" |
| 3532 |
" struct sigaction sa;\n" |
| 3533 |
"\\&\n" |
| 3534 |
" setbuf(stdout, NULL);\n" |
| 3535 |
"\\&\n" |
| 3536 |
" if (argc E<lt> 2) {\n" |
| 3537 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 3538 |
" exit(EXIT_FAILURE);\n" |
| 3539 |
" }\n" |
| 3540 |
"\\&\n" |
| 3541 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 3542 |
" notification file descriptor from the target process to the\n" |
| 3543 |
" supervisor process. */\n" |
| 3544 |
"\\&\n" |
| 3545 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 3546 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 3547 |
"\\&\n" |
| 3548 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 3549 |
" filtering. The target process writes the seccomp notification\n" |
| 3550 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 3551 |
" each directory in the command-line arguments. */\n" |
| 3552 |
"\\&\n" |
| 3553 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 3554 |
"\\&\n" |
| 3555 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 3556 |
" supervisor can also terminate. */\n" |
| 3557 |
"\\&\n" |
| 3558 |
" sa.sa_handler = sigchldHandler;\n" |
| 3559 |
" sa.sa_flags = 0;\n" |
| 3560 |
" sigemptyset(&sa.sa_mask);\n" |
| 3561 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 3562 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 3563 |
"\\&\n" |
| 3564 |
" supervisor(sockPair);\n" |
| 3565 |
"\\&\n" |
| 3566 |
" exit(EXIT_SUCCESS);\n" |
| 3567 |
"}\n" |
| 3568 |
msgstr "" |
| 3569 |
"#define _GNU_SOURCE\n" |
| 3570 |
"#include E<lt>err.hE<gt>\n" |
| 3571 |
"#include E<lt>errno.hE<gt>\n" |
| 3572 |
"#include E<lt>fcntl.hE<gt>\n" |
| 3573 |
"#include E<lt>limits.hE<gt>\n" |
| 3574 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 3575 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 3576 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 3577 |
"#include E<lt>signal.hE<gt>\n" |
| 3578 |
"#include E<lt>stdbool.hE<gt>\n" |
| 3579 |
"#include E<lt>stdcountof.hE<gt>\n" |
| 3580 |
"#include E<lt>stddef.hE<gt>\n" |
| 3581 |
"#include E<lt>stdint.hE<gt>\n" |
| 3582 |
"#include E<lt>stdio.hE<gt>\n" |
| 3583 |
"#include E<lt>stdlib.hE<gt>\n" |
| 3584 |
"#include E<lt>string.hE<gt>\n" |
| 3585 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 3586 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 3587 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 3588 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 3589 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 3590 |
"#include E<lt>sys/types.hE<gt>\n" |
| 3591 |
"#include E<lt>sys/un.hE<gt>\n" |
| 3592 |
"#include E<lt>unistd.hE<gt>\n" |
| 3593 |
"\\&\n" |
| 3594 |
"#define streq(...) (strcmp(__VA_ARGS__) == 0)\n" |
| 3595 |
"\\&\n" |
| 3596 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 3597 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 3598 |
"\\&\n" |
| 3599 |
"static int\n" |
| 3600 |
"sendfd(int sockfd, int fd)\n" |
| 3601 |
"{\n" |
| 3602 |
" int data;\n" |
| 3603 |
" struct iovec iov;\n" |
| 3604 |
" struct msghdr msgh;\n" |
| 3605 |
" struct cmsghdr *cmsgp;\n" |
| 3606 |
"\\&\n" |
| 3607 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 3608 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 3609 |
" union to ensure that it is suitably aligned. */\n" |
| 3610 |
" union {\n" |
| 3611 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 3612 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 3613 |
" struct cmsghdr align;\n" |
| 3614 |
" } controlMsg;\n" |
| 3615 |
"\\&\n" |
| 3616 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 3617 |
" destination socket when sending a datagram. However, we do not\n" |
| 3618 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 3619 |
"\\&\n" |
| 3620 |
" msgh.msg_name = NULL;\n" |
| 3621 |
" msgh.msg_namelen = 0;\n" |
| 3622 |
"\\&\n" |
| 3623 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 3624 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 3625 |
" whose value is ignored by recvfd(). */\n" |
| 3626 |
"\\&\n" |
| 3627 |
" msgh.msg_iov = &iov;\n" |
| 3628 |
" msgh.msg_iovlen = 1;\n" |
| 3629 |
" iov.iov_base = &data;\n" |
| 3630 |
" iov.iov_len = sizeof(int);\n" |
| 3631 |
" data = 12345;\n" |
| 3632 |
"\\&\n" |
| 3633 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 3634 |
"\\&\n" |
| 3635 |
" msgh.msg_control = controlMsg.buf;\n" |
| 3636 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 3637 |
"\\&\n" |
| 3638 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 3639 |
"\\&\n" |
| 3640 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 3641 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 3642 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 3643 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 3644 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 3645 |
"\\&\n" |
| 3646 |
" /* Send real plus ancillary data */\n" |
| 3647 |
"\\&\n" |
| 3648 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 3649 |
" return -1;\n" |
| 3650 |
"\\&\n" |
| 3651 |
" return 0;\n" |
| 3652 |
"}\n" |
| 3653 |
"\\&\n" |
| 3654 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 3655 |
" the received file descriptor on success, or -1 on error. */\n" |
| 3656 |
"\\&\n" |
| 3657 |
"static int\n" |
| 3658 |
"recvfd(int sockfd)\n" |
| 3659 |
"{\n" |
| 3660 |
" int data, fd;\n" |
| 3661 |
" ssize_t nr;\n" |
| 3662 |
" struct iovec iov;\n" |
| 3663 |
" struct msghdr msgh;\n" |
| 3664 |
"\\&\n" |
| 3665 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 3666 |
" in sendfd() */\n" |
| 3667 |
" union {\n" |
| 3668 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 3669 |
" struct cmsghdr align;\n" |
| 3670 |
" } controlMsg;\n" |
| 3671 |
" struct cmsghdr *cmsgp;\n" |
| 3672 |
"\\&\n" |
| 3673 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 3674 |
" sending socket. However, we do not need this information. */\n" |
| 3675 |
"\\&\n" |
| 3676 |
" msgh.msg_name = NULL;\n" |
| 3677 |
" msgh.msg_namelen = 0;\n" |
| 3678 |
"\\&\n" |
| 3679 |
" /* Specify buffer for receiving real data */\n" |
| 3680 |
"\\&\n" |
| 3681 |
" msgh.msg_iov = &iov;\n" |
| 3682 |
" msgh.msg_iovlen = 1;\n" |
| 3683 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 3684 |
" iov.iov_len = sizeof(int);\n" |
| 3685 |
"\\&\n" |
| 3686 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 3687 |
"\\&\n" |
| 3688 |
" msgh.msg_control = controlMsg.buf;\n" |
| 3689 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 3690 |
"\\&\n" |
| 3691 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 3692 |
"\\&\n" |
| 3693 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 3694 |
" if (nr == -1)\n" |
| 3695 |
" return -1;\n" |
| 3696 |
"\\&\n" |
| 3697 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 3698 |
"\\&\n" |
| 3699 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 3700 |
"\\&\n" |
| 3701 |
" if (cmsgp == NULL\n" |
| 3702 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 3703 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 3704 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 3705 |
" {\n" |
| 3706 |
" errno = EINVAL;\n" |
| 3707 |
" return -1;\n" |
| 3708 |
" }\n" |
| 3709 |
"\\&\n" |
| 3710 |
" /* Return the received file descriptor to our caller */\n" |
| 3711 |
"\\&\n" |
| 3712 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 3713 |
" return fd;\n" |
| 3714 |
"}\n" |
| 3715 |
"\\&\n" |
| 3716 |
"static void\n" |
| 3717 |
"sigchldHandler(int sig)\n" |
| 3718 |
"{\n" |
| 3719 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 3720 |
"\\&\n" |
| 3721 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 3722 |
" _exit(EXIT_SUCCESS);\n" |
| 3723 |
"}\n" |
| 3724 |
"\\&\n" |
| 3725 |
"static int\n" |
| 3726 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 3727 |
"{\n" |
| 3728 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 3729 |
"}\n" |
| 3730 |
"\\&\n" |
| 3731 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 3732 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 3733 |
" completion of these instructions, the accumulator contains the system\n" |
| 3734 |
" call number. */\n" |
| 3735 |
"\\&\n" |
| 3736 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 3737 |
"\\&\n" |
| 3738 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 3739 |
"\\&\n" |
| 3740 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 3741 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 3742 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 3743 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 3744 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 3745 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 3746 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 3747 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 3748 |
"\\&\n" |
| 3749 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 3750 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 3751 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 3752 |
"\\&\n" |
| 3753 |
" The function return value is a file descriptor from which the\n" |
| 3754 |
" user-space notifications can be fetched. */\n" |
| 3755 |
"\\&\n" |
| 3756 |
"static int\n" |
| 3757 |
"installNotifyFilter(void)\n" |
| 3758 |
"{\n" |
| 3759 |
" int notifyFd;\n" |
| 3760 |
"\\&\n" |
| 3761 |
" struct sock_filter filter[] = {\n" |
| 3762 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 3763 |
"\\&\n" |
| 3764 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 3765 |
"\\&\n" |
| 3766 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 3767 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 3768 |
"\\&\n" |
| 3769 |
" /* Every other system call is allowed */\n" |
| 3770 |
"\\&\n" |
| 3771 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 3772 |
" };\n" |
| 3773 |
"\\&\n" |
| 3774 |
" struct sock_fprog prog = {\n" |
| 3775 |
" .len = countof(filter),\n" |
| 3776 |
" .filter = filter,\n" |
| 3777 |
" };\n" |
| 3778 |
"\\&\n" |
| 3779 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 3780 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 3781 |
"\\&\n" |
| 3782 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 3783 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 3784 |
" if (notifyFd == -1)\n" |
| 3785 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 3786 |
"\\&\n" |
| 3787 |
" return notifyFd;\n" |
| 3788 |
"}\n" |
| 3789 |
"\\&\n" |
| 3790 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 3791 |
"\\&\n" |
| 3792 |
"static void\n" |
| 3793 |
"closeSocketPair(int sockPair[2])\n" |
| 3794 |
"{\n" |
| 3795 |
" if (close(sockPair[0]) == -1)\n" |
| 3796 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 3797 |
" if (close(sockPair[1]) == -1)\n" |
| 3798 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 3799 |
"}\n" |
| 3800 |
"\\&\n" |
| 3801 |
"/* Implementation of the target process. Create a child process that:\n" |
| 3802 |
"\\&\n" |
| 3803 |
" (1) installs a seccomp filter with the\n" |
| 3804 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 3805 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 3806 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 3807 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 3808 |
"\\&\n" |
| 3809 |
" The function return value in the parent is the PID of the child\n" |
| 3810 |
" process; the child does not return from this function. */\n" |
| 3811 |
"\\&\n" |
| 3812 |
"static pid_t\n" |
| 3813 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 3814 |
"{\n" |
| 3815 |
" int notifyFd, s;\n" |
| 3816 |
" pid_t targetPid;\n" |
| 3817 |
"\\&\n" |
| 3818 |
" targetPid = fork();\n" |
| 3819 |
"\\&\n" |
| 3820 |
" if (targetPid == -1)\n" |
| 3821 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 3822 |
"\\&\n" |
| 3823 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 3824 |
" return targetPid;\n" |
| 3825 |
"\\&\n" |
| 3826 |
" /* Child falls through to here */\n" |
| 3827 |
"\\&\n" |
| 3828 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 3829 |
"\\&\n" |
| 3830 |
" /* Install seccomp filter(s) */\n" |
| 3831 |
"\\&\n" |
| 3832 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 3833 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 3834 |
"\\&\n" |
| 3835 |
" notifyFd = installNotifyFilter();\n" |
| 3836 |
"\\&\n" |
| 3837 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 3838 |
" a UNIX domain socket */\n" |
| 3839 |
"\\&\n" |
| 3840 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 3841 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 3842 |
"\\&\n" |
| 3843 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 3844 |
"\\&\n" |
| 3845 |
" if (close(notifyFd) == -1)\n" |
| 3846 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 3847 |
"\\&\n" |
| 3848 |
" closeSocketPair(sockPair);\n" |
| 3849 |
"\\&\n" |
| 3850 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 3851 |
"\\&\n" |
| 3852 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 3853 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 3854 |
"\\&\n" |
| 3855 |
" s = mkdir(*ap, 0700);\n" |
| 3856 |
" if (s == -1)\n" |
| 3857 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 3858 |
" else\n" |
| 3859 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 3860 |
" }\n" |
| 3861 |
"\\&\n" |
| 3862 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 3863 |
" exit(EXIT_SUCCESS);\n" |
| 3864 |
"}\n" |
| 3865 |
"\\&\n" |
| 3866 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 3867 |
" operation is still valid. It will no longer be valid if the target\n" |
| 3868 |
" process has terminated or is no longer blocked in the system call that\n" |
| 3869 |
" generated the notification (because it was interrupted by a signal).\n" |
| 3870 |
"\\&\n" |
| 3871 |
" This operation can be used when doing such things as accessing\n" |
| 3872 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 3873 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 3874 |
" terminates and is reused by another process. */\n" |
| 3875 |
"\\&\n" |
| 3876 |
"static bool\n" |
| 3877 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 3878 |
"{\n" |
| 3879 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 3880 |
"}\n" |
| 3881 |
"\\&\n" |
| 3882 |
"/* Access the memory of the target process in order to fetch the\n" |
| 3883 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 3884 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 3885 |
" a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" |
| 3886 |
"\\&\n" |
| 3887 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 3888 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 3889 |
"\\&\n" |
| 3890 |
"static bool\n" |
| 3891 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 3892 |
" int argNum, char *path, size_t size)\n" |
| 3893 |
"{\n" |
| 3894 |
" int procMemFd;\n" |
| 3895 |
" char procMemPath[PATH_MAX];\n" |
| 3896 |
" ssize_t nread;\n" |
| 3897 |
"\\&\n" |
| 3898 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 3899 |
"\\&\n" |
| 3900 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 3901 |
" if (procMemFd == -1)\n" |
| 3902 |
" return false;\n" |
| 3903 |
"\\&\n" |
| 3904 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 3905 |
" and blocked in the system call that caused the notification.\n" |
| 3906 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 3907 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 3908 |
" descriptor that we opened corresponded to the process for which we\n" |
| 3909 |
" received a notification. If that process subsequently terminates,\n" |
| 3910 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 3911 |
"\\&\n" |
| 3912 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 3913 |
" close(procMemFd);\n" |
| 3914 |
" return false;\n" |
| 3915 |
" }\n" |
| 3916 |
"\\&\n" |
| 3917 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 3918 |
"\\&\n" |
| 3919 |
" nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n" |
| 3920 |
"\\&\n" |
| 3921 |
" close(procMemFd);\n" |
| 3922 |
"\\&\n" |
| 3923 |
" if (nread E<lt>= 0)\n" |
| 3924 |
" return false;\n" |
| 3925 |
"\\&\n" |
| 3926 |
" /* Once again check that the notification ID is still valid. The\n" |
| 3927 |
" case we are particularly concerned about here is that just\n" |
| 3928 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 3929 |
" call was interrupted by a signal handler, and after the handler\n" |
| 3930 |
" returned, the target carried on execution (past the interrupted\n" |
| 3931 |
" system call). In that case, we have no guarantees about what we\n" |
| 3932 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 3933 |
" changed by subsequent operations. */\n" |
| 3934 |
"\\&\n" |
| 3935 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 3936 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 3937 |
" return false;\n" |
| 3938 |
" }\n" |
| 3939 |
"\\&\n" |
| 3940 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 3941 |
" we have no guarantees about what was in the memory of the target\n" |
| 3942 |
" process. (The memory may have been modified by another thread, or\n" |
| 3943 |
" even by an external attacking process.) We therefore treat the\n" |
| 3944 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 3945 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 3946 |
" error for the target process. */\n" |
| 3947 |
"\\&\n" |
| 3948 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 3949 |
" return true;\n" |
| 3950 |
"\\&\n" |
| 3951 |
" return false;\n" |
| 3952 |
"}\n" |
| 3953 |
"\\&\n" |
| 3954 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 3955 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 3956 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 3957 |
"\\&\n" |
| 3958 |
"static void\n" |
| 3959 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 3960 |
" struct seccomp_notif_resp **resp,\n" |
| 3961 |
" struct seccomp_notif_sizes *sizes)\n" |
| 3962 |
"{\n" |
| 3963 |
" size_t resp_size;\n" |
| 3964 |
"\\&\n" |
| 3965 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 3966 |
" notifications and send notification responses, and allocate\n" |
| 3967 |
" buffers of those sizes. */\n" |
| 3968 |
"\\&\n" |
| 3969 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 3970 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 3971 |
"\\&\n" |
| 3972 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 3973 |
" if (*req == NULL)\n" |
| 3974 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 3975 |
"\\&\n" |
| 3976 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 3977 |
" that the user-space binary may have been built with user-space\n" |
| 3978 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 3979 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 3980 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 3981 |
" ensures that if the supervisor places bytes into the response\n" |
| 3982 |
" structure that are past the response size that the kernel expects,\n" |
| 3983 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 3984 |
"\\&\n" |
| 3985 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 3986 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 3987 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 3988 |
"\\&\n" |
| 3989 |
" *resp = malloc(resp_size);\n" |
| 3990 |
" if (*resp == NULL)\n" |
| 3991 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 3992 |
"\\&\n" |
| 3993 |
"}\n" |
| 3994 |
"\\&\n" |
| 3995 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 3996 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 3997 |
"\\&\n" |
| 3998 |
"static void\n" |
| 3999 |
"handleNotifications(int notifyFd)\n" |
| 4000 |
"{\n" |
| 4001 |
" bool pathOK;\n" |
| 4002 |
" char path[PATH_MAX];\n" |
| 4003 |
" struct seccomp_notif *req;\n" |
| 4004 |
" struct seccomp_notif_resp *resp;\n" |
| 4005 |
" struct seccomp_notif_sizes sizes;\n" |
| 4006 |
"\\&\n" |
| 4007 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 4008 |
"\\&\n" |
| 4009 |
" /* Loop handling notifications */\n" |
| 4010 |
"\\&\n" |
| 4011 |
" for (;;) {\n" |
| 4012 |
"\\&\n" |
| 4013 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 4014 |
"\\&\n" |
| 4015 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 4016 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 4017 |
" if (errno == EINTR)\n" |
| 4018 |
" continue;\n" |
| 4019 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 4020 |
" }\n" |
| 4021 |
"\\&\n" |
| 4022 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 4023 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 4024 |
"\\&\n" |
| 4025 |
" /* The only system call that can generate a notification event\n" |
| 4026 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 4027 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 4028 |
" code in case the seccomp filter is later modified to\n" |
| 4029 |
" generate notifications for other system calls. */\n" |
| 4030 |
"\\&\n" |
| 4031 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 4032 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 4033 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 4034 |
" exit(EXIT_FAILURE);\n" |
| 4035 |
" }\n" |
| 4036 |
"\\&\n" |
| 4037 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 4038 |
"\\&\n" |
| 4039 |
" /* Prepopulate some fields of the response */\n" |
| 4040 |
"\\&\n" |
| 4041 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 4042 |
" resp-E<gt>flags = 0;\n" |
| 4043 |
" resp-E<gt>val = 0;\n" |
| 4044 |
"\\&\n" |
| 4045 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 4046 |
" response (sending this response may yield an error if the\n" |
| 4047 |
" failure occurred because the notification ID was no longer\n" |
| 4048 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 4049 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 4050 |
" kernel to let the target process execute the mkdir();\n" |
| 4051 |
" otherwise, give an error for a directory pathname in any other\n" |
| 4052 |
" location. */\n" |
| 4053 |
"\\&\n" |
| 4054 |
" if (!pathOK) {\n" |
| 4055 |
" resp-E<gt>error = -EINVAL;\n" |
| 4056 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 4057 |
" strerror(-resp-E<gt>error));\n" |
| 4058 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 4059 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 4060 |
" path, req-E<gt>data.args[1]);\n" |
| 4061 |
"\\&\n" |
| 4062 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 4063 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 4064 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 4065 |
" mkdir() in target */\n" |
| 4066 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 4067 |
" resp-E<gt>val);\n" |
| 4068 |
" } else {\n" |
| 4069 |
"\\&\n" |
| 4070 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 4071 |
" back to the target */\n" |
| 4072 |
"\\&\n" |
| 4073 |
" resp-E<gt>error = -errno;\n" |
| 4074 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 4075 |
" strerror(errno));\n" |
| 4076 |
" }\n" |
| 4077 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 4078 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 4079 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 4080 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 4081 |
" } else {\n" |
| 4082 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 4083 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 4084 |
" strerror(-resp-E<gt>error));\n" |
| 4085 |
" }\n" |
| 4086 |
"\\&\n" |
| 4087 |
" /* Send a response to the notification */\n" |
| 4088 |
"\\&\n" |
| 4089 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 4090 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 4091 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 4092 |
"\\&\n" |
| 4093 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 4094 |
" if (errno == ENOENT)\n" |
| 4095 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 4096 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 4097 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 4098 |
" else\n" |
| 4099 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 4100 |
" }\n" |
| 4101 |
"\\&\n" |
| 4102 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 4103 |
" of the loop and terminates. This allows us to see what happens\n" |
| 4104 |
" if the target process makes further calls to mkdir(2). */\n" |
| 4105 |
"\\&\n" |
| 4106 |
" if (streq(path, \"/bye\"))\n" |
| 4107 |
" break;\n" |
| 4108 |
" }\n" |
| 4109 |
"\\&\n" |
| 4110 |
" free(req);\n" |
| 4111 |
" free(resp);\n" |
| 4112 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 4113 |
" exit(EXIT_FAILURE);\n" |
| 4114 |
"}\n" |
| 4115 |
"\\&\n" |
| 4116 |
"/* Implementation of the supervisor process:\n" |
| 4117 |
"\\&\n" |
| 4118 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 4119 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 4120 |
"\\&\n" |
| 4121 |
"static void\n" |
| 4122 |
"supervisor(int sockPair[2])\n" |
| 4123 |
"{\n" |
| 4124 |
" int notifyFd;\n" |
| 4125 |
"\\&\n" |
| 4126 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 4127 |
"\\&\n" |
| 4128 |
" if (notifyFd == -1)\n" |
| 4129 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 4130 |
"\\&\n" |
| 4131 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 4132 |
"\\&\n" |
| 4133 |
" handleNotifications(notifyFd);\n" |
| 4134 |
"}\n" |
| 4135 |
"\\&\n" |
| 4136 |
"int\n" |
| 4137 |
"main(int argc, char *argv[])\n" |
| 4138 |
"{\n" |
| 4139 |
" int sockPair[2];\n" |
| 4140 |
" struct sigaction sa;\n" |
| 4141 |
"\\&\n" |
| 4142 |
" setbuf(stdout, NULL);\n" |
| 4143 |
"\\&\n" |
| 4144 |
" if (argc E<lt> 2) {\n" |
| 4145 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 4146 |
" exit(EXIT_FAILURE);\n" |
| 4147 |
" }\n" |
| 4148 |
"\\&\n" |
| 4149 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 4150 |
" notification file descriptor from the target process to the\n" |
| 4151 |
" supervisor process. */\n" |
| 4152 |
"\\&\n" |
| 4153 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 4154 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 4155 |
"\\&\n" |
| 4156 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 4157 |
" filtering. The target process writes the seccomp notification\n" |
| 4158 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 4159 |
" each directory in the command-line arguments. */\n" |
| 4160 |
"\\&\n" |
| 4161 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 4162 |
"\\&\n" |
| 4163 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 4164 |
" supervisor can also terminate. */\n" |
| 4165 |
"\\&\n" |
| 4166 |
" sa.sa_handler = sigchldHandler;\n" |
| 4167 |
" sa.sa_flags = 0;\n" |
| 4168 |
" sigemptyset(&sa.sa_mask);\n" |
| 4169 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 4170 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 4171 |
"\\&\n" |
| 4172 |
" supervisor(sockPair);\n" |
| 4173 |
"\\&\n" |
| 4174 |
" exit(EXIT_SUCCESS);\n" |
| 4175 |
"}\n" |
| 4176 |
|
| 4177 |
#. SRC END |
| 4178 |
#. type: SH |
| 4179 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 4180 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 4181 |
#, no-wrap |
| 4182 |
msgid "SEE ALSO" |
| 4183 |
msgstr "انظر أيضًا" |
| 4184 |
|
| 4185 |
#. type: Plain text |
| 4186 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 4187 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 4188 |
msgid "B<ioctl>(2), B<pidfd_getfd>(2), B<pidfd_open>(2), B<seccomp>(2)" |
| 4189 |
msgstr "B<ioctl>(2)، B<pidfd_getfd>(2)، B<pidfd_open>(2)، B<seccomp>(2)" |
| 4190 |
|
| 4191 |
#. type: Plain text |
| 4192 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 4193 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 4194 |
msgid "" |
| 4195 |
"A further example program can be found in the kernel source file I<samples/" |
| 4196 |
"seccomp/user-trap.c>." |
| 4197 |
msgstr "" |
| 4198 |
"يمكن العثور على مزيد من الأمثلة في ملف مصدر النواة I<samples/seccomp/user-" |
| 4199 |
"trap.c>." |
| 4200 |
|
| 4201 |
#. type: TH |
| 4202 |
#: debian-trixie |
| 4203 |
#, no-wrap |
| 4204 |
msgid "2024-06-15" |
| 4205 |
msgstr "15 يونيو 2024" |
| 4206 |
|
| 4207 |
#. type: TH |
| 4208 |
#: debian-trixie |
| 4209 |
#, no-wrap |
| 4210 |
msgid "Linux man-pages 6.9.1" |
| 4211 |
msgstr "صفحات دليل لينكس 6.9.1" |
| 4212 |
|
| 4213 |
#. type: Plain text |
| 4214 |
#: debian-trixie |
| 4215 |
msgid "Standard C library (I<libc>, I<-lc>)" |
| 4216 |
msgstr "مكتبة سي المعيارية (I<libc>، I<-lc>)" |
| 4217 |
|
| 4218 |
#. type: Plain text |
| 4219 |
#: debian-trixie |
| 4220 |
msgid "" |
| 4221 |
"On success, this operation returns 0; on failure, -1 is returned, and " |
| 4222 |
"I<errno> is set to indicate the cause of the error. This operation can fail " |
| 4223 |
"with the following errors:" |
| 4224 |
msgstr "" |
| 4225 |
"عند النجاح، تعيد هذه العملية 0؛ وعند الفشل، تُعاد -1، ويُضبط I<errno> للإشارة " |
| 4226 |
"إلى سبب الخطأ. يمكن أن تفشل هذه العملية بالأخطاء التالية:" |
| 4227 |
|
| 4228 |
#. type: Plain text |
| 4229 |
#: debian-trixie |
| 4230 |
msgid "" |
| 4231 |
"On error, -1 is returned and I<errno> is set to indicate the cause of the " |
| 4232 |
"error." |
| 4233 |
msgstr "عند الخطأ، تُعاد القيمة -1 ويُضبط I<errno> للإشارة إلى سبب الخطأ." |
| 4234 |
|
| 4235 |
#. type: Plain text |
| 4236 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4237 |
#, no-wrap |
| 4238 |
msgid "" |
| 4239 |
"int fd, removeFd;\n" |
| 4240 |
"\\&\n" |
| 4241 |
"fd = openat(req-E<gt>data.args[0], path, req-E<gt>data.args[2],\n" |
| 4242 |
" req-E<gt>data.args[3]);\n" |
| 4243 |
"\\&\n" |
| 4244 |
"struct seccomp_notif_addfd addfd;\n" |
| 4245 |
"addfd.id = req-E<gt>id; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n" |
| 4246 |
"addfd.srcfd = fd;\n" |
| 4247 |
"addfd.newfd = 0;\n" |
| 4248 |
"addfd.flags = 0;\n" |
| 4249 |
"addfd.newfd_flags = O_CLOEXEC;\n" |
| 4250 |
"\\&\n" |
| 4251 |
"targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" |
| 4252 |
"\\&\n" |
| 4253 |
"close(fd); /* No longer needed in supervisor */\n" |
| 4254 |
"\\&\n" |
| 4255 |
"struct seccomp_notif_resp *resp;\n" |
| 4256 |
" /* Code to allocate 'resp' omitted */\n" |
| 4257 |
"resp-E<gt>id = req-E<gt>id;\n" |
| 4258 |
"resp-E<gt>error = 0; /* \"Success\" */\n" |
| 4259 |
"resp-E<gt>val = targetFd;\n" |
| 4260 |
"resp-E<gt>flags = 0;\n" |
| 4261 |
"ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" |
| 4262 |
msgstr "" |
| 4263 |
"int fd, removeFd;\n" |
| 4264 |
"\\&\n" |
| 4265 |
"fd = openat(req-E<gt>data.args[0], path, req-E<gt>data.args[2],\n" |
| 4266 |
" req-E<gt>data.args[3]);\n" |
| 4267 |
"\\&\n" |
| 4268 |
"struct seccomp_notif_addfd addfd;\n" |
| 4269 |
"addfd.id = req-E<gt>id; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n" |
| 4270 |
"addfd.srcfd = fd;\n" |
| 4271 |
"addfd.newfd = 0;\n" |
| 4272 |
"addfd.flags = 0;\n" |
| 4273 |
"addfd.newfd_flags = O_CLOEXEC;\n" |
| 4274 |
"\\&\n" |
| 4275 |
"targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" |
| 4276 |
"\\&\n" |
| 4277 |
"close(fd); /* No longer needed in supervisor */\n" |
| 4278 |
"\\&\n" |
| 4279 |
"struct seccomp_notif_resp *resp;\n" |
| 4280 |
" /* Code to allocate 'resp' omitted */\n" |
| 4281 |
"resp-E<gt>id = req-E<gt>id;\n" |
| 4282 |
"resp-E<gt>error = 0; /* \"Success\" */\n" |
| 4283 |
"resp-E<gt>val = targetFd;\n" |
| 4284 |
"resp-E<gt>flags = 0;\n" |
| 4285 |
"ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" |
| 4286 |
|
| 4287 |
#. type: SS |
| 4288 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4289 |
#, no-wrap |
| 4290 |
msgid "Caveats regarding the use of I</proc/>tidI</mem>" |
| 4291 |
msgstr "تحذيرات بشأن استخدام I</proc/>tidI</mem>" |
| 4292 |
|
| 4293 |
#. type: Plain text |
| 4294 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4295 |
msgid "" |
| 4296 |
"The discussion above noted the need to use the " |
| 4297 |
"B<SECCOMP_IOCTL_NOTIF_ID_VALID> B<ioctl>(2) when opening the I</proc/>tidI</" |
| 4298 |
"mem> file of the target to avoid the possibility of accessing the memory of " |
| 4299 |
"the wrong process in the event that the target terminates and its ID is " |
| 4300 |
"recycled by another (unrelated) thread. However, the use of this " |
| 4301 |
"B<ioctl>(2) operation is also necessary in other situations, as explained " |
| 4302 |
"in the following paragraphs." |
| 4303 |
msgstr "" |
| 4304 |
"أشارت المناقشة أعلاه إلى الحاجة لاستخدام B<SECCOMP_IOCTL_NOTIF_ID_VALID> " |
| 4305 |
"B<ioctl>(2) عند فتح ملف I</proc/>tidI</mem> الخاص بالمستهدف لتجنب إمكانية " |
| 4306 |
"الوصول إلى ذاكرة عملية خاطئة في حال انتهى المستهدف وأعيد استخدام معرّفه " |
| 4307 |
"بواسطة خيط معالجة آخر (غير ذي صلة). ومع ذلك، فإن استخدام عملية B<ioctl>(2) " |
| 4308 |
"هذه ضروري أيضًا في مواقف أخرى، كما هو موضح في الفقرات التالية." |
| 4309 |
|
| 4310 |
#. type: Plain text |
| 4311 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4312 |
msgid "" |
| 4313 |
"In this scenario, it is important to note that if the target's system call " |
| 4314 |
"is now interrupted by a signal, the supervisor is I<not> informed of this. " |
| 4315 |
"If the supervisor does not take suitable steps to actively discover that the " |
| 4316 |
"target's system call has been canceled, various difficulties can occur. " |
| 4317 |
"Taking the example of B<accept>(2), the supervisor might remain blocked in " |
| 4318 |
"its B<accept>(2) holding a port number that the target (which, after the " |
| 4319 |
"interruption by the signal handler, perhaps closed its listening socket) " |
| 4320 |
"might expect to be able to reuse in a B<bind>(2) call." |
| 4321 |
msgstr "" |
| 4322 |
"في هذا السيناريو، من المهم ملاحظة أنه إذا قوطع نداء نظام المستهدف الآن " |
| 4323 |
"بواسطة إشارة، فإن المشرف I<لا> يُبلغ بذلك. إذا لم يتخذ المشرف خطوات مناسبة " |
| 4324 |
"لاكتشاف أن نداء نظام المستهدف قد أُلغي بشكل نشط، فقد تحدث صعوبات مختلفة. " |
| 4325 |
"وبأخذ B<accept>(2) كمثال، قد يظل المشرف محجوبًا في نداء B<accept>(2) الخاص به " |
| 4326 |
"وهو يحمل رقم منفذ قد يتوقع المستهدف (الذي ربما أغلق مقبس الاستماع الخاص به " |
| 4327 |
"بعد مقاطعته بواسطة معالج الإشارة) أن يتمكن من إعادة استخدامه في نداء " |
| 4328 |
"B<bind>(2)." |
| 4329 |
|
| 4330 |
#. type: Plain text |
| 4331 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4332 |
#, no-wrap |
| 4333 |
msgid "" |
| 4334 |
"$ B<./seccomp_unotify /tmp/x>\n" |
| 4335 |
"T: PID = 23168\n" |
| 4336 |
"\\&\n" |
| 4337 |
"T: about to mkdir(\"/tmp/x\")\n" |
| 4338 |
" S: got notification (ID 0x17445c4a0f4e0e3c) for PID 23168\n" |
| 4339 |
" S: executing: mkdir(\"/tmp/x\", 0700)\n" |
| 4340 |
" S: success! spoofed return = 6\n" |
| 4341 |
" S: sending response (flags = 0; val = 6; error = 0)\n" |
| 4342 |
"T: SUCCESS: mkdir(2) returned 6\n" |
| 4343 |
"\\&\n" |
| 4344 |
"T: terminating\n" |
| 4345 |
" S: target has terminated; bye\n" |
| 4346 |
msgstr "" |
| 4347 |
"$ B<./seccomp_unotify /tmp/x>\n" |
| 4348 |
"T: PID = 23168\n" |
| 4349 |
"\\&\n" |
| 4350 |
"T: على وشك تنفيذ mkdir(\"/tmp/x\")\n" |
| 4351 |
" S: استُلم إشعار (ID 0x17445c4a0f4e0e3c) لـ PID 23168\n" |
| 4352 |
" S: يجري تنفيذ: mkdir(\"/tmp/x\", 0700)\n" |
| 4353 |
" S: نجاح! القيمة الراجعة المزيفة = 6\n" |
| 4354 |
" S: يجري إرسال الاستجابة (flags = 0; val = 6; error = 0)\n" |
| 4355 |
"T: نجاح: أعاد mkdir(2) القيمة 6\n" |
| 4356 |
"\\&\n" |
| 4357 |
"T: يجري الإنهاء\n" |
| 4358 |
" S: انتهى المستهدف؛ وداعًا\n" |
| 4359 |
|
| 4360 |
#. type: Plain text |
| 4361 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4362 |
#, no-wrap |
| 4363 |
msgid "" |
| 4364 |
"$ B<./seccomp_unotify ./sub>\n" |
| 4365 |
"T: PID = 23204\n" |
| 4366 |
"\\&\n" |
| 4367 |
"T: about to mkdir(\"./sub\")\n" |
| 4368 |
" S: got notification (ID 0xddb16abe25b4c12) for PID 23204\n" |
| 4369 |
" S: target can execute system call\n" |
| 4370 |
" S: sending response (flags = 0x1; val = 0; error = 0)\n" |
| 4371 |
"T: SUCCESS: mkdir(2) returned 0\n" |
| 4372 |
"\\&\n" |
| 4373 |
"T: terminating\n" |
| 4374 |
" S: target has terminated; bye\n" |
| 4375 |
msgstr "" |
| 4376 |
"$ B<./seccomp_unotify ./sub>\n" |
| 4377 |
"T: PID = 23204\n" |
| 4378 |
"\\&\n" |
| 4379 |
"T: على وشك تنفيذ mkdir(\"./sub\")\n" |
| 4380 |
" S: استُلم إشعار (ID 0xddb16abe25b4c12) لـ PID 23204\n" |
| 4381 |
" S: يمكن للمستهدف تنفيذ نداء النظام\n" |
| 4382 |
" S: يجري إرسال الاستجابة (flags = 0x1; val = 0; error = 0)\n" |
| 4383 |
"T: نجاح: أعاد mkdir(2) القيمة 0\n" |
| 4384 |
"\\&\n" |
| 4385 |
"T: يجري الإنهاء\n" |
| 4386 |
" S: انتهى المستهدف؛ وداعًا\n" |
| 4387 |
|
| 4388 |
#. type: Plain text |
| 4389 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4390 |
#, no-wrap |
| 4391 |
msgid "" |
| 4392 |
"$ B<./seccomp_unotify /xxx>\n" |
| 4393 |
"T: PID = 23178\n" |
| 4394 |
"\\&\n" |
| 4395 |
"T: about to mkdir(\"/xxx\")\n" |
| 4396 |
" S: got notification (ID 0xe7dc095d1c524e80) for PID 23178\n" |
| 4397 |
" S: spoofing error response (Operation not supported)\n" |
| 4398 |
" S: sending response (flags = 0; val = 0; error = -95)\n" |
| 4399 |
"T: ERROR: mkdir(2): Operation not supported\n" |
| 4400 |
"\\&\n" |
| 4401 |
"T: terminating\n" |
| 4402 |
" S: target has terminated; bye\n" |
| 4403 |
msgstr "" |
| 4404 |
"$ B<./seccomp_unotify /xxx>\n" |
| 4405 |
"T: PID = 23178\n" |
| 4406 |
"\\&\n" |
| 4407 |
"T: على وشك تنفيذ mkdir(\"/xxx\")\n" |
| 4408 |
" S: استُلم إشعار (ID 0xe7dc095d1c524e80) لـ PID 23178\n" |
| 4409 |
" S: تزييف استجابة خطأ (العملية غير مدعومة)\n" |
| 4410 |
" S: يجري إرسال الاستجابة (flags = 0; val = 0; error = -95)\n" |
| 4411 |
"T: خطأ: mkdir(2): العملية غير مدعومة\n" |
| 4412 |
"\\&\n" |
| 4413 |
"T: يجري الإنهاء\n" |
| 4414 |
" S: انتهى المستهدف؛ وداعًا\n" |
| 4415 |
|
| 4416 |
#. type: Plain text |
| 4417 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4418 |
#, no-wrap |
| 4419 |
msgid "" |
| 4420 |
"$ B<./seccomp_unotify /tmp/nosuchdir/b>\n" |
| 4421 |
"T: PID = 23199\n" |
| 4422 |
"\\&\n" |
| 4423 |
"T: about to mkdir(\"/tmp/nosuchdir/b\")\n" |
| 4424 |
" S: got notification (ID 0x8744454293506046) for PID 23199\n" |
| 4425 |
" S: executing: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" |
| 4426 |
" S: failure! (errno = 2; No such file or directory)\n" |
| 4427 |
" S: sending response (flags = 0; val = 0; error = -2)\n" |
| 4428 |
"T: ERROR: mkdir(2): No such file or directory\n" |
| 4429 |
"\\&\n" |
| 4430 |
"T: terminating\n" |
| 4431 |
" S: target has terminated; bye\n" |
| 4432 |
msgstr "" |
| 4433 |
"$ B<./seccomp_unotify /tmp/nosuchdir/b>\n" |
| 4434 |
"T: PID = 23199\n" |
| 4435 |
"\\&\n" |
| 4436 |
"T: على وشك تنفيذ mkdir(\"/tmp/nosuchdir/b\")\n" |
| 4437 |
" S: استُلم إشعار (ID 0x8744454293506046) لـ PID 23199\n" |
| 4438 |
" S: يجري تنفيذ: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" |
| 4439 |
" S: فشل! (errno = 2; لا يوجد ملف أو دليل بهذا الاسم)\n" |
| 4440 |
" S: يجري إرسال الاستجابة (flags = 0; val = 0; error = -2)\n" |
| 4441 |
"T: خطأ: mkdir(2): لا يوجد ملف أو دليل بهذا الاسم\n" |
| 4442 |
"\\&\n" |
| 4443 |
"T: يجري الإنهاء\n" |
| 4444 |
" S: انتهى المستهدف؛ وداعًا\n" |
| 4445 |
|
| 4446 |
#. type: Plain text |
| 4447 |
#: debian-trixie fedora-44 fedora-rawhide |
| 4448 |
#, no-wrap |
| 4449 |
msgid "" |
| 4450 |
"$ B<./seccomp_unotify /bye /tmp/y>\n" |
| 4451 |
"T: PID = 23185\n" |
| 4452 |
"\\&\n" |
| 4453 |
"T: about to mkdir(\"/bye\")\n" |
| 4454 |
" S: got notification (ID 0xa81236b1d2f7b0f4) for PID 23185\n" |
| 4455 |
" S: spoofing error response (Operation not supported)\n" |
| 4456 |
" S: sending response (flags = 0; val = 0; error = -95)\n" |
| 4457 |
" S: terminating **********\n" |
| 4458 |
"T: ERROR: mkdir(2): Operation not supported\n" |
| 4459 |
"\\&\n" |
| 4460 |
"T: about to mkdir(\"/tmp/y\")\n" |
| 4461 |
"T: ERROR: mkdir(2): Function not implemented\n" |
| 4462 |
"\\&\n" |
| 4463 |
"T: terminating\n" |
| 4464 |
msgstr "" |
| 4465 |
"$ B<./seccomp_unotify /bye /tmp/y>\n" |
| 4466 |
"T: PID = 23185\n" |
| 4467 |
"\\&\n" |
| 4468 |
"T: على وشك تنفيذ mkdir(\"/bye\")\n" |
| 4469 |
" S: استُلم إشعار (ID 0xa81236b1d2f7b0f4) لـ PID 23185\n" |
| 4470 |
" S: تزييف استجابة خطأ (العملية غير مدعومة)\n" |
| 4471 |
" S: يجري إرسال الاستجابة (flags = 0; val = 0; error = -95)\n" |
| 4472 |
" S: يجري الإنهاء **********\n" |
| 4473 |
"T: خطأ: mkdir(2): العملية غير مدعومة\n" |
| 4474 |
"\\&\n" |
| 4475 |
"T: على وشك تنفيذ mkdir(\"/tmp/y\")\n" |
| 4476 |
"T: خطأ: mkdir(2): الوظيفة غير مُنفذة\n" |
| 4477 |
"\\&\n" |
| 4478 |
"T: يجري الإنهاء\n" |
| 4479 |
|
| 4480 |
#. type: Plain text |
| 4481 |
#: debian-trixie |
| 4482 |
#, no-wrap |
| 4483 |
msgid "" |
| 4484 |
"#define _GNU_SOURCE\n" |
| 4485 |
"#include E<lt>err.hE<gt>\n" |
| 4486 |
"#include E<lt>errno.hE<gt>\n" |
| 4487 |
"#include E<lt>fcntl.hE<gt>\n" |
| 4488 |
"#include E<lt>limits.hE<gt>\n" |
| 4489 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 4490 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 4491 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 4492 |
"#include E<lt>signal.hE<gt>\n" |
| 4493 |
"#include E<lt>stdbool.hE<gt>\n" |
| 4494 |
"#include E<lt>stddef.hE<gt>\n" |
| 4495 |
"#include E<lt>stdint.hE<gt>\n" |
| 4496 |
"#include E<lt>stdio.hE<gt>\n" |
| 4497 |
"#include E<lt>stdlib.hE<gt>\n" |
| 4498 |
"#include E<lt>string.hE<gt>\n" |
| 4499 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 4500 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 4501 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 4502 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 4503 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 4504 |
"#include E<lt>sys/types.hE<gt>\n" |
| 4505 |
"#include E<lt>sys/un.hE<gt>\n" |
| 4506 |
"#include E<lt>unistd.hE<gt>\n" |
| 4507 |
"\\&\n" |
| 4508 |
"#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" |
| 4509 |
"\\&\n" |
| 4510 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 4511 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 4512 |
"\\&\n" |
| 4513 |
"static int\n" |
| 4514 |
"sendfd(int sockfd, int fd)\n" |
| 4515 |
"{\n" |
| 4516 |
" int data;\n" |
| 4517 |
" struct iovec iov;\n" |
| 4518 |
" struct msghdr msgh;\n" |
| 4519 |
" struct cmsghdr *cmsgp;\n" |
| 4520 |
"\\&\n" |
| 4521 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 4522 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 4523 |
" union to ensure that it is suitably aligned. */\n" |
| 4524 |
" union {\n" |
| 4525 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 4526 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 4527 |
" struct cmsghdr align;\n" |
| 4528 |
" } controlMsg;\n" |
| 4529 |
"\\&\n" |
| 4530 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 4531 |
" destination socket when sending a datagram. However, we do not\n" |
| 4532 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 4533 |
"\\&\n" |
| 4534 |
" msgh.msg_name = NULL;\n" |
| 4535 |
" msgh.msg_namelen = 0;\n" |
| 4536 |
"\\&\n" |
| 4537 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 4538 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 4539 |
" whose value is ignored by recvfd(). */\n" |
| 4540 |
"\\&\n" |
| 4541 |
" msgh.msg_iov = &iov;\n" |
| 4542 |
" msgh.msg_iovlen = 1;\n" |
| 4543 |
" iov.iov_base = &data;\n" |
| 4544 |
" iov.iov_len = sizeof(int);\n" |
| 4545 |
" data = 12345;\n" |
| 4546 |
"\\&\n" |
| 4547 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 4548 |
"\\&\n" |
| 4549 |
" msgh.msg_control = controlMsg.buf;\n" |
| 4550 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 4551 |
"\\&\n" |
| 4552 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 4553 |
"\\&\n" |
| 4554 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 4555 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 4556 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 4557 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 4558 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 4559 |
"\\&\n" |
| 4560 |
" /* Send real plus ancillary data */\n" |
| 4561 |
"\\&\n" |
| 4562 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 4563 |
" return -1;\n" |
| 4564 |
"\\&\n" |
| 4565 |
" return 0;\n" |
| 4566 |
"}\n" |
| 4567 |
"\\&\n" |
| 4568 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 4569 |
" the received file descriptor on success, or -1 on error. */\n" |
| 4570 |
"\\&\n" |
| 4571 |
"static int\n" |
| 4572 |
"recvfd(int sockfd)\n" |
| 4573 |
"{\n" |
| 4574 |
" int data, fd;\n" |
| 4575 |
" ssize_t nr;\n" |
| 4576 |
" struct iovec iov;\n" |
| 4577 |
" struct msghdr msgh;\n" |
| 4578 |
"\\&\n" |
| 4579 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 4580 |
" in sendfd() */\n" |
| 4581 |
" union {\n" |
| 4582 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 4583 |
" struct cmsghdr align;\n" |
| 4584 |
" } controlMsg;\n" |
| 4585 |
" struct cmsghdr *cmsgp;\n" |
| 4586 |
"\\&\n" |
| 4587 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 4588 |
" sending socket. However, we do not need this information. */\n" |
| 4589 |
"\\&\n" |
| 4590 |
" msgh.msg_name = NULL;\n" |
| 4591 |
" msgh.msg_namelen = 0;\n" |
| 4592 |
"\\&\n" |
| 4593 |
" /* Specify buffer for receiving real data */\n" |
| 4594 |
"\\&\n" |
| 4595 |
" msgh.msg_iov = &iov;\n" |
| 4596 |
" msgh.msg_iovlen = 1;\n" |
| 4597 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 4598 |
" iov.iov_len = sizeof(int);\n" |
| 4599 |
"\\&\n" |
| 4600 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 4601 |
"\\&\n" |
| 4602 |
" msgh.msg_control = controlMsg.buf;\n" |
| 4603 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 4604 |
"\\&\n" |
| 4605 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 4606 |
"\\&\n" |
| 4607 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 4608 |
" if (nr == -1)\n" |
| 4609 |
" return -1;\n" |
| 4610 |
"\\&\n" |
| 4611 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 4612 |
"\\&\n" |
| 4613 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 4614 |
"\\&\n" |
| 4615 |
" if (cmsgp == NULL\n" |
| 4616 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 4617 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 4618 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 4619 |
" {\n" |
| 4620 |
" errno = EINVAL;\n" |
| 4621 |
" return -1;\n" |
| 4622 |
" }\n" |
| 4623 |
"\\&\n" |
| 4624 |
" /* Return the received file descriptor to our caller */\n" |
| 4625 |
"\\&\n" |
| 4626 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 4627 |
" return fd;\n" |
| 4628 |
"}\n" |
| 4629 |
"\\&\n" |
| 4630 |
"static void\n" |
| 4631 |
"sigchldHandler(int sig)\n" |
| 4632 |
"{\n" |
| 4633 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 4634 |
"\\&\n" |
| 4635 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 4636 |
" _exit(EXIT_SUCCESS);\n" |
| 4637 |
"}\n" |
| 4638 |
"\\&\n" |
| 4639 |
"static int\n" |
| 4640 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 4641 |
"{\n" |
| 4642 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 4643 |
"}\n" |
| 4644 |
"\\&\n" |
| 4645 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 4646 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 4647 |
" completion of these instructions, the accumulator contains the system\n" |
| 4648 |
" call number. */\n" |
| 4649 |
"\\&\n" |
| 4650 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 4651 |
"\\&\n" |
| 4652 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 4653 |
"\\&\n" |
| 4654 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 4655 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 4656 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 4657 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 4658 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 4659 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 4660 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 4661 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 4662 |
"\\&\n" |
| 4663 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 4664 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 4665 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 4666 |
"\\&\n" |
| 4667 |
" The function return value is a file descriptor from which the\n" |
| 4668 |
" user-space notifications can be fetched. */\n" |
| 4669 |
"\\&\n" |
| 4670 |
"static int\n" |
| 4671 |
"installNotifyFilter(void)\n" |
| 4672 |
"{\n" |
| 4673 |
" int notifyFd;\n" |
| 4674 |
"\\&\n" |
| 4675 |
" struct sock_filter filter[] = {\n" |
| 4676 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 4677 |
"\\&\n" |
| 4678 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 4679 |
"\\&\n" |
| 4680 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 4681 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 4682 |
"\\&\n" |
| 4683 |
" /* Every other system call is allowed */\n" |
| 4684 |
"\\&\n" |
| 4685 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 4686 |
" };\n" |
| 4687 |
"\\&\n" |
| 4688 |
" struct sock_fprog prog = {\n" |
| 4689 |
" .len = ARRAY_SIZE(filter),\n" |
| 4690 |
" .filter = filter,\n" |
| 4691 |
" };\n" |
| 4692 |
"\\&\n" |
| 4693 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 4694 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 4695 |
"\\&\n" |
| 4696 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 4697 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 4698 |
" if (notifyFd == -1)\n" |
| 4699 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 4700 |
"\\&\n" |
| 4701 |
" return notifyFd;\n" |
| 4702 |
"}\n" |
| 4703 |
"\\&\n" |
| 4704 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 4705 |
"\\&\n" |
| 4706 |
"static void\n" |
| 4707 |
"closeSocketPair(int sockPair[2])\n" |
| 4708 |
"{\n" |
| 4709 |
" if (close(sockPair[0]) == -1)\n" |
| 4710 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 4711 |
" if (close(sockPair[1]) == -1)\n" |
| 4712 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 4713 |
"}\n" |
| 4714 |
"\\&\n" |
| 4715 |
"/* Implementation of the target process; create a child process that:\n" |
| 4716 |
"\\&\n" |
| 4717 |
" (1) installs a seccomp filter with the\n" |
| 4718 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 4719 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 4720 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 4721 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 4722 |
"\\&\n" |
| 4723 |
" The function return value in the parent is the PID of the child\n" |
| 4724 |
" process; the child does not return from this function. */\n" |
| 4725 |
"\\&\n" |
| 4726 |
"static pid_t\n" |
| 4727 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 4728 |
"{\n" |
| 4729 |
" int notifyFd, s;\n" |
| 4730 |
" pid_t targetPid;\n" |
| 4731 |
"\\&\n" |
| 4732 |
" targetPid = fork();\n" |
| 4733 |
"\\&\n" |
| 4734 |
" if (targetPid == -1)\n" |
| 4735 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 4736 |
"\\&\n" |
| 4737 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 4738 |
" return targetPid;\n" |
| 4739 |
"\\&\n" |
| 4740 |
" /* Child falls through to here */\n" |
| 4741 |
"\\&\n" |
| 4742 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 4743 |
"\\&\n" |
| 4744 |
" /* Install seccomp filter(s) */\n" |
| 4745 |
"\\&\n" |
| 4746 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 4747 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 4748 |
"\\&\n" |
| 4749 |
" notifyFd = installNotifyFilter();\n" |
| 4750 |
"\\&\n" |
| 4751 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 4752 |
" a UNIX domain socket */\n" |
| 4753 |
"\\&\n" |
| 4754 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 4755 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 4756 |
"\\&\n" |
| 4757 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 4758 |
"\\&\n" |
| 4759 |
" if (close(notifyFd) == -1)\n" |
| 4760 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 4761 |
"\\&\n" |
| 4762 |
" closeSocketPair(sockPair);\n" |
| 4763 |
"\\&\n" |
| 4764 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 4765 |
"\\&\n" |
| 4766 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 4767 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 4768 |
"\\&\n" |
| 4769 |
" s = mkdir(*ap, 0700);\n" |
| 4770 |
" if (s == -1)\n" |
| 4771 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 4772 |
" else\n" |
| 4773 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 4774 |
" }\n" |
| 4775 |
"\\&\n" |
| 4776 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 4777 |
" exit(EXIT_SUCCESS);\n" |
| 4778 |
"}\n" |
| 4779 |
"\\&\n" |
| 4780 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 4781 |
" operation is still valid. It will no longer be valid if the target\n" |
| 4782 |
" process has terminated or is no longer blocked in the system call that\n" |
| 4783 |
" generated the notification (because it was interrupted by a signal).\n" |
| 4784 |
"\\&\n" |
| 4785 |
" This operation can be used when doing such things as accessing\n" |
| 4786 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 4787 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 4788 |
" terminates and is reused by another process. */\n" |
| 4789 |
"\\&\n" |
| 4790 |
"static bool\n" |
| 4791 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 4792 |
"{\n" |
| 4793 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 4794 |
"}\n" |
| 4795 |
"\\&\n" |
| 4796 |
"/* Access the memory of the target process in order to fetch the\n" |
| 4797 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 4798 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 4799 |
" a buffer of \\[aq]len\\[aq] bytes allocated by the caller.\n" |
| 4800 |
"\\&\n" |
| 4801 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 4802 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 4803 |
"\\&\n" |
| 4804 |
"static bool\n" |
| 4805 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 4806 |
" int argNum, char *path, size_t len)\n" |
| 4807 |
"{\n" |
| 4808 |
" int procMemFd;\n" |
| 4809 |
" char procMemPath[PATH_MAX];\n" |
| 4810 |
" ssize_t nread;\n" |
| 4811 |
"\\&\n" |
| 4812 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 4813 |
"\\&\n" |
| 4814 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 4815 |
" if (procMemFd == -1)\n" |
| 4816 |
" return false;\n" |
| 4817 |
"\\&\n" |
| 4818 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 4819 |
" and blocked in the system call that caused the notification.\n" |
| 4820 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 4821 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 4822 |
" descriptor that we opened corresponded to the process for which we\n" |
| 4823 |
" received a notification. If that process subsequently terminates,\n" |
| 4824 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 4825 |
"\\&\n" |
| 4826 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 4827 |
" close(procMemFd);\n" |
| 4828 |
" return false;\n" |
| 4829 |
" }\n" |
| 4830 |
"\\&\n" |
| 4831 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 4832 |
"\\&\n" |
| 4833 |
" nread = pread(procMemFd, path, len, req-E<gt>data.args[argNum]);\n" |
| 4834 |
"\\&\n" |
| 4835 |
" close(procMemFd);\n" |
| 4836 |
"\\&\n" |
| 4837 |
" if (nread E<lt>= 0)\n" |
| 4838 |
" return false;\n" |
| 4839 |
"\\&\n" |
| 4840 |
" /* Once again check that the notification ID is still valid. The\n" |
| 4841 |
" case we are particularly concerned about here is that just\n" |
| 4842 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 4843 |
" call was interrupted by a signal handler, and after the handler\n" |
| 4844 |
" returned, the target carried on execution (past the interrupted\n" |
| 4845 |
" system call). In that case, we have no guarantees about what we\n" |
| 4846 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 4847 |
" changed by subsequent operations. */\n" |
| 4848 |
"\\&\n" |
| 4849 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 4850 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 4851 |
" return false;\n" |
| 4852 |
" }\n" |
| 4853 |
"\\&\n" |
| 4854 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 4855 |
" we have no guarantees about what was in the memory of the target\n" |
| 4856 |
" process. (The memory may have been modified by another thread, or\n" |
| 4857 |
" even by an external attacking process.) We therefore treat the\n" |
| 4858 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 4859 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 4860 |
" error for the target process. */\n" |
| 4861 |
"\\&\n" |
| 4862 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 4863 |
" return true;\n" |
| 4864 |
"\\&\n" |
| 4865 |
" return false;\n" |
| 4866 |
"}\n" |
| 4867 |
"\\&\n" |
| 4868 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 4869 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 4870 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 4871 |
"\\&\n" |
| 4872 |
"static void\n" |
| 4873 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 4874 |
" struct seccomp_notif_resp **resp,\n" |
| 4875 |
" struct seccomp_notif_sizes *sizes)\n" |
| 4876 |
"{\n" |
| 4877 |
" size_t resp_size;\n" |
| 4878 |
"\\&\n" |
| 4879 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 4880 |
" notifications and send notification responses, and allocate\n" |
| 4881 |
" buffers of those sizes. */\n" |
| 4882 |
"\\&\n" |
| 4883 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 4884 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 4885 |
"\\&\n" |
| 4886 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 4887 |
" if (*req == NULL)\n" |
| 4888 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 4889 |
"\\&\n" |
| 4890 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 4891 |
" that the user-space binary may have been built with user-space\n" |
| 4892 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 4893 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 4894 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 4895 |
" ensures that if the supervisor places bytes into the response\n" |
| 4896 |
" structure that are past the response size that the kernel expects,\n" |
| 4897 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 4898 |
"\\&\n" |
| 4899 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 4900 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 4901 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 4902 |
"\\&\n" |
| 4903 |
" *resp = malloc(resp_size);\n" |
| 4904 |
" if (*resp == NULL)\n" |
| 4905 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 4906 |
"\\&\n" |
| 4907 |
"}\n" |
| 4908 |
"\\&\n" |
| 4909 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 4910 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 4911 |
"\\&\n" |
| 4912 |
"static void\n" |
| 4913 |
"handleNotifications(int notifyFd)\n" |
| 4914 |
"{\n" |
| 4915 |
" bool pathOK;\n" |
| 4916 |
" char path[PATH_MAX];\n" |
| 4917 |
" struct seccomp_notif *req;\n" |
| 4918 |
" struct seccomp_notif_resp *resp;\n" |
| 4919 |
" struct seccomp_notif_sizes sizes;\n" |
| 4920 |
"\\&\n" |
| 4921 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 4922 |
"\\&\n" |
| 4923 |
" /* Loop handling notifications */\n" |
| 4924 |
"\\&\n" |
| 4925 |
" for (;;) {\n" |
| 4926 |
"\\&\n" |
| 4927 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 4928 |
"\\&\n" |
| 4929 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 4930 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 4931 |
" if (errno == EINTR)\n" |
| 4932 |
" continue;\n" |
| 4933 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 4934 |
" }\n" |
| 4935 |
"\\&\n" |
| 4936 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 4937 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 4938 |
"\\&\n" |
| 4939 |
" /* The only system call that can generate a notification event\n" |
| 4940 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 4941 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 4942 |
" code in case the seccomp filter is later modified to\n" |
| 4943 |
" generate notifications for other system calls. */\n" |
| 4944 |
"\\&\n" |
| 4945 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 4946 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 4947 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 4948 |
" exit(EXIT_FAILURE);\n" |
| 4949 |
" }\n" |
| 4950 |
"\\&\n" |
| 4951 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 4952 |
"\\&\n" |
| 4953 |
" /* Prepopulate some fields of the response */\n" |
| 4954 |
"\\&\n" |
| 4955 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 4956 |
" resp-E<gt>flags = 0;\n" |
| 4957 |
" resp-E<gt>val = 0;\n" |
| 4958 |
"\\&\n" |
| 4959 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 4960 |
" response (sending this response may yield an error if the\n" |
| 4961 |
" failure occurred because the notification ID was no longer\n" |
| 4962 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 4963 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 4964 |
" kernel to let the target process execute the mkdir();\n" |
| 4965 |
" otherwise, give an error for a directory pathname in any other\n" |
| 4966 |
" location. */\n" |
| 4967 |
"\\&\n" |
| 4968 |
" if (!pathOK) {\n" |
| 4969 |
" resp-E<gt>error = -EINVAL;\n" |
| 4970 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 4971 |
" strerror(-resp-E<gt>error));\n" |
| 4972 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 4973 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 4974 |
" path, req-E<gt>data.args[1]);\n" |
| 4975 |
"\\&\n" |
| 4976 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 4977 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 4978 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 4979 |
" mkdir() in target */\n" |
| 4980 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 4981 |
" resp-E<gt>val);\n" |
| 4982 |
" } else {\n" |
| 4983 |
"\\&\n" |
| 4984 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 4985 |
" back to the target */\n" |
| 4986 |
"\\&\n" |
| 4987 |
" resp-E<gt>error = -errno;\n" |
| 4988 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 4989 |
" strerror(errno));\n" |
| 4990 |
" }\n" |
| 4991 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 4992 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 4993 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 4994 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 4995 |
" } else {\n" |
| 4996 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 4997 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 4998 |
" strerror(-resp-E<gt>error));\n" |
| 4999 |
" }\n" |
| 5000 |
"\\&\n" |
| 5001 |
" /* Send a response to the notification */\n" |
| 5002 |
"\\&\n" |
| 5003 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 5004 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 5005 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 5006 |
"\\&\n" |
| 5007 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 5008 |
" if (errno == ENOENT)\n" |
| 5009 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 5010 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 5011 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 5012 |
" else\n" |
| 5013 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 5014 |
" }\n" |
| 5015 |
"\\&\n" |
| 5016 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 5017 |
" of the loop and terminates. This allows us to see what happens\n" |
| 5018 |
" if the target process makes further calls to mkdir(2). */\n" |
| 5019 |
"\\&\n" |
| 5020 |
" if (strcmp(path, \"/bye\") == 0)\n" |
| 5021 |
" break;\n" |
| 5022 |
" }\n" |
| 5023 |
"\\&\n" |
| 5024 |
" free(req);\n" |
| 5025 |
" free(resp);\n" |
| 5026 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 5027 |
" exit(EXIT_FAILURE);\n" |
| 5028 |
"}\n" |
| 5029 |
"\\&\n" |
| 5030 |
"/* Implementation of the supervisor process:\n" |
| 5031 |
"\\&\n" |
| 5032 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 5033 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 5034 |
"\\&\n" |
| 5035 |
"static void\n" |
| 5036 |
"supervisor(int sockPair[2])\n" |
| 5037 |
"{\n" |
| 5038 |
" int notifyFd;\n" |
| 5039 |
"\\&\n" |
| 5040 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 5041 |
"\\&\n" |
| 5042 |
" if (notifyFd == -1)\n" |
| 5043 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 5044 |
"\\&\n" |
| 5045 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 5046 |
"\\&\n" |
| 5047 |
" handleNotifications(notifyFd);\n" |
| 5048 |
"}\n" |
| 5049 |
"\\&\n" |
| 5050 |
"int\n" |
| 5051 |
"main(int argc, char *argv[])\n" |
| 5052 |
"{\n" |
| 5053 |
" int sockPair[2];\n" |
| 5054 |
" struct sigaction sa;\n" |
| 5055 |
"\\&\n" |
| 5056 |
" setbuf(stdout, NULL);\n" |
| 5057 |
"\\&\n" |
| 5058 |
" if (argc E<lt> 2) {\n" |
| 5059 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 5060 |
" exit(EXIT_FAILURE);\n" |
| 5061 |
" }\n" |
| 5062 |
"\\&\n" |
| 5063 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 5064 |
" notification file descriptor from the target process to the\n" |
| 5065 |
" supervisor process. */\n" |
| 5066 |
"\\&\n" |
| 5067 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 5068 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 5069 |
"\\&\n" |
| 5070 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 5071 |
" filtering. The target process writes the seccomp notification\n" |
| 5072 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 5073 |
" each directory in the command-line arguments. */\n" |
| 5074 |
"\\&\n" |
| 5075 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 5076 |
"\\&\n" |
| 5077 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 5078 |
" supervisor can also terminate. */\n" |
| 5079 |
"\\&\n" |
| 5080 |
" sa.sa_handler = sigchldHandler;\n" |
| 5081 |
" sa.sa_flags = 0;\n" |
| 5082 |
" sigemptyset(&sa.sa_mask);\n" |
| 5083 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 5084 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 5085 |
"\\&\n" |
| 5086 |
" supervisor(sockPair);\n" |
| 5087 |
"\\&\n" |
| 5088 |
" exit(EXIT_SUCCESS);\n" |
| 5089 |
"}\n" |
| 5090 |
msgstr "" |
| 5091 |
"#define _GNU_SOURCE\n" |
| 5092 |
"#include E<lt>err.hE<gt>\n" |
| 5093 |
"#include E<lt>errno.hE<gt>\n" |
| 5094 |
"#include E<lt>fcntl.hE<gt>\n" |
| 5095 |
"#include E<lt>limits.hE<gt>\n" |
| 5096 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 5097 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 5098 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 5099 |
"#include E<lt>signal.hE<gt>\n" |
| 5100 |
"#include E<lt>stdbool.hE<gt>\n" |
| 5101 |
"#include E<lt>stddef.hE<gt>\n" |
| 5102 |
"#include E<lt>stdint.hE<gt>\n" |
| 5103 |
"#include E<lt>stdio.hE<gt>\n" |
| 5104 |
"#include E<lt>stdlib.hE<gt>\n" |
| 5105 |
"#include E<lt>string.hE<gt>\n" |
| 5106 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 5107 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 5108 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 5109 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 5110 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 5111 |
"#include E<lt>sys/types.hE<gt>\n" |
| 5112 |
"#include E<lt>sys/un.hE<gt>\n" |
| 5113 |
"#include E<lt>unistd.hE<gt>\n" |
| 5114 |
"\\&\n" |
| 5115 |
"#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" |
| 5116 |
"\\&\n" |
| 5117 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 5118 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 5119 |
"\\&\n" |
| 5120 |
"static int\n" |
| 5121 |
"sendfd(int sockfd, int fd)\n" |
| 5122 |
"{\n" |
| 5123 |
" int data;\n" |
| 5124 |
" struct iovec iov;\n" |
| 5125 |
" struct msghdr msgh;\n" |
| 5126 |
" struct cmsghdr *cmsgp;\n" |
| 5127 |
"\\&\n" |
| 5128 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 5129 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 5130 |
" union to ensure that it is suitably aligned. */\n" |
| 5131 |
" union {\n" |
| 5132 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 5133 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 5134 |
" struct cmsghdr align;\n" |
| 5135 |
" } controlMsg;\n" |
| 5136 |
"\\&\n" |
| 5137 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 5138 |
" destination socket when sending a datagram. However, we do not\n" |
| 5139 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 5140 |
"\\&\n" |
| 5141 |
" msgh.msg_name = NULL;\n" |
| 5142 |
" msgh.msg_namelen = 0;\n" |
| 5143 |
"\\&\n" |
| 5144 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 5145 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 5146 |
" whose value is ignored by recvfd(). */\n" |
| 5147 |
"\\&\n" |
| 5148 |
" msgh.msg_iov = &iov;\n" |
| 5149 |
" msgh.msg_iovlen = 1;\n" |
| 5150 |
" iov.iov_base = &data;\n" |
| 5151 |
" iov.iov_len = sizeof(int);\n" |
| 5152 |
" data = 12345;\n" |
| 5153 |
"\\&\n" |
| 5154 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 5155 |
"\\&\n" |
| 5156 |
" msgh.msg_control = controlMsg.buf;\n" |
| 5157 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 5158 |
"\\&\n" |
| 5159 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 5160 |
"\\&\n" |
| 5161 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 5162 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 5163 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 5164 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 5165 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 5166 |
"\\&\n" |
| 5167 |
" /* Send real plus ancillary data */\n" |
| 5168 |
"\\&\n" |
| 5169 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 5170 |
" return -1;\n" |
| 5171 |
"\\&\n" |
| 5172 |
" return 0;\n" |
| 5173 |
"}\n" |
| 5174 |
"\\&\n" |
| 5175 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 5176 |
" the received file descriptor on success, or -1 on error. */\n" |
| 5177 |
"\\&\n" |
| 5178 |
"static int\n" |
| 5179 |
"recvfd(int sockfd)\n" |
| 5180 |
"{\n" |
| 5181 |
" int data, fd;\n" |
| 5182 |
" ssize_t nr;\n" |
| 5183 |
" struct iovec iov;\n" |
| 5184 |
" struct msghdr msgh;\n" |
| 5185 |
"\\&\n" |
| 5186 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 5187 |
" in sendfd() */\n" |
| 5188 |
" union {\n" |
| 5189 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 5190 |
" struct cmsghdr align;\n" |
| 5191 |
" } controlMsg;\n" |
| 5192 |
" struct cmsghdr *cmsgp;\n" |
| 5193 |
"\\&\n" |
| 5194 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 5195 |
" sending socket. However, we do not need this information. */\n" |
| 5196 |
"\\&\n" |
| 5197 |
" msgh.msg_name = NULL;\n" |
| 5198 |
" msgh.msg_namelen = 0;\n" |
| 5199 |
"\\&\n" |
| 5200 |
" /* Specify buffer for receiving real data */\n" |
| 5201 |
"\\&\n" |
| 5202 |
" msgh.msg_iov = &iov;\n" |
| 5203 |
" msgh.msg_iovlen = 1;\n" |
| 5204 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 5205 |
" iov.iov_len = sizeof(int);\n" |
| 5206 |
"\\&\n" |
| 5207 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 5208 |
"\\&\n" |
| 5209 |
" msgh.msg_control = controlMsg.buf;\n" |
| 5210 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 5211 |
"\\&\n" |
| 5212 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 5213 |
"\\&\n" |
| 5214 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 5215 |
" if (nr == -1)\n" |
| 5216 |
" return -1;\n" |
| 5217 |
"\\&\n" |
| 5218 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 5219 |
"\\&\n" |
| 5220 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 5221 |
"\\&\n" |
| 5222 |
" if (cmsgp == NULL\n" |
| 5223 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 5224 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 5225 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 5226 |
" {\n" |
| 5227 |
" errno = EINVAL;\n" |
| 5228 |
" return -1;\n" |
| 5229 |
" }\n" |
| 5230 |
"\\&\n" |
| 5231 |
" /* Return the received file descriptor to our caller */\n" |
| 5232 |
"\\&\n" |
| 5233 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 5234 |
" return fd;\n" |
| 5235 |
"}\n" |
| 5236 |
"\\&\n" |
| 5237 |
"static void\n" |
| 5238 |
"sigchldHandler(int sig)\n" |
| 5239 |
"{\n" |
| 5240 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 5241 |
"\\&\n" |
| 5242 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 5243 |
" _exit(EXIT_SUCCESS);\n" |
| 5244 |
"}\n" |
| 5245 |
"\\&\n" |
| 5246 |
"static int\n" |
| 5247 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 5248 |
"{\n" |
| 5249 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 5250 |
"}\n" |
| 5251 |
"\\&\n" |
| 5252 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 5253 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 5254 |
" completion of these instructions, the accumulator contains the system\n" |
| 5255 |
" call number. */\n" |
| 5256 |
"\\&\n" |
| 5257 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 5258 |
"\\&\n" |
| 5259 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 5260 |
"\\&\n" |
| 5261 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 5262 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 5263 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 5264 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 5265 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 5266 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 5267 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 5268 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 5269 |
"\\&\n" |
| 5270 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 5271 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 5272 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 5273 |
"\\&\n" |
| 5274 |
" The function return value is a file descriptor from which the\n" |
| 5275 |
" user-space notifications can be fetched. */\n" |
| 5276 |
"\\&\n" |
| 5277 |
"static int\n" |
| 5278 |
"installNotifyFilter(void)\n" |
| 5279 |
"{\n" |
| 5280 |
" int notifyFd;\n" |
| 5281 |
"\\&\n" |
| 5282 |
" struct sock_filter filter[] = {\n" |
| 5283 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 5284 |
"\\&\n" |
| 5285 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 5286 |
"\\&\n" |
| 5287 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 5288 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 5289 |
"\\&\n" |
| 5290 |
" /* Every other system call is allowed */\n" |
| 5291 |
"\\&\n" |
| 5292 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 5293 |
" };\n" |
| 5294 |
"\\&\n" |
| 5295 |
" struct sock_fprog prog = {\n" |
| 5296 |
" .len = ARRAY_SIZE(filter),\n" |
| 5297 |
" .filter = filter,\n" |
| 5298 |
" };\n" |
| 5299 |
"\\&\n" |
| 5300 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 5301 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 5302 |
"\\&\n" |
| 5303 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 5304 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 5305 |
" if (notifyFd == -1)\n" |
| 5306 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 5307 |
"\\&\n" |
| 5308 |
" return notifyFd;\n" |
| 5309 |
"}\n" |
| 5310 |
"\\&\n" |
| 5311 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 5312 |
"\\&\n" |
| 5313 |
"static void\n" |
| 5314 |
"closeSocketPair(int sockPair[2])\n" |
| 5315 |
"{\n" |
| 5316 |
" if (close(sockPair[0]) == -1)\n" |
| 5317 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 5318 |
" if (close(sockPair[1]) == -1)\n" |
| 5319 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 5320 |
"}\n" |
| 5321 |
"\\&\n" |
| 5322 |
"/* Implementation of the target process; create a child process that:\n" |
| 5323 |
"\\&\n" |
| 5324 |
" (1) installs a seccomp filter with the\n" |
| 5325 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 5326 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 5327 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 5328 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 5329 |
"\\&\n" |
| 5330 |
" The function return value in the parent is the PID of the child\n" |
| 5331 |
" process; the child does not return from this function. */\n" |
| 5332 |
"\\&\n" |
| 5333 |
"static pid_t\n" |
| 5334 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 5335 |
"{\n" |
| 5336 |
" int notifyFd, s;\n" |
| 5337 |
" pid_t targetPid;\n" |
| 5338 |
"\\&\n" |
| 5339 |
" targetPid = fork();\n" |
| 5340 |
"\\&\n" |
| 5341 |
" if (targetPid == -1)\n" |
| 5342 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 5343 |
"\\&\n" |
| 5344 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 5345 |
" return targetPid;\n" |
| 5346 |
"\\&\n" |
| 5347 |
" /* Child falls through to here */\n" |
| 5348 |
"\\&\n" |
| 5349 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 5350 |
"\\&\n" |
| 5351 |
" /* Install seccomp filter(s) */\n" |
| 5352 |
"\\&\n" |
| 5353 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 5354 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 5355 |
"\\&\n" |
| 5356 |
" notifyFd = installNotifyFilter();\n" |
| 5357 |
"\\&\n" |
| 5358 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 5359 |
" a UNIX domain socket */\n" |
| 5360 |
"\\&\n" |
| 5361 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 5362 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 5363 |
"\\&\n" |
| 5364 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 5365 |
"\\&\n" |
| 5366 |
" if (close(notifyFd) == -1)\n" |
| 5367 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 5368 |
"\\&\n" |
| 5369 |
" closeSocketPair(sockPair);\n" |
| 5370 |
"\\&\n" |
| 5371 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 5372 |
"\\&\n" |
| 5373 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 5374 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 5375 |
"\\&\n" |
| 5376 |
" s = mkdir(*ap, 0700);\n" |
| 5377 |
" if (s == -1)\n" |
| 5378 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 5379 |
" else\n" |
| 5380 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 5381 |
" }\n" |
| 5382 |
"\\&\n" |
| 5383 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 5384 |
" exit(EXIT_SUCCESS);\n" |
| 5385 |
"}\n" |
| 5386 |
"\\&\n" |
| 5387 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 5388 |
" operation is still valid. It will no longer be valid if the target\n" |
| 5389 |
" process has terminated or is no longer blocked in the system call that\n" |
| 5390 |
" generated the notification (because it was interrupted by a signal).\n" |
| 5391 |
"\\&\n" |
| 5392 |
" This operation can be used when doing such things as accessing\n" |
| 5393 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 5394 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 5395 |
" terminates and is reused by another process. */\n" |
| 5396 |
"\\&\n" |
| 5397 |
"static bool\n" |
| 5398 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 5399 |
"{\n" |
| 5400 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 5401 |
"}\n" |
| 5402 |
"\\&\n" |
| 5403 |
"/* Access the memory of the target process in order to fetch the\n" |
| 5404 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 5405 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 5406 |
" a buffer of \\[aq]len\\[aq] bytes allocated by the caller.\n" |
| 5407 |
"\\&\n" |
| 5408 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 5409 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 5410 |
"\\&\n" |
| 5411 |
"static bool\n" |
| 5412 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 5413 |
" int argNum, char *path, size_t len)\n" |
| 5414 |
"{\n" |
| 5415 |
" int procMemFd;\n" |
| 5416 |
" char procMemPath[PATH_MAX];\n" |
| 5417 |
" ssize_t nread;\n" |
| 5418 |
"\\&\n" |
| 5419 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 5420 |
"\\&\n" |
| 5421 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 5422 |
" if (procMemFd == -1)\n" |
| 5423 |
" return false;\n" |
| 5424 |
"\\&\n" |
| 5425 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 5426 |
" and blocked in the system call that caused the notification.\n" |
| 5427 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 5428 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 5429 |
" descriptor that we opened corresponded to the process for which we\n" |
| 5430 |
" received a notification. If that process subsequently terminates,\n" |
| 5431 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 5432 |
"\\&\n" |
| 5433 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 5434 |
" close(procMemFd);\n" |
| 5435 |
" return false;\n" |
| 5436 |
" }\n" |
| 5437 |
"\\&\n" |
| 5438 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 5439 |
"\\&\n" |
| 5440 |
" nread = pread(procMemFd, path, len, req-E<gt>data.args[argNum]);\n" |
| 5441 |
"\\&\n" |
| 5442 |
" close(procMemFd);\n" |
| 5443 |
"\\&\n" |
| 5444 |
" if (nread E<lt>= 0)\n" |
| 5445 |
" return false;\n" |
| 5446 |
"\\&\n" |
| 5447 |
" /* Once again check that the notification ID is still valid. The\n" |
| 5448 |
" case we are particularly concerned about here is that just\n" |
| 5449 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 5450 |
" call was interrupted by a signal handler, and after the handler\n" |
| 5451 |
" returned, the target carried on execution (past the interrupted\n" |
| 5452 |
" system call). In that case, we have no guarantees about what we\n" |
| 5453 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 5454 |
" changed by subsequent operations. */\n" |
| 5455 |
"\\&\n" |
| 5456 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 5457 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 5458 |
" return false;\n" |
| 5459 |
" }\n" |
| 5460 |
"\\&\n" |
| 5461 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 5462 |
" we have no guarantees about what was in the memory of the target\n" |
| 5463 |
" process. (The memory may have been modified by another thread, or\n" |
| 5464 |
" even by an external attacking process.) We therefore treat the\n" |
| 5465 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 5466 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 5467 |
" error for the target process. */\n" |
| 5468 |
"\\&\n" |
| 5469 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 5470 |
" return true;\n" |
| 5471 |
"\\&\n" |
| 5472 |
" return false;\n" |
| 5473 |
"}\n" |
| 5474 |
"\\&\n" |
| 5475 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 5476 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 5477 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 5478 |
"\\&\n" |
| 5479 |
"static void\n" |
| 5480 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 5481 |
" struct seccomp_notif_resp **resp,\n" |
| 5482 |
" struct seccomp_notif_sizes *sizes)\n" |
| 5483 |
"{\n" |
| 5484 |
" size_t resp_size;\n" |
| 5485 |
"\\&\n" |
| 5486 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 5487 |
" notifications and send notification responses, and allocate\n" |
| 5488 |
" buffers of those sizes. */\n" |
| 5489 |
"\\&\n" |
| 5490 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 5491 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 5492 |
"\\&\n" |
| 5493 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 5494 |
" if (*req == NULL)\n" |
| 5495 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 5496 |
"\\&\n" |
| 5497 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 5498 |
" that the user-space binary may have been built with user-space\n" |
| 5499 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 5500 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 5501 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 5502 |
" ensures that if the supervisor places bytes into the response\n" |
| 5503 |
" structure that are past the response size that the kernel expects,\n" |
| 5504 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 5505 |
"\\&\n" |
| 5506 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 5507 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 5508 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 5509 |
"\\&\n" |
| 5510 |
" *resp = malloc(resp_size);\n" |
| 5511 |
" if (*resp == NULL)\n" |
| 5512 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 5513 |
"\\&\n" |
| 5514 |
"}\n" |
| 5515 |
"\\&\n" |
| 5516 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 5517 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 5518 |
"\\&\n" |
| 5519 |
"static void\n" |
| 5520 |
"handleNotifications(int notifyFd)\n" |
| 5521 |
"{\n" |
| 5522 |
" bool pathOK;\n" |
| 5523 |
" char path[PATH_MAX];\n" |
| 5524 |
" struct seccomp_notif *req;\n" |
| 5525 |
" struct seccomp_notif_resp *resp;\n" |
| 5526 |
" struct seccomp_notif_sizes sizes;\n" |
| 5527 |
"\\&\n" |
| 5528 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 5529 |
"\\&\n" |
| 5530 |
" /* Loop handling notifications */\n" |
| 5531 |
"\\&\n" |
| 5532 |
" for (;;) {\n" |
| 5533 |
"\\&\n" |
| 5534 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 5535 |
"\\&\n" |
| 5536 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 5537 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 5538 |
" if (errno == EINTR)\n" |
| 5539 |
" continue;\n" |
| 5540 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 5541 |
" }\n" |
| 5542 |
"\\&\n" |
| 5543 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 5544 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 5545 |
"\\&\n" |
| 5546 |
" /* The only system call that can generate a notification event\n" |
| 5547 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 5548 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 5549 |
" code in case the seccomp filter is later modified to\n" |
| 5550 |
" generate notifications for other system calls. */\n" |
| 5551 |
"\\&\n" |
| 5552 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 5553 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 5554 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 5555 |
" exit(EXIT_FAILURE);\n" |
| 5556 |
" }\n" |
| 5557 |
"\\&\n" |
| 5558 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 5559 |
"\\&\n" |
| 5560 |
" /* Prepopulate some fields of the response */\n" |
| 5561 |
"\\&\n" |
| 5562 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 5563 |
" resp-E<gt>flags = 0;\n" |
| 5564 |
" resp-E<gt>val = 0;\n" |
| 5565 |
"\\&\n" |
| 5566 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 5567 |
" response (sending this response may yield an error if the\n" |
| 5568 |
" failure occurred because the notification ID was no longer\n" |
| 5569 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 5570 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 5571 |
" kernel to let the target process execute the mkdir();\n" |
| 5572 |
" otherwise, give an error for a directory pathname in any other\n" |
| 5573 |
" location. */\n" |
| 5574 |
"\\&\n" |
| 5575 |
" if (!pathOK) {\n" |
| 5576 |
" resp-E<gt>error = -EINVAL;\n" |
| 5577 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 5578 |
" strerror(-resp-E<gt>error));\n" |
| 5579 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 5580 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 5581 |
" path, req-E<gt>data.args[1]);\n" |
| 5582 |
"\\&\n" |
| 5583 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 5584 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 5585 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 5586 |
" mkdir() in target */\n" |
| 5587 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 5588 |
" resp-E<gt>val);\n" |
| 5589 |
" } else {\n" |
| 5590 |
"\\&\n" |
| 5591 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 5592 |
" back to the target */\n" |
| 5593 |
"\\&\n" |
| 5594 |
" resp-E<gt>error = -errno;\n" |
| 5595 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 5596 |
" strerror(errno));\n" |
| 5597 |
" }\n" |
| 5598 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 5599 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 5600 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 5601 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 5602 |
" } else {\n" |
| 5603 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 5604 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 5605 |
" strerror(-resp-E<gt>error));\n" |
| 5606 |
" }\n" |
| 5607 |
"\\&\n" |
| 5608 |
" /* Send a response to the notification */\n" |
| 5609 |
"\\&\n" |
| 5610 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 5611 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 5612 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 5613 |
"\\&\n" |
| 5614 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 5615 |
" if (errno == ENOENT)\n" |
| 5616 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 5617 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 5618 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 5619 |
" else\n" |
| 5620 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 5621 |
" }\n" |
| 5622 |
"\\&\n" |
| 5623 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 5624 |
" of the loop and terminates. This allows us to see what happens\n" |
| 5625 |
" if the target process makes further calls to mkdir(2). */\n" |
| 5626 |
"\\&\n" |
| 5627 |
" if (strcmp(path, \"/bye\") == 0)\n" |
| 5628 |
" break;\n" |
| 5629 |
" }\n" |
| 5630 |
"\\&\n" |
| 5631 |
" free(req);\n" |
| 5632 |
" free(resp);\n" |
| 5633 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 5634 |
" exit(EXIT_FAILURE);\n" |
| 5635 |
"}\n" |
| 5636 |
"\\&\n" |
| 5637 |
"/* Implementation of the supervisor process:\n" |
| 5638 |
"\\&\n" |
| 5639 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 5640 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 5641 |
"\\&\n" |
| 5642 |
"static void\n" |
| 5643 |
"supervisor(int sockPair[2])\n" |
| 5644 |
"{\n" |
| 5645 |
" int notifyFd;\n" |
| 5646 |
"\\&\n" |
| 5647 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 5648 |
"\\&\n" |
| 5649 |
" if (notifyFd == -1)\n" |
| 5650 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 5651 |
"\\&\n" |
| 5652 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 5653 |
"\\&\n" |
| 5654 |
" handleNotifications(notifyFd);\n" |
| 5655 |
"}\n" |
| 5656 |
"\\&\n" |
| 5657 |
"int\n" |
| 5658 |
"main(int argc, char *argv[])\n" |
| 5659 |
"{\n" |
| 5660 |
" int sockPair[2];\n" |
| 5661 |
" struct sigaction sa;\n" |
| 5662 |
"\\&\n" |
| 5663 |
" setbuf(stdout, NULL);\n" |
| 5664 |
"\\&\n" |
| 5665 |
" if (argc E<lt> 2) {\n" |
| 5666 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 5667 |
" exit(EXIT_FAILURE);\n" |
| 5668 |
" }\n" |
| 5669 |
"\\&\n" |
| 5670 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 5671 |
" notification file descriptor from the target process to the\n" |
| 5672 |
" supervisor process. */\n" |
| 5673 |
"\\&\n" |
| 5674 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 5675 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 5676 |
"\\&\n" |
| 5677 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 5678 |
" filtering. The target process writes the seccomp notification\n" |
| 5679 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 5680 |
" each directory in the command-line arguments. */\n" |
| 5681 |
"\\&\n" |
| 5682 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 5683 |
"\\&\n" |
| 5684 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 5685 |
" supervisor can also terminate. */\n" |
| 5686 |
"\\&\n" |
| 5687 |
" sa.sa_handler = sigchldHandler;\n" |
| 5688 |
" sa.sa_flags = 0;\n" |
| 5689 |
" sigemptyset(&sa.sa_mask);\n" |
| 5690 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 5691 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 5692 |
"\\&\n" |
| 5693 |
" supervisor(sockPair);\n" |
| 5694 |
"\\&\n" |
| 5695 |
" exit(EXIT_SUCCESS);\n" |
| 5696 |
"}\n" |
| 5697 |
|
| 5698 |
#. type: TH |
| 5699 |
#: fedora-44 fedora-rawhide |
| 5700 |
#, no-wrap |
| 5701 |
msgid "2024-11-17" |
| 5702 |
msgstr "17 نوفمبر 2024" |
| 5703 |
|
| 5704 |
#. type: TH |
| 5705 |
#: fedora-44 fedora-rawhide |
| 5706 |
#, no-wrap |
| 5707 |
msgid "Linux man-pages 6.13" |
| 5708 |
msgstr "صفحات دليل لينكس 6.13" |
| 5709 |
|
| 5710 |
#. type: Plain text |
| 5711 |
#: fedora-44 fedora-rawhide |
| 5712 |
#, no-wrap |
| 5713 |
msgid "" |
| 5714 |
"#define _GNU_SOURCE\n" |
| 5715 |
"#include E<lt>err.hE<gt>\n" |
| 5716 |
"#include E<lt>errno.hE<gt>\n" |
| 5717 |
"#include E<lt>fcntl.hE<gt>\n" |
| 5718 |
"#include E<lt>limits.hE<gt>\n" |
| 5719 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 5720 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 5721 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 5722 |
"#include E<lt>signal.hE<gt>\n" |
| 5723 |
"#include E<lt>stdbool.hE<gt>\n" |
| 5724 |
"#include E<lt>stddef.hE<gt>\n" |
| 5725 |
"#include E<lt>stdint.hE<gt>\n" |
| 5726 |
"#include E<lt>stdio.hE<gt>\n" |
| 5727 |
"#include E<lt>stdlib.hE<gt>\n" |
| 5728 |
"#include E<lt>string.hE<gt>\n" |
| 5729 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 5730 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 5731 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 5732 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 5733 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 5734 |
"#include E<lt>sys/types.hE<gt>\n" |
| 5735 |
"#include E<lt>sys/un.hE<gt>\n" |
| 5736 |
"#include E<lt>unistd.hE<gt>\n" |
| 5737 |
"\\&\n" |
| 5738 |
"#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" |
| 5739 |
"\\&\n" |
| 5740 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 5741 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 5742 |
"\\&\n" |
| 5743 |
"static int\n" |
| 5744 |
"sendfd(int sockfd, int fd)\n" |
| 5745 |
"{\n" |
| 5746 |
" int data;\n" |
| 5747 |
" struct iovec iov;\n" |
| 5748 |
" struct msghdr msgh;\n" |
| 5749 |
" struct cmsghdr *cmsgp;\n" |
| 5750 |
"\\&\n" |
| 5751 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 5752 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 5753 |
" union to ensure that it is suitably aligned. */\n" |
| 5754 |
" union {\n" |
| 5755 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 5756 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 5757 |
" struct cmsghdr align;\n" |
| 5758 |
" } controlMsg;\n" |
| 5759 |
"\\&\n" |
| 5760 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 5761 |
" destination socket when sending a datagram. However, we do not\n" |
| 5762 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 5763 |
"\\&\n" |
| 5764 |
" msgh.msg_name = NULL;\n" |
| 5765 |
" msgh.msg_namelen = 0;\n" |
| 5766 |
"\\&\n" |
| 5767 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 5768 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 5769 |
" whose value is ignored by recvfd(). */\n" |
| 5770 |
"\\&\n" |
| 5771 |
" msgh.msg_iov = &iov;\n" |
| 5772 |
" msgh.msg_iovlen = 1;\n" |
| 5773 |
" iov.iov_base = &data;\n" |
| 5774 |
" iov.iov_len = sizeof(int);\n" |
| 5775 |
" data = 12345;\n" |
| 5776 |
"\\&\n" |
| 5777 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 5778 |
"\\&\n" |
| 5779 |
" msgh.msg_control = controlMsg.buf;\n" |
| 5780 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 5781 |
"\\&\n" |
| 5782 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 5783 |
"\\&\n" |
| 5784 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 5785 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 5786 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 5787 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 5788 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 5789 |
"\\&\n" |
| 5790 |
" /* Send real plus ancillary data */\n" |
| 5791 |
"\\&\n" |
| 5792 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 5793 |
" return -1;\n" |
| 5794 |
"\\&\n" |
| 5795 |
" return 0;\n" |
| 5796 |
"}\n" |
| 5797 |
"\\&\n" |
| 5798 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 5799 |
" the received file descriptor on success, or -1 on error. */\n" |
| 5800 |
"\\&\n" |
| 5801 |
"static int\n" |
| 5802 |
"recvfd(int sockfd)\n" |
| 5803 |
"{\n" |
| 5804 |
" int data, fd;\n" |
| 5805 |
" ssize_t nr;\n" |
| 5806 |
" struct iovec iov;\n" |
| 5807 |
" struct msghdr msgh;\n" |
| 5808 |
"\\&\n" |
| 5809 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 5810 |
" in sendfd() */\n" |
| 5811 |
" union {\n" |
| 5812 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 5813 |
" struct cmsghdr align;\n" |
| 5814 |
" } controlMsg;\n" |
| 5815 |
" struct cmsghdr *cmsgp;\n" |
| 5816 |
"\\&\n" |
| 5817 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 5818 |
" sending socket. However, we do not need this information. */\n" |
| 5819 |
"\\&\n" |
| 5820 |
" msgh.msg_name = NULL;\n" |
| 5821 |
" msgh.msg_namelen = 0;\n" |
| 5822 |
"\\&\n" |
| 5823 |
" /* Specify buffer for receiving real data */\n" |
| 5824 |
"\\&\n" |
| 5825 |
" msgh.msg_iov = &iov;\n" |
| 5826 |
" msgh.msg_iovlen = 1;\n" |
| 5827 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 5828 |
" iov.iov_len = sizeof(int);\n" |
| 5829 |
"\\&\n" |
| 5830 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 5831 |
"\\&\n" |
| 5832 |
" msgh.msg_control = controlMsg.buf;\n" |
| 5833 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 5834 |
"\\&\n" |
| 5835 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 5836 |
"\\&\n" |
| 5837 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 5838 |
" if (nr == -1)\n" |
| 5839 |
" return -1;\n" |
| 5840 |
"\\&\n" |
| 5841 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 5842 |
"\\&\n" |
| 5843 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 5844 |
"\\&\n" |
| 5845 |
" if (cmsgp == NULL\n" |
| 5846 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 5847 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 5848 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 5849 |
" {\n" |
| 5850 |
" errno = EINVAL;\n" |
| 5851 |
" return -1;\n" |
| 5852 |
" }\n" |
| 5853 |
"\\&\n" |
| 5854 |
" /* Return the received file descriptor to our caller */\n" |
| 5855 |
"\\&\n" |
| 5856 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 5857 |
" return fd;\n" |
| 5858 |
"}\n" |
| 5859 |
"\\&\n" |
| 5860 |
"static void\n" |
| 5861 |
"sigchldHandler(int sig)\n" |
| 5862 |
"{\n" |
| 5863 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 5864 |
"\\&\n" |
| 5865 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 5866 |
" _exit(EXIT_SUCCESS);\n" |
| 5867 |
"}\n" |
| 5868 |
"\\&\n" |
| 5869 |
"static int\n" |
| 5870 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 5871 |
"{\n" |
| 5872 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 5873 |
"}\n" |
| 5874 |
"\\&\n" |
| 5875 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 5876 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 5877 |
" completion of these instructions, the accumulator contains the system\n" |
| 5878 |
" call number. */\n" |
| 5879 |
"\\&\n" |
| 5880 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 5881 |
"\\&\n" |
| 5882 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 5883 |
"\\&\n" |
| 5884 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 5885 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 5886 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 5887 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 5888 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 5889 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 5890 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 5891 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 5892 |
"\\&\n" |
| 5893 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 5894 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 5895 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 5896 |
"\\&\n" |
| 5897 |
" The function return value is a file descriptor from which the\n" |
| 5898 |
" user-space notifications can be fetched. */\n" |
| 5899 |
"\\&\n" |
| 5900 |
"static int\n" |
| 5901 |
"installNotifyFilter(void)\n" |
| 5902 |
"{\n" |
| 5903 |
" int notifyFd;\n" |
| 5904 |
"\\&\n" |
| 5905 |
" struct sock_filter filter[] = {\n" |
| 5906 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 5907 |
"\\&\n" |
| 5908 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 5909 |
"\\&\n" |
| 5910 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 5911 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 5912 |
"\\&\n" |
| 5913 |
" /* Every other system call is allowed */\n" |
| 5914 |
"\\&\n" |
| 5915 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 5916 |
" };\n" |
| 5917 |
"\\&\n" |
| 5918 |
" struct sock_fprog prog = {\n" |
| 5919 |
" .len = ARRAY_SIZE(filter),\n" |
| 5920 |
" .filter = filter,\n" |
| 5921 |
" };\n" |
| 5922 |
"\\&\n" |
| 5923 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 5924 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 5925 |
"\\&\n" |
| 5926 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 5927 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 5928 |
" if (notifyFd == -1)\n" |
| 5929 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 5930 |
"\\&\n" |
| 5931 |
" return notifyFd;\n" |
| 5932 |
"}\n" |
| 5933 |
"\\&\n" |
| 5934 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 5935 |
"\\&\n" |
| 5936 |
"static void\n" |
| 5937 |
"closeSocketPair(int sockPair[2])\n" |
| 5938 |
"{\n" |
| 5939 |
" if (close(sockPair[0]) == -1)\n" |
| 5940 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 5941 |
" if (close(sockPair[1]) == -1)\n" |
| 5942 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 5943 |
"}\n" |
| 5944 |
"\\&\n" |
| 5945 |
"/* Implementation of the target process; create a child process that:\n" |
| 5946 |
"\\&\n" |
| 5947 |
" (1) installs a seccomp filter with the\n" |
| 5948 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 5949 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 5950 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 5951 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 5952 |
"\\&\n" |
| 5953 |
" The function return value in the parent is the PID of the child\n" |
| 5954 |
" process; the child does not return from this function. */\n" |
| 5955 |
"\\&\n" |
| 5956 |
"static pid_t\n" |
| 5957 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 5958 |
"{\n" |
| 5959 |
" int notifyFd, s;\n" |
| 5960 |
" pid_t targetPid;\n" |
| 5961 |
"\\&\n" |
| 5962 |
" targetPid = fork();\n" |
| 5963 |
"\\&\n" |
| 5964 |
" if (targetPid == -1)\n" |
| 5965 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 5966 |
"\\&\n" |
| 5967 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 5968 |
" return targetPid;\n" |
| 5969 |
"\\&\n" |
| 5970 |
" /* Child falls through to here */\n" |
| 5971 |
"\\&\n" |
| 5972 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 5973 |
"\\&\n" |
| 5974 |
" /* Install seccomp filter(s) */\n" |
| 5975 |
"\\&\n" |
| 5976 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 5977 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 5978 |
"\\&\n" |
| 5979 |
" notifyFd = installNotifyFilter();\n" |
| 5980 |
"\\&\n" |
| 5981 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 5982 |
" a UNIX domain socket */\n" |
| 5983 |
"\\&\n" |
| 5984 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 5985 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 5986 |
"\\&\n" |
| 5987 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 5988 |
"\\&\n" |
| 5989 |
" if (close(notifyFd) == -1)\n" |
| 5990 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 5991 |
"\\&\n" |
| 5992 |
" closeSocketPair(sockPair);\n" |
| 5993 |
"\\&\n" |
| 5994 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 5995 |
"\\&\n" |
| 5996 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 5997 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 5998 |
"\\&\n" |
| 5999 |
" s = mkdir(*ap, 0700);\n" |
| 6000 |
" if (s == -1)\n" |
| 6001 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 6002 |
" else\n" |
| 6003 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 6004 |
" }\n" |
| 6005 |
"\\&\n" |
| 6006 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 6007 |
" exit(EXIT_SUCCESS);\n" |
| 6008 |
"}\n" |
| 6009 |
"\\&\n" |
| 6010 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 6011 |
" operation is still valid. It will no longer be valid if the target\n" |
| 6012 |
" process has terminated or is no longer blocked in the system call that\n" |
| 6013 |
" generated the notification (because it was interrupted by a signal).\n" |
| 6014 |
"\\&\n" |
| 6015 |
" This operation can be used when doing such things as accessing\n" |
| 6016 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 6017 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 6018 |
" terminates and is reused by another process. */\n" |
| 6019 |
"\\&\n" |
| 6020 |
"static bool\n" |
| 6021 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 6022 |
"{\n" |
| 6023 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 6024 |
"}\n" |
| 6025 |
"\\&\n" |
| 6026 |
"/* Access the memory of the target process in order to fetch the\n" |
| 6027 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 6028 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 6029 |
" a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" |
| 6030 |
"\\&\n" |
| 6031 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 6032 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 6033 |
"\\&\n" |
| 6034 |
"static bool\n" |
| 6035 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 6036 |
" int argNum, char *path, size_t size)\n" |
| 6037 |
"{\n" |
| 6038 |
" int procMemFd;\n" |
| 6039 |
" char procMemPath[PATH_MAX];\n" |
| 6040 |
" ssize_t nread;\n" |
| 6041 |
"\\&\n" |
| 6042 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 6043 |
"\\&\n" |
| 6044 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 6045 |
" if (procMemFd == -1)\n" |
| 6046 |
" return false;\n" |
| 6047 |
"\\&\n" |
| 6048 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 6049 |
" and blocked in the system call that caused the notification.\n" |
| 6050 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 6051 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 6052 |
" descriptor that we opened corresponded to the process for which we\n" |
| 6053 |
" received a notification. If that process subsequently terminates,\n" |
| 6054 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 6055 |
"\\&\n" |
| 6056 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 6057 |
" close(procMemFd);\n" |
| 6058 |
" return false;\n" |
| 6059 |
" }\n" |
| 6060 |
"\\&\n" |
| 6061 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 6062 |
"\\&\n" |
| 6063 |
" nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n" |
| 6064 |
"\\&\n" |
| 6065 |
" close(procMemFd);\n" |
| 6066 |
"\\&\n" |
| 6067 |
" if (nread E<lt>= 0)\n" |
| 6068 |
" return false;\n" |
| 6069 |
"\\&\n" |
| 6070 |
" /* Once again check that the notification ID is still valid. The\n" |
| 6071 |
" case we are particularly concerned about here is that just\n" |
| 6072 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 6073 |
" call was interrupted by a signal handler, and after the handler\n" |
| 6074 |
" returned, the target carried on execution (past the interrupted\n" |
| 6075 |
" system call). In that case, we have no guarantees about what we\n" |
| 6076 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 6077 |
" changed by subsequent operations. */\n" |
| 6078 |
"\\&\n" |
| 6079 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 6080 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 6081 |
" return false;\n" |
| 6082 |
" }\n" |
| 6083 |
"\\&\n" |
| 6084 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 6085 |
" we have no guarantees about what was in the memory of the target\n" |
| 6086 |
" process. (The memory may have been modified by another thread, or\n" |
| 6087 |
" even by an external attacking process.) We therefore treat the\n" |
| 6088 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 6089 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 6090 |
" error for the target process. */\n" |
| 6091 |
"\\&\n" |
| 6092 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 6093 |
" return true;\n" |
| 6094 |
"\\&\n" |
| 6095 |
" return false;\n" |
| 6096 |
"}\n" |
| 6097 |
"\\&\n" |
| 6098 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 6099 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 6100 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 6101 |
"\\&\n" |
| 6102 |
"static void\n" |
| 6103 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 6104 |
" struct seccomp_notif_resp **resp,\n" |
| 6105 |
" struct seccomp_notif_sizes *sizes)\n" |
| 6106 |
"{\n" |
| 6107 |
" size_t resp_size;\n" |
| 6108 |
"\\&\n" |
| 6109 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 6110 |
" notifications and send notification responses, and allocate\n" |
| 6111 |
" buffers of those sizes. */\n" |
| 6112 |
"\\&\n" |
| 6113 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 6114 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 6115 |
"\\&\n" |
| 6116 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 6117 |
" if (*req == NULL)\n" |
| 6118 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 6119 |
"\\&\n" |
| 6120 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 6121 |
" that the user-space binary may have been built with user-space\n" |
| 6122 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 6123 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 6124 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 6125 |
" ensures that if the supervisor places bytes into the response\n" |
| 6126 |
" structure that are past the response size that the kernel expects,\n" |
| 6127 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 6128 |
"\\&\n" |
| 6129 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 6130 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 6131 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 6132 |
"\\&\n" |
| 6133 |
" *resp = malloc(resp_size);\n" |
| 6134 |
" if (*resp == NULL)\n" |
| 6135 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 6136 |
"\\&\n" |
| 6137 |
"}\n" |
| 6138 |
"\\&\n" |
| 6139 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 6140 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 6141 |
"\\&\n" |
| 6142 |
"static void\n" |
| 6143 |
"handleNotifications(int notifyFd)\n" |
| 6144 |
"{\n" |
| 6145 |
" bool pathOK;\n" |
| 6146 |
" char path[PATH_MAX];\n" |
| 6147 |
" struct seccomp_notif *req;\n" |
| 6148 |
" struct seccomp_notif_resp *resp;\n" |
| 6149 |
" struct seccomp_notif_sizes sizes;\n" |
| 6150 |
"\\&\n" |
| 6151 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 6152 |
"\\&\n" |
| 6153 |
" /* Loop handling notifications */\n" |
| 6154 |
"\\&\n" |
| 6155 |
" for (;;) {\n" |
| 6156 |
"\\&\n" |
| 6157 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 6158 |
"\\&\n" |
| 6159 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 6160 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 6161 |
" if (errno == EINTR)\n" |
| 6162 |
" continue;\n" |
| 6163 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 6164 |
" }\n" |
| 6165 |
"\\&\n" |
| 6166 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 6167 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 6168 |
"\\&\n" |
| 6169 |
" /* The only system call that can generate a notification event\n" |
| 6170 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 6171 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 6172 |
" code in case the seccomp filter is later modified to\n" |
| 6173 |
" generate notifications for other system calls. */\n" |
| 6174 |
"\\&\n" |
| 6175 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 6176 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 6177 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 6178 |
" exit(EXIT_FAILURE);\n" |
| 6179 |
" }\n" |
| 6180 |
"\\&\n" |
| 6181 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 6182 |
"\\&\n" |
| 6183 |
" /* Prepopulate some fields of the response */\n" |
| 6184 |
"\\&\n" |
| 6185 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 6186 |
" resp-E<gt>flags = 0;\n" |
| 6187 |
" resp-E<gt>val = 0;\n" |
| 6188 |
"\\&\n" |
| 6189 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 6190 |
" response (sending this response may yield an error if the\n" |
| 6191 |
" failure occurred because the notification ID was no longer\n" |
| 6192 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 6193 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 6194 |
" kernel to let the target process execute the mkdir();\n" |
| 6195 |
" otherwise, give an error for a directory pathname in any other\n" |
| 6196 |
" location. */\n" |
| 6197 |
"\\&\n" |
| 6198 |
" if (!pathOK) {\n" |
| 6199 |
" resp-E<gt>error = -EINVAL;\n" |
| 6200 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 6201 |
" strerror(-resp-E<gt>error));\n" |
| 6202 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 6203 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 6204 |
" path, req-E<gt>data.args[1]);\n" |
| 6205 |
"\\&\n" |
| 6206 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 6207 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 6208 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 6209 |
" mkdir() in target */\n" |
| 6210 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 6211 |
" resp-E<gt>val);\n" |
| 6212 |
" } else {\n" |
| 6213 |
"\\&\n" |
| 6214 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 6215 |
" back to the target */\n" |
| 6216 |
"\\&\n" |
| 6217 |
" resp-E<gt>error = -errno;\n" |
| 6218 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 6219 |
" strerror(errno));\n" |
| 6220 |
" }\n" |
| 6221 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 6222 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 6223 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 6224 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 6225 |
" } else {\n" |
| 6226 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 6227 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 6228 |
" strerror(-resp-E<gt>error));\n" |
| 6229 |
" }\n" |
| 6230 |
"\\&\n" |
| 6231 |
" /* Send a response to the notification */\n" |
| 6232 |
"\\&\n" |
| 6233 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 6234 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 6235 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 6236 |
"\\&\n" |
| 6237 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 6238 |
" if (errno == ENOENT)\n" |
| 6239 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 6240 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 6241 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 6242 |
" else\n" |
| 6243 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 6244 |
" }\n" |
| 6245 |
"\\&\n" |
| 6246 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 6247 |
" of the loop and terminates. This allows us to see what happens\n" |
| 6248 |
" if the target process makes further calls to mkdir(2). */\n" |
| 6249 |
"\\&\n" |
| 6250 |
" if (strcmp(path, \"/bye\") == 0)\n" |
| 6251 |
" break;\n" |
| 6252 |
" }\n" |
| 6253 |
"\\&\n" |
| 6254 |
" free(req);\n" |
| 6255 |
" free(resp);\n" |
| 6256 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 6257 |
" exit(EXIT_FAILURE);\n" |
| 6258 |
"}\n" |
| 6259 |
"\\&\n" |
| 6260 |
"/* Implementation of the supervisor process:\n" |
| 6261 |
"\\&\n" |
| 6262 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 6263 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 6264 |
"\\&\n" |
| 6265 |
"static void\n" |
| 6266 |
"supervisor(int sockPair[2])\n" |
| 6267 |
"{\n" |
| 6268 |
" int notifyFd;\n" |
| 6269 |
"\\&\n" |
| 6270 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 6271 |
"\\&\n" |
| 6272 |
" if (notifyFd == -1)\n" |
| 6273 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 6274 |
"\\&\n" |
| 6275 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 6276 |
"\\&\n" |
| 6277 |
" handleNotifications(notifyFd);\n" |
| 6278 |
"}\n" |
| 6279 |
"\\&\n" |
| 6280 |
"int\n" |
| 6281 |
"main(int argc, char *argv[])\n" |
| 6282 |
"{\n" |
| 6283 |
" int sockPair[2];\n" |
| 6284 |
" struct sigaction sa;\n" |
| 6285 |
"\\&\n" |
| 6286 |
" setbuf(stdout, NULL);\n" |
| 6287 |
"\\&\n" |
| 6288 |
" if (argc E<lt> 2) {\n" |
| 6289 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 6290 |
" exit(EXIT_FAILURE);\n" |
| 6291 |
" }\n" |
| 6292 |
"\\&\n" |
| 6293 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 6294 |
" notification file descriptor from the target process to the\n" |
| 6295 |
" supervisor process. */\n" |
| 6296 |
"\\&\n" |
| 6297 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 6298 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 6299 |
"\\&\n" |
| 6300 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 6301 |
" filtering. The target process writes the seccomp notification\n" |
| 6302 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 6303 |
" each directory in the command-line arguments. */\n" |
| 6304 |
"\\&\n" |
| 6305 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 6306 |
"\\&\n" |
| 6307 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 6308 |
" supervisor can also terminate. */\n" |
| 6309 |
"\\&\n" |
| 6310 |
" sa.sa_handler = sigchldHandler;\n" |
| 6311 |
" sa.sa_flags = 0;\n" |
| 6312 |
" sigemptyset(&sa.sa_mask);\n" |
| 6313 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 6314 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 6315 |
"\\&\n" |
| 6316 |
" supervisor(sockPair);\n" |
| 6317 |
"\\&\n" |
| 6318 |
" exit(EXIT_SUCCESS);\n" |
| 6319 |
"}\n" |
| 6320 |
msgstr "" |
| 6321 |
"#define _GNU_SOURCE\n" |
| 6322 |
"#include E<lt>err.hE<gt>\n" |
| 6323 |
"#include E<lt>errno.hE<gt>\n" |
| 6324 |
"#include E<lt>fcntl.hE<gt>\n" |
| 6325 |
"#include E<lt>limits.hE<gt>\n" |
| 6326 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 6327 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 6328 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 6329 |
"#include E<lt>signal.hE<gt>\n" |
| 6330 |
"#include E<lt>stdbool.hE<gt>\n" |
| 6331 |
"#include E<lt>stddef.hE<gt>\n" |
| 6332 |
"#include E<lt>stdint.hE<gt>\n" |
| 6333 |
"#include E<lt>stdio.hE<gt>\n" |
| 6334 |
"#include E<lt>stdlib.hE<gt>\n" |
| 6335 |
"#include E<lt>string.hE<gt>\n" |
| 6336 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 6337 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 6338 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 6339 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 6340 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 6341 |
"#include E<lt>sys/types.hE<gt>\n" |
| 6342 |
"#include E<lt>sys/un.hE<gt>\n" |
| 6343 |
"#include E<lt>unistd.hE<gt>\n" |
| 6344 |
"\\&\n" |
| 6345 |
"#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" |
| 6346 |
"\\&\n" |
| 6347 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 6348 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 6349 |
"\\&\n" |
| 6350 |
"static int\n" |
| 6351 |
"sendfd(int sockfd, int fd)\n" |
| 6352 |
"{\n" |
| 6353 |
" int data;\n" |
| 6354 |
" struct iovec iov;\n" |
| 6355 |
" struct msghdr msgh;\n" |
| 6356 |
" struct cmsghdr *cmsgp;\n" |
| 6357 |
"\\&\n" |
| 6358 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 6359 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 6360 |
" union to ensure that it is suitably aligned. */\n" |
| 6361 |
" union {\n" |
| 6362 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 6363 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 6364 |
" struct cmsghdr align;\n" |
| 6365 |
" } controlMsg;\n" |
| 6366 |
"\\&\n" |
| 6367 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 6368 |
" destination socket when sending a datagram. However, we do not\n" |
| 6369 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 6370 |
"\\&\n" |
| 6371 |
" msgh.msg_name = NULL;\n" |
| 6372 |
" msgh.msg_namelen = 0;\n" |
| 6373 |
"\\&\n" |
| 6374 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 6375 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 6376 |
" whose value is ignored by recvfd(). */\n" |
| 6377 |
"\\&\n" |
| 6378 |
" msgh.msg_iov = &iov;\n" |
| 6379 |
" msgh.msg_iovlen = 1;\n" |
| 6380 |
" iov.iov_base = &data;\n" |
| 6381 |
" iov.iov_len = sizeof(int);\n" |
| 6382 |
" data = 12345;\n" |
| 6383 |
"\\&\n" |
| 6384 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 6385 |
"\\&\n" |
| 6386 |
" msgh.msg_control = controlMsg.buf;\n" |
| 6387 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 6388 |
"\\&\n" |
| 6389 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 6390 |
"\\&\n" |
| 6391 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 6392 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 6393 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 6394 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 6395 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 6396 |
"\\&\n" |
| 6397 |
" /* Send real plus ancillary data */\n" |
| 6398 |
"\\&\n" |
| 6399 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 6400 |
" return -1;\n" |
| 6401 |
"\\&\n" |
| 6402 |
" return 0;\n" |
| 6403 |
"}\n" |
| 6404 |
"\\&\n" |
| 6405 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 6406 |
" the received file descriptor on success, or -1 on error. */\n" |
| 6407 |
"\\&\n" |
| 6408 |
"static int\n" |
| 6409 |
"recvfd(int sockfd)\n" |
| 6410 |
"{\n" |
| 6411 |
" int data, fd;\n" |
| 6412 |
" ssize_t nr;\n" |
| 6413 |
" struct iovec iov;\n" |
| 6414 |
" struct msghdr msgh;\n" |
| 6415 |
"\\&\n" |
| 6416 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 6417 |
" in sendfd() */\n" |
| 6418 |
" union {\n" |
| 6419 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 6420 |
" struct cmsghdr align;\n" |
| 6421 |
" } controlMsg;\n" |
| 6422 |
" struct cmsghdr *cmsgp;\n" |
| 6423 |
"\\&\n" |
| 6424 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 6425 |
" sending socket. However, we do not need this information. */\n" |
| 6426 |
"\\&\n" |
| 6427 |
" msgh.msg_name = NULL;\n" |
| 6428 |
" msgh.msg_namelen = 0;\n" |
| 6429 |
"\\&\n" |
| 6430 |
" /* Specify buffer for receiving real data */\n" |
| 6431 |
"\\&\n" |
| 6432 |
" msgh.msg_iov = &iov;\n" |
| 6433 |
" msgh.msg_iovlen = 1;\n" |
| 6434 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 6435 |
" iov.iov_len = sizeof(int);\n" |
| 6436 |
"\\&\n" |
| 6437 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 6438 |
"\\&\n" |
| 6439 |
" msgh.msg_control = controlMsg.buf;\n" |
| 6440 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 6441 |
"\\&\n" |
| 6442 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 6443 |
"\\&\n" |
| 6444 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 6445 |
" if (nr == -1)\n" |
| 6446 |
" return -1;\n" |
| 6447 |
"\\&\n" |
| 6448 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 6449 |
"\\&\n" |
| 6450 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 6451 |
"\\&\n" |
| 6452 |
" if (cmsgp == NULL\n" |
| 6453 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 6454 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 6455 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 6456 |
" {\n" |
| 6457 |
" errno = EINVAL;\n" |
| 6458 |
" return -1;\n" |
| 6459 |
" }\n" |
| 6460 |
"\\&\n" |
| 6461 |
" /* Return the received file descriptor to our caller */\n" |
| 6462 |
"\\&\n" |
| 6463 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 6464 |
" return fd;\n" |
| 6465 |
"}\n" |
| 6466 |
"\\&\n" |
| 6467 |
"static void\n" |
| 6468 |
"sigchldHandler(int sig)\n" |
| 6469 |
"{\n" |
| 6470 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 6471 |
"\\&\n" |
| 6472 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 6473 |
" _exit(EXIT_SUCCESS);\n" |
| 6474 |
"}\n" |
| 6475 |
"\\&\n" |
| 6476 |
"static int\n" |
| 6477 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 6478 |
"{\n" |
| 6479 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 6480 |
"}\n" |
| 6481 |
"\\&\n" |
| 6482 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 6483 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 6484 |
" completion of these instructions, the accumulator contains the system\n" |
| 6485 |
" call number. */\n" |
| 6486 |
"\\&\n" |
| 6487 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 6488 |
"\\&\n" |
| 6489 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 6490 |
"\\&\n" |
| 6491 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 6492 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 6493 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 6494 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 6495 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 6496 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 6497 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 6498 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 6499 |
"\\&\n" |
| 6500 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 6501 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 6502 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 6503 |
"\\&\n" |
| 6504 |
" The function return value is a file descriptor from which the\n" |
| 6505 |
" user-space notifications can be fetched. */\n" |
| 6506 |
"\\&\n" |
| 6507 |
"static int\n" |
| 6508 |
"installNotifyFilter(void)\n" |
| 6509 |
"{\n" |
| 6510 |
" int notifyFd;\n" |
| 6511 |
"\\&\n" |
| 6512 |
" struct sock_filter filter[] = {\n" |
| 6513 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 6514 |
"\\&\n" |
| 6515 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 6516 |
"\\&\n" |
| 6517 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 6518 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 6519 |
"\\&\n" |
| 6520 |
" /* Every other system call is allowed */\n" |
| 6521 |
"\\&\n" |
| 6522 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 6523 |
" };\n" |
| 6524 |
"\\&\n" |
| 6525 |
" struct sock_fprog prog = {\n" |
| 6526 |
" .len = ARRAY_SIZE(filter),\n" |
| 6527 |
" .filter = filter,\n" |
| 6528 |
" };\n" |
| 6529 |
"\\&\n" |
| 6530 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 6531 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 6532 |
"\\&\n" |
| 6533 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 6534 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 6535 |
" if (notifyFd == -1)\n" |
| 6536 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 6537 |
"\\&\n" |
| 6538 |
" return notifyFd;\n" |
| 6539 |
"}\n" |
| 6540 |
"\\&\n" |
| 6541 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 6542 |
"\\&\n" |
| 6543 |
"static void\n" |
| 6544 |
"closeSocketPair(int sockPair[2])\n" |
| 6545 |
"{\n" |
| 6546 |
" if (close(sockPair[0]) == -1)\n" |
| 6547 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 6548 |
" if (close(sockPair[1]) == -1)\n" |
| 6549 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 6550 |
"}\n" |
| 6551 |
"\\&\n" |
| 6552 |
"/* Implementation of the target process; create a child process that:\n" |
| 6553 |
"\\&\n" |
| 6554 |
" (1) installs a seccomp filter with the\n" |
| 6555 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 6556 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 6557 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 6558 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 6559 |
"\\&\n" |
| 6560 |
" The function return value in the parent is the PID of the child\n" |
| 6561 |
" process; the child does not return from this function. */\n" |
| 6562 |
"\\&\n" |
| 6563 |
"static pid_t\n" |
| 6564 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 6565 |
"{\n" |
| 6566 |
" int notifyFd, s;\n" |
| 6567 |
" pid_t targetPid;\n" |
| 6568 |
"\\&\n" |
| 6569 |
" targetPid = fork();\n" |
| 6570 |
"\\&\n" |
| 6571 |
" if (targetPid == -1)\n" |
| 6572 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 6573 |
"\\&\n" |
| 6574 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 6575 |
" return targetPid;\n" |
| 6576 |
"\\&\n" |
| 6577 |
" /* Child falls through to here */\n" |
| 6578 |
"\\&\n" |
| 6579 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 6580 |
"\\&\n" |
| 6581 |
" /* Install seccomp filter(s) */\n" |
| 6582 |
"\\&\n" |
| 6583 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 6584 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 6585 |
"\\&\n" |
| 6586 |
" notifyFd = installNotifyFilter();\n" |
| 6587 |
"\\&\n" |
| 6588 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 6589 |
" a UNIX domain socket */\n" |
| 6590 |
"\\&\n" |
| 6591 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 6592 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 6593 |
"\\&\n" |
| 6594 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 6595 |
"\\&\n" |
| 6596 |
" if (close(notifyFd) == -1)\n" |
| 6597 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 6598 |
"\\&\n" |
| 6599 |
" closeSocketPair(sockPair);\n" |
| 6600 |
"\\&\n" |
| 6601 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 6602 |
"\\&\n" |
| 6603 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 6604 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 6605 |
"\\&\n" |
| 6606 |
" s = mkdir(*ap, 0700);\n" |
| 6607 |
" if (s == -1)\n" |
| 6608 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 6609 |
" else\n" |
| 6610 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 6611 |
" }\n" |
| 6612 |
"\\&\n" |
| 6613 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 6614 |
" exit(EXIT_SUCCESS);\n" |
| 6615 |
"}\n" |
| 6616 |
"\\&\n" |
| 6617 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 6618 |
" operation is still valid. It will no longer be valid if the target\n" |
| 6619 |
" process has terminated or is no longer blocked in the system call that\n" |
| 6620 |
" generated the notification (because it was interrupted by a signal).\n" |
| 6621 |
"\\&\n" |
| 6622 |
" This operation can be used when doing such things as accessing\n" |
| 6623 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 6624 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 6625 |
" terminates and is reused by another process. */\n" |
| 6626 |
"\\&\n" |
| 6627 |
"static bool\n" |
| 6628 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 6629 |
"{\n" |
| 6630 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 6631 |
"}\n" |
| 6632 |
"\\&\n" |
| 6633 |
"/* Access the memory of the target process in order to fetch the\n" |
| 6634 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 6635 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 6636 |
" a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" |
| 6637 |
"\\&\n" |
| 6638 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 6639 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 6640 |
"\\&\n" |
| 6641 |
"static bool\n" |
| 6642 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 6643 |
" int argNum, char *path, size_t size)\n" |
| 6644 |
"{\n" |
| 6645 |
" int procMemFd;\n" |
| 6646 |
" char procMemPath[PATH_MAX];\n" |
| 6647 |
" ssize_t nread;\n" |
| 6648 |
"\\&\n" |
| 6649 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 6650 |
"\\&\n" |
| 6651 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 6652 |
" if (procMemFd == -1)\n" |
| 6653 |
" return false;\n" |
| 6654 |
"\\&\n" |
| 6655 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 6656 |
" and blocked in the system call that caused the notification.\n" |
| 6657 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 6658 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 6659 |
" descriptor that we opened corresponded to the process for which we\n" |
| 6660 |
" received a notification. If that process subsequently terminates,\n" |
| 6661 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 6662 |
"\\&\n" |
| 6663 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 6664 |
" close(procMemFd);\n" |
| 6665 |
" return false;\n" |
| 6666 |
" }\n" |
| 6667 |
"\\&\n" |
| 6668 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 6669 |
"\\&\n" |
| 6670 |
" nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n" |
| 6671 |
"\\&\n" |
| 6672 |
" close(procMemFd);\n" |
| 6673 |
"\\&\n" |
| 6674 |
" if (nread E<lt>= 0)\n" |
| 6675 |
" return false;\n" |
| 6676 |
"\\&\n" |
| 6677 |
" /* Once again check that the notification ID is still valid. The\n" |
| 6678 |
" case we are particularly concerned about here is that just\n" |
| 6679 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 6680 |
" call was interrupted by a signal handler, and after the handler\n" |
| 6681 |
" returned, the target carried on execution (past the interrupted\n" |
| 6682 |
" system call). In that case, we have no guarantees about what we\n" |
| 6683 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 6684 |
" changed by subsequent operations. */\n" |
| 6685 |
"\\&\n" |
| 6686 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 6687 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 6688 |
" return false;\n" |
| 6689 |
" }\n" |
| 6690 |
"\\&\n" |
| 6691 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 6692 |
" we have no guarantees about what was in the memory of the target\n" |
| 6693 |
" process. (The memory may have been modified by another thread, or\n" |
| 6694 |
" even by an external attacking process.) We therefore treat the\n" |
| 6695 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 6696 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 6697 |
" error for the target process. */\n" |
| 6698 |
"\\&\n" |
| 6699 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 6700 |
" return true;\n" |
| 6701 |
"\\&\n" |
| 6702 |
" return false;\n" |
| 6703 |
"}\n" |
| 6704 |
"\\&\n" |
| 6705 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 6706 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 6707 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 6708 |
"\\&\n" |
| 6709 |
"static void\n" |
| 6710 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 6711 |
" struct seccomp_notif_resp **resp,\n" |
| 6712 |
" struct seccomp_notif_sizes *sizes)\n" |
| 6713 |
"{\n" |
| 6714 |
" size_t resp_size;\n" |
| 6715 |
"\\&\n" |
| 6716 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 6717 |
" notifications and send notification responses, and allocate\n" |
| 6718 |
" buffers of those sizes. */\n" |
| 6719 |
"\\&\n" |
| 6720 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 6721 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 6722 |
"\\&\n" |
| 6723 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 6724 |
" if (*req == NULL)\n" |
| 6725 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 6726 |
"\\&\n" |
| 6727 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 6728 |
" that the user-space binary may have been built with user-space\n" |
| 6729 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 6730 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 6731 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 6732 |
" ensures that if the supervisor places bytes into the response\n" |
| 6733 |
" structure that are past the response size that the kernel expects,\n" |
| 6734 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 6735 |
"\\&\n" |
| 6736 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 6737 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 6738 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 6739 |
"\\&\n" |
| 6740 |
" *resp = malloc(resp_size);\n" |
| 6741 |
" if (*resp == NULL)\n" |
| 6742 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 6743 |
"\\&\n" |
| 6744 |
"}\n" |
| 6745 |
"\\&\n" |
| 6746 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 6747 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 6748 |
"\\&\n" |
| 6749 |
"static void\n" |
| 6750 |
"handleNotifications(int notifyFd)\n" |
| 6751 |
"{\n" |
| 6752 |
" bool pathOK;\n" |
| 6753 |
" char path[PATH_MAX];\n" |
| 6754 |
" struct seccomp_notif *req;\n" |
| 6755 |
" struct seccomp_notif_resp *resp;\n" |
| 6756 |
" struct seccomp_notif_sizes sizes;\n" |
| 6757 |
"\\&\n" |
| 6758 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 6759 |
"\\&\n" |
| 6760 |
" /* Loop handling notifications */\n" |
| 6761 |
"\\&\n" |
| 6762 |
" for (;;) {\n" |
| 6763 |
"\\&\n" |
| 6764 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 6765 |
"\\&\n" |
| 6766 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 6767 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 6768 |
" if (errno == EINTR)\n" |
| 6769 |
" continue;\n" |
| 6770 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 6771 |
" }\n" |
| 6772 |
"\\&\n" |
| 6773 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 6774 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 6775 |
"\\&\n" |
| 6776 |
" /* The only system call that can generate a notification event\n" |
| 6777 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 6778 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 6779 |
" code in case the seccomp filter is later modified to\n" |
| 6780 |
" generate notifications for other system calls. */\n" |
| 6781 |
"\\&\n" |
| 6782 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 6783 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 6784 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 6785 |
" exit(EXIT_FAILURE);\n" |
| 6786 |
" }\n" |
| 6787 |
"\\&\n" |
| 6788 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 6789 |
"\\&\n" |
| 6790 |
" /* Prepopulate some fields of the response */\n" |
| 6791 |
"\\&\n" |
| 6792 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 6793 |
" resp-E<gt>flags = 0;\n" |
| 6794 |
" resp-E<gt>val = 0;\n" |
| 6795 |
"\\&\n" |
| 6796 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 6797 |
" response (sending this response may yield an error if the\n" |
| 6798 |
" failure occurred because the notification ID was no longer\n" |
| 6799 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 6800 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 6801 |
" kernel to let the target process execute the mkdir();\n" |
| 6802 |
" otherwise, give an error for a directory pathname in any other\n" |
| 6803 |
" location. */\n" |
| 6804 |
"\\&\n" |
| 6805 |
" if (!pathOK) {\n" |
| 6806 |
" resp-E<gt>error = -EINVAL;\n" |
| 6807 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 6808 |
" strerror(-resp-E<gt>error));\n" |
| 6809 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 6810 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 6811 |
" path, req-E<gt>data.args[1]);\n" |
| 6812 |
"\\&\n" |
| 6813 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 6814 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 6815 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 6816 |
" mkdir() in target */\n" |
| 6817 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 6818 |
" resp-E<gt>val);\n" |
| 6819 |
" } else {\n" |
| 6820 |
"\\&\n" |
| 6821 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 6822 |
" back to the target */\n" |
| 6823 |
"\\&\n" |
| 6824 |
" resp-E<gt>error = -errno;\n" |
| 6825 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 6826 |
" strerror(errno));\n" |
| 6827 |
" }\n" |
| 6828 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 6829 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 6830 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 6831 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 6832 |
" } else {\n" |
| 6833 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 6834 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 6835 |
" strerror(-resp-E<gt>error));\n" |
| 6836 |
" }\n" |
| 6837 |
"\\&\n" |
| 6838 |
" /* Send a response to the notification */\n" |
| 6839 |
"\\&\n" |
| 6840 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 6841 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 6842 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 6843 |
"\\&\n" |
| 6844 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 6845 |
" if (errno == ENOENT)\n" |
| 6846 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 6847 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 6848 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 6849 |
" else\n" |
| 6850 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 6851 |
" }\n" |
| 6852 |
"\\&\n" |
| 6853 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 6854 |
" of the loop and terminates. This allows us to see what happens\n" |
| 6855 |
" if the target process makes further calls to mkdir(2). */\n" |
| 6856 |
"\\&\n" |
| 6857 |
" if (strcmp(path, \"/bye\") == 0)\n" |
| 6858 |
" break;\n" |
| 6859 |
" }\n" |
| 6860 |
"\\&\n" |
| 6861 |
" free(req);\n" |
| 6862 |
" free(resp);\n" |
| 6863 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 6864 |
" exit(EXIT_FAILURE);\n" |
| 6865 |
"}\n" |
| 6866 |
"\\&\n" |
| 6867 |
"/* Implementation of the supervisor process:\n" |
| 6868 |
"\\&\n" |
| 6869 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 6870 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 6871 |
"\\&\n" |
| 6872 |
"static void\n" |
| 6873 |
"supervisor(int sockPair[2])\n" |
| 6874 |
"{\n" |
| 6875 |
" int notifyFd;\n" |
| 6876 |
"\\&\n" |
| 6877 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 6878 |
"\\&\n" |
| 6879 |
" if (notifyFd == -1)\n" |
| 6880 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 6881 |
"\\&\n" |
| 6882 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 6883 |
"\\&\n" |
| 6884 |
" handleNotifications(notifyFd);\n" |
| 6885 |
"}\n" |
| 6886 |
"\\&\n" |
| 6887 |
"int\n" |
| 6888 |
"main(int argc, char *argv[])\n" |
| 6889 |
"{\n" |
| 6890 |
" int sockPair[2];\n" |
| 6891 |
" struct sigaction sa;\n" |
| 6892 |
"\\&\n" |
| 6893 |
" setbuf(stdout, NULL);\n" |
| 6894 |
"\\&\n" |
| 6895 |
" if (argc E<lt> 2) {\n" |
| 6896 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 6897 |
" exit(EXIT_FAILURE);\n" |
| 6898 |
" }\n" |
| 6899 |
"\\&\n" |
| 6900 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 6901 |
" notification file descriptor from the target process to the\n" |
| 6902 |
" supervisor process. */\n" |
| 6903 |
"\\&\n" |
| 6904 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 6905 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 6906 |
"\\&\n" |
| 6907 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 6908 |
" filtering. The target process writes the seccomp notification\n" |
| 6909 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 6910 |
" each directory in the command-line arguments. */\n" |
| 6911 |
"\\&\n" |
| 6912 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 6913 |
"\\&\n" |
| 6914 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 6915 |
" supervisor can also terminate. */\n" |
| 6916 |
"\\&\n" |
| 6917 |
" sa.sa_handler = sigchldHandler;\n" |
| 6918 |
" sa.sa_flags = 0;\n" |
| 6919 |
" sigemptyset(&sa.sa_mask);\n" |
| 6920 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 6921 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 6922 |
"\\&\n" |
| 6923 |
" supervisor(sockPair);\n" |
| 6924 |
"\\&\n" |
| 6925 |
" exit(EXIT_SUCCESS);\n" |
| 6926 |
"}\n" |
| 6927 |
|
| 6928 |
#. type: TH |
| 6929 |
#: mageia-cauldron |
| 6930 |
#, no-wrap |
| 6931 |
msgid "2026-02-10" |
| 6932 |
msgstr "10 فبراير 2026" |
| 6933 |
|
| 6934 |
#. type: TH |
| 6935 |
#: mageia-cauldron |
| 6936 |
#, no-wrap |
| 6937 |
msgid "Linux man-pages 6.17" |
| 6938 |
msgstr "صفحات دليل لينكس 6.17" |
| 6939 |
|
| 6940 |
#. type: Plain text |
| 6941 |
#: mageia-cauldron |
| 6942 |
#, no-wrap |
| 6943 |
msgid "" |
| 6944 |
"#define _GNU_SOURCE\n" |
| 6945 |
"#include E<lt>err.hE<gt>\n" |
| 6946 |
"#include E<lt>errno.hE<gt>\n" |
| 6947 |
"#include E<lt>fcntl.hE<gt>\n" |
| 6948 |
"#include E<lt>limits.hE<gt>\n" |
| 6949 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 6950 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 6951 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 6952 |
"#include E<lt>signal.hE<gt>\n" |
| 6953 |
"#include E<lt>stdbool.hE<gt>\n" |
| 6954 |
"#include E<lt>stdcountof.hE<gt>\n" |
| 6955 |
"#include E<lt>stddef.hE<gt>\n" |
| 6956 |
"#include E<lt>stdint.hE<gt>\n" |
| 6957 |
"#include E<lt>stdio.hE<gt>\n" |
| 6958 |
"#include E<lt>stdlib.hE<gt>\n" |
| 6959 |
"#include E<lt>string.hE<gt>\n" |
| 6960 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 6961 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 6962 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 6963 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 6964 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 6965 |
"#include E<lt>sys/types.hE<gt>\n" |
| 6966 |
"#include E<lt>sys/un.hE<gt>\n" |
| 6967 |
"#include E<lt>unistd.hE<gt>\n" |
| 6968 |
"\\&\n" |
| 6969 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 6970 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 6971 |
"\\&\n" |
| 6972 |
"static int\n" |
| 6973 |
"sendfd(int sockfd, int fd)\n" |
| 6974 |
"{\n" |
| 6975 |
" int data;\n" |
| 6976 |
" struct iovec iov;\n" |
| 6977 |
" struct msghdr msgh;\n" |
| 6978 |
" struct cmsghdr *cmsgp;\n" |
| 6979 |
"\\&\n" |
| 6980 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 6981 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 6982 |
" union to ensure that it is suitably aligned. */\n" |
| 6983 |
" union {\n" |
| 6984 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 6985 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 6986 |
" struct cmsghdr align;\n" |
| 6987 |
" } controlMsg;\n" |
| 6988 |
"\\&\n" |
| 6989 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 6990 |
" destination socket when sending a datagram. However, we do not\n" |
| 6991 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 6992 |
"\\&\n" |
| 6993 |
" msgh.msg_name = NULL;\n" |
| 6994 |
" msgh.msg_namelen = 0;\n" |
| 6995 |
"\\&\n" |
| 6996 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 6997 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 6998 |
" whose value is ignored by recvfd(). */\n" |
| 6999 |
"\\&\n" |
| 7000 |
" msgh.msg_iov = &iov;\n" |
| 7001 |
" msgh.msg_iovlen = 1;\n" |
| 7002 |
" iov.iov_base = &data;\n" |
| 7003 |
" iov.iov_len = sizeof(int);\n" |
| 7004 |
" data = 12345;\n" |
| 7005 |
"\\&\n" |
| 7006 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 7007 |
"\\&\n" |
| 7008 |
" msgh.msg_control = controlMsg.buf;\n" |
| 7009 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 7010 |
"\\&\n" |
| 7011 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 7012 |
"\\&\n" |
| 7013 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 7014 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 7015 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 7016 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 7017 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 7018 |
"\\&\n" |
| 7019 |
" /* Send real plus ancillary data */\n" |
| 7020 |
"\\&\n" |
| 7021 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 7022 |
" return -1;\n" |
| 7023 |
"\\&\n" |
| 7024 |
" return 0;\n" |
| 7025 |
"}\n" |
| 7026 |
"\\&\n" |
| 7027 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 7028 |
" the received file descriptor on success, or -1 on error. */\n" |
| 7029 |
"\\&\n" |
| 7030 |
"static int\n" |
| 7031 |
"recvfd(int sockfd)\n" |
| 7032 |
"{\n" |
| 7033 |
" int data, fd;\n" |
| 7034 |
" ssize_t nr;\n" |
| 7035 |
" struct iovec iov;\n" |
| 7036 |
" struct msghdr msgh;\n" |
| 7037 |
"\\&\n" |
| 7038 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 7039 |
" in sendfd() */\n" |
| 7040 |
" union {\n" |
| 7041 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 7042 |
" struct cmsghdr align;\n" |
| 7043 |
" } controlMsg;\n" |
| 7044 |
" struct cmsghdr *cmsgp;\n" |
| 7045 |
"\\&\n" |
| 7046 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 7047 |
" sending socket. However, we do not need this information. */\n" |
| 7048 |
"\\&\n" |
| 7049 |
" msgh.msg_name = NULL;\n" |
| 7050 |
" msgh.msg_namelen = 0;\n" |
| 7051 |
"\\&\n" |
| 7052 |
" /* Specify buffer for receiving real data */\n" |
| 7053 |
"\\&\n" |
| 7054 |
" msgh.msg_iov = &iov;\n" |
| 7055 |
" msgh.msg_iovlen = 1;\n" |
| 7056 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 7057 |
" iov.iov_len = sizeof(int);\n" |
| 7058 |
"\\&\n" |
| 7059 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 7060 |
"\\&\n" |
| 7061 |
" msgh.msg_control = controlMsg.buf;\n" |
| 7062 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 7063 |
"\\&\n" |
| 7064 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 7065 |
"\\&\n" |
| 7066 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 7067 |
" if (nr == -1)\n" |
| 7068 |
" return -1;\n" |
| 7069 |
"\\&\n" |
| 7070 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 7071 |
"\\&\n" |
| 7072 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 7073 |
"\\&\n" |
| 7074 |
" if (cmsgp == NULL\n" |
| 7075 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 7076 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 7077 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 7078 |
" {\n" |
| 7079 |
" errno = EINVAL;\n" |
| 7080 |
" return -1;\n" |
| 7081 |
" }\n" |
| 7082 |
"\\&\n" |
| 7083 |
" /* Return the received file descriptor to our caller */\n" |
| 7084 |
"\\&\n" |
| 7085 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 7086 |
" return fd;\n" |
| 7087 |
"}\n" |
| 7088 |
"\\&\n" |
| 7089 |
"static void\n" |
| 7090 |
"sigchldHandler(int sig)\n" |
| 7091 |
"{\n" |
| 7092 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 7093 |
"\\&\n" |
| 7094 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 7095 |
" _exit(EXIT_SUCCESS);\n" |
| 7096 |
"}\n" |
| 7097 |
"\\&\n" |
| 7098 |
"static int\n" |
| 7099 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 7100 |
"{\n" |
| 7101 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 7102 |
"}\n" |
| 7103 |
"\\&\n" |
| 7104 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 7105 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 7106 |
" completion of these instructions, the accumulator contains the system\n" |
| 7107 |
" call number. */\n" |
| 7108 |
"\\&\n" |
| 7109 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 7110 |
"\\&\n" |
| 7111 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 7112 |
"\\&\n" |
| 7113 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 7114 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 7115 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 7116 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 7117 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 7118 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 7119 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 7120 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 7121 |
"\\&\n" |
| 7122 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 7123 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 7124 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 7125 |
"\\&\n" |
| 7126 |
" The function return value is a file descriptor from which the\n" |
| 7127 |
" user-space notifications can be fetched. */\n" |
| 7128 |
"\\&\n" |
| 7129 |
"static int\n" |
| 7130 |
"installNotifyFilter(void)\n" |
| 7131 |
"{\n" |
| 7132 |
" int notifyFd;\n" |
| 7133 |
"\\&\n" |
| 7134 |
" struct sock_filter filter[] = {\n" |
| 7135 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 7136 |
"\\&\n" |
| 7137 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 7138 |
"\\&\n" |
| 7139 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 7140 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 7141 |
"\\&\n" |
| 7142 |
" /* Every other system call is allowed */\n" |
| 7143 |
"\\&\n" |
| 7144 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 7145 |
" };\n" |
| 7146 |
"\\&\n" |
| 7147 |
" struct sock_fprog prog = {\n" |
| 7148 |
" .len = countof(filter),\n" |
| 7149 |
" .filter = filter,\n" |
| 7150 |
" };\n" |
| 7151 |
"\\&\n" |
| 7152 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 7153 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 7154 |
"\\&\n" |
| 7155 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 7156 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 7157 |
" if (notifyFd == -1)\n" |
| 7158 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 7159 |
"\\&\n" |
| 7160 |
" return notifyFd;\n" |
| 7161 |
"}\n" |
| 7162 |
"\\&\n" |
| 7163 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 7164 |
"\\&\n" |
| 7165 |
"static void\n" |
| 7166 |
"closeSocketPair(int sockPair[2])\n" |
| 7167 |
"{\n" |
| 7168 |
" if (close(sockPair[0]) == -1)\n" |
| 7169 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 7170 |
" if (close(sockPair[1]) == -1)\n" |
| 7171 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 7172 |
"}\n" |
| 7173 |
"\\&\n" |
| 7174 |
"/* Implementation of the target process. Create a child process that:\n" |
| 7175 |
"\\&\n" |
| 7176 |
" (1) installs a seccomp filter with the\n" |
| 7177 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 7178 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 7179 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 7180 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 7181 |
"\\&\n" |
| 7182 |
" The function return value in the parent is the PID of the child\n" |
| 7183 |
" process; the child does not return from this function. */\n" |
| 7184 |
"\\&\n" |
| 7185 |
"static pid_t\n" |
| 7186 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 7187 |
"{\n" |
| 7188 |
" int notifyFd, s;\n" |
| 7189 |
" pid_t targetPid;\n" |
| 7190 |
"\\&\n" |
| 7191 |
" targetPid = fork();\n" |
| 7192 |
"\\&\n" |
| 7193 |
" if (targetPid == -1)\n" |
| 7194 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 7195 |
"\\&\n" |
| 7196 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 7197 |
" return targetPid;\n" |
| 7198 |
"\\&\n" |
| 7199 |
" /* Child falls through to here */\n" |
| 7200 |
"\\&\n" |
| 7201 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 7202 |
"\\&\n" |
| 7203 |
" /* Install seccomp filter(s) */\n" |
| 7204 |
"\\&\n" |
| 7205 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 7206 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 7207 |
"\\&\n" |
| 7208 |
" notifyFd = installNotifyFilter();\n" |
| 7209 |
"\\&\n" |
| 7210 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 7211 |
" a UNIX domain socket */\n" |
| 7212 |
"\\&\n" |
| 7213 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 7214 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 7215 |
"\\&\n" |
| 7216 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 7217 |
"\\&\n" |
| 7218 |
" if (close(notifyFd) == -1)\n" |
| 7219 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 7220 |
"\\&\n" |
| 7221 |
" closeSocketPair(sockPair);\n" |
| 7222 |
"\\&\n" |
| 7223 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 7224 |
"\\&\n" |
| 7225 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 7226 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 7227 |
"\\&\n" |
| 7228 |
" s = mkdir(*ap, 0700);\n" |
| 7229 |
" if (s == -1)\n" |
| 7230 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 7231 |
" else\n" |
| 7232 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 7233 |
" }\n" |
| 7234 |
"\\&\n" |
| 7235 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 7236 |
" exit(EXIT_SUCCESS);\n" |
| 7237 |
"}\n" |
| 7238 |
"\\&\n" |
| 7239 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 7240 |
" operation is still valid. It will no longer be valid if the target\n" |
| 7241 |
" process has terminated or is no longer blocked in the system call that\n" |
| 7242 |
" generated the notification (because it was interrupted by a signal).\n" |
| 7243 |
"\\&\n" |
| 7244 |
" This operation can be used when doing such things as accessing\n" |
| 7245 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 7246 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 7247 |
" terminates and is reused by another process. */\n" |
| 7248 |
"\\&\n" |
| 7249 |
"static bool\n" |
| 7250 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 7251 |
"{\n" |
| 7252 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 7253 |
"}\n" |
| 7254 |
"\\&\n" |
| 7255 |
"/* Access the memory of the target process in order to fetch the\n" |
| 7256 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 7257 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 7258 |
" a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" |
| 7259 |
"\\&\n" |
| 7260 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 7261 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 7262 |
"\\&\n" |
| 7263 |
"static bool\n" |
| 7264 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 7265 |
" int argNum, char *path, size_t size)\n" |
| 7266 |
"{\n" |
| 7267 |
" int procMemFd;\n" |
| 7268 |
" char procMemPath[PATH_MAX];\n" |
| 7269 |
" ssize_t nread;\n" |
| 7270 |
"\\&\n" |
| 7271 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 7272 |
"\\&\n" |
| 7273 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 7274 |
" if (procMemFd == -1)\n" |
| 7275 |
" return false;\n" |
| 7276 |
"\\&\n" |
| 7277 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 7278 |
" and blocked in the system call that caused the notification.\n" |
| 7279 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 7280 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 7281 |
" descriptor that we opened corresponded to the process for which we\n" |
| 7282 |
" received a notification. If that process subsequently terminates,\n" |
| 7283 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 7284 |
"\\&\n" |
| 7285 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 7286 |
" close(procMemFd);\n" |
| 7287 |
" return false;\n" |
| 7288 |
" }\n" |
| 7289 |
"\\&\n" |
| 7290 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 7291 |
"\\&\n" |
| 7292 |
" nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n" |
| 7293 |
"\\&\n" |
| 7294 |
" close(procMemFd);\n" |
| 7295 |
"\\&\n" |
| 7296 |
" if (nread E<lt>= 0)\n" |
| 7297 |
" return false;\n" |
| 7298 |
"\\&\n" |
| 7299 |
" /* Once again check that the notification ID is still valid. The\n" |
| 7300 |
" case we are particularly concerned about here is that just\n" |
| 7301 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 7302 |
" call was interrupted by a signal handler, and after the handler\n" |
| 7303 |
" returned, the target carried on execution (past the interrupted\n" |
| 7304 |
" system call). In that case, we have no guarantees about what we\n" |
| 7305 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 7306 |
" changed by subsequent operations. */\n" |
| 7307 |
"\\&\n" |
| 7308 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 7309 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 7310 |
" return false;\n" |
| 7311 |
" }\n" |
| 7312 |
"\\&\n" |
| 7313 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 7314 |
" we have no guarantees about what was in the memory of the target\n" |
| 7315 |
" process. (The memory may have been modified by another thread, or\n" |
| 7316 |
" even by an external attacking process.) We therefore treat the\n" |
| 7317 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 7318 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 7319 |
" error for the target process. */\n" |
| 7320 |
"\\&\n" |
| 7321 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 7322 |
" return true;\n" |
| 7323 |
"\\&\n" |
| 7324 |
" return false;\n" |
| 7325 |
"}\n" |
| 7326 |
"\\&\n" |
| 7327 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 7328 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 7329 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 7330 |
"\\&\n" |
| 7331 |
"static void\n" |
| 7332 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 7333 |
" struct seccomp_notif_resp **resp,\n" |
| 7334 |
" struct seccomp_notif_sizes *sizes)\n" |
| 7335 |
"{\n" |
| 7336 |
" size_t resp_size;\n" |
| 7337 |
"\\&\n" |
| 7338 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 7339 |
" notifications and send notification responses, and allocate\n" |
| 7340 |
" buffers of those sizes. */\n" |
| 7341 |
"\\&\n" |
| 7342 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 7343 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 7344 |
"\\&\n" |
| 7345 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 7346 |
" if (*req == NULL)\n" |
| 7347 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 7348 |
"\\&\n" |
| 7349 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 7350 |
" that the user-space binary may have been built with user-space\n" |
| 7351 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 7352 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 7353 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 7354 |
" ensures that if the supervisor places bytes into the response\n" |
| 7355 |
" structure that are past the response size that the kernel expects,\n" |
| 7356 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 7357 |
"\\&\n" |
| 7358 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 7359 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 7360 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 7361 |
"\\&\n" |
| 7362 |
" *resp = malloc(resp_size);\n" |
| 7363 |
" if (*resp == NULL)\n" |
| 7364 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 7365 |
"\\&\n" |
| 7366 |
"}\n" |
| 7367 |
"\\&\n" |
| 7368 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 7369 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 7370 |
"\\&\n" |
| 7371 |
"static void\n" |
| 7372 |
"handleNotifications(int notifyFd)\n" |
| 7373 |
"{\n" |
| 7374 |
" bool pathOK;\n" |
| 7375 |
" char path[PATH_MAX];\n" |
| 7376 |
" struct seccomp_notif *req;\n" |
| 7377 |
" struct seccomp_notif_resp *resp;\n" |
| 7378 |
" struct seccomp_notif_sizes sizes;\n" |
| 7379 |
"\\&\n" |
| 7380 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 7381 |
"\\&\n" |
| 7382 |
" /* Loop handling notifications */\n" |
| 7383 |
"\\&\n" |
| 7384 |
" for (;;) {\n" |
| 7385 |
"\\&\n" |
| 7386 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 7387 |
"\\&\n" |
| 7388 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 7389 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 7390 |
" if (errno == EINTR)\n" |
| 7391 |
" continue;\n" |
| 7392 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 7393 |
" }\n" |
| 7394 |
"\\&\n" |
| 7395 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 7396 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 7397 |
"\\&\n" |
| 7398 |
" /* The only system call that can generate a notification event\n" |
| 7399 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 7400 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 7401 |
" code in case the seccomp filter is later modified to\n" |
| 7402 |
" generate notifications for other system calls. */\n" |
| 7403 |
"\\&\n" |
| 7404 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 7405 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 7406 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 7407 |
" exit(EXIT_FAILURE);\n" |
| 7408 |
" }\n" |
| 7409 |
"\\&\n" |
| 7410 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 7411 |
"\\&\n" |
| 7412 |
" /* Prepopulate some fields of the response */\n" |
| 7413 |
"\\&\n" |
| 7414 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 7415 |
" resp-E<gt>flags = 0;\n" |
| 7416 |
" resp-E<gt>val = 0;\n" |
| 7417 |
"\\&\n" |
| 7418 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 7419 |
" response (sending this response may yield an error if the\n" |
| 7420 |
" failure occurred because the notification ID was no longer\n" |
| 7421 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 7422 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 7423 |
" kernel to let the target process execute the mkdir();\n" |
| 7424 |
" otherwise, give an error for a directory pathname in any other\n" |
| 7425 |
" location. */\n" |
| 7426 |
"\\&\n" |
| 7427 |
" if (!pathOK) {\n" |
| 7428 |
" resp-E<gt>error = -EINVAL;\n" |
| 7429 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 7430 |
" strerror(-resp-E<gt>error));\n" |
| 7431 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 7432 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 7433 |
" path, req-E<gt>data.args[1]);\n" |
| 7434 |
"\\&\n" |
| 7435 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 7436 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 7437 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 7438 |
" mkdir() in target */\n" |
| 7439 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 7440 |
" resp-E<gt>val);\n" |
| 7441 |
" } else {\n" |
| 7442 |
"\\&\n" |
| 7443 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 7444 |
" back to the target */\n" |
| 7445 |
"\\&\n" |
| 7446 |
" resp-E<gt>error = -errno;\n" |
| 7447 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 7448 |
" strerror(errno));\n" |
| 7449 |
" }\n" |
| 7450 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 7451 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 7452 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 7453 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 7454 |
" } else {\n" |
| 7455 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 7456 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 7457 |
" strerror(-resp-E<gt>error));\n" |
| 7458 |
" }\n" |
| 7459 |
"\\&\n" |
| 7460 |
" /* Send a response to the notification */\n" |
| 7461 |
"\\&\n" |
| 7462 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 7463 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 7464 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 7465 |
"\\&\n" |
| 7466 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 7467 |
" if (errno == ENOENT)\n" |
| 7468 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 7469 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 7470 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 7471 |
" else\n" |
| 7472 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 7473 |
" }\n" |
| 7474 |
"\\&\n" |
| 7475 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 7476 |
" of the loop and terminates. This allows us to see what happens\n" |
| 7477 |
" if the target process makes further calls to mkdir(2). */\n" |
| 7478 |
"\\&\n" |
| 7479 |
" if (strcmp(path, \"/bye\") == 0)\n" |
| 7480 |
" break;\n" |
| 7481 |
" }\n" |
| 7482 |
"\\&\n" |
| 7483 |
" free(req);\n" |
| 7484 |
" free(resp);\n" |
| 7485 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 7486 |
" exit(EXIT_FAILURE);\n" |
| 7487 |
"}\n" |
| 7488 |
"\\&\n" |
| 7489 |
"/* Implementation of the supervisor process:\n" |
| 7490 |
"\\&\n" |
| 7491 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 7492 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 7493 |
"\\&\n" |
| 7494 |
"static void\n" |
| 7495 |
"supervisor(int sockPair[2])\n" |
| 7496 |
"{\n" |
| 7497 |
" int notifyFd;\n" |
| 7498 |
"\\&\n" |
| 7499 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 7500 |
"\\&\n" |
| 7501 |
" if (notifyFd == -1)\n" |
| 7502 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 7503 |
"\\&\n" |
| 7504 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 7505 |
"\\&\n" |
| 7506 |
" handleNotifications(notifyFd);\n" |
| 7507 |
"}\n" |
| 7508 |
"\\&\n" |
| 7509 |
"int\n" |
| 7510 |
"main(int argc, char *argv[])\n" |
| 7511 |
"{\n" |
| 7512 |
" int sockPair[2];\n" |
| 7513 |
" struct sigaction sa;\n" |
| 7514 |
"\\&\n" |
| 7515 |
" setbuf(stdout, NULL);\n" |
| 7516 |
"\\&\n" |
| 7517 |
" if (argc E<lt> 2) {\n" |
| 7518 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 7519 |
" exit(EXIT_FAILURE);\n" |
| 7520 |
" }\n" |
| 7521 |
"\\&\n" |
| 7522 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 7523 |
" notification file descriptor from the target process to the\n" |
| 7524 |
" supervisor process. */\n" |
| 7525 |
"\\&\n" |
| 7526 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 7527 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 7528 |
"\\&\n" |
| 7529 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 7530 |
" filtering. The target process writes the seccomp notification\n" |
| 7531 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 7532 |
" each directory in the command-line arguments. */\n" |
| 7533 |
"\\&\n" |
| 7534 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 7535 |
"\\&\n" |
| 7536 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 7537 |
" supervisor can also terminate. */\n" |
| 7538 |
"\\&\n" |
| 7539 |
" sa.sa_handler = sigchldHandler;\n" |
| 7540 |
" sa.sa_flags = 0;\n" |
| 7541 |
" sigemptyset(&sa.sa_mask);\n" |
| 7542 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 7543 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 7544 |
"\\&\n" |
| 7545 |
" supervisor(sockPair);\n" |
| 7546 |
"\\&\n" |
| 7547 |
" exit(EXIT_SUCCESS);\n" |
| 7548 |
"}\n" |
| 7549 |
msgstr "" |
| 7550 |
"#define _GNU_SOURCE\n" |
| 7551 |
"#include E<lt>err.hE<gt>\n" |
| 7552 |
"#include E<lt>errno.hE<gt>\n" |
| 7553 |
"#include E<lt>fcntl.hE<gt>\n" |
| 7554 |
"#include E<lt>limits.hE<gt>\n" |
| 7555 |
"#include E<lt>linux/audit.hE<gt>\n" |
| 7556 |
"#include E<lt>linux/filter.hE<gt>\n" |
| 7557 |
"#include E<lt>linux/seccomp.hE<gt>\n" |
| 7558 |
"#include E<lt>signal.hE<gt>\n" |
| 7559 |
"#include E<lt>stdbool.hE<gt>\n" |
| 7560 |
"#include E<lt>stdcountof.hE<gt>\n" |
| 7561 |
"#include E<lt>stddef.hE<gt>\n" |
| 7562 |
"#include E<lt>stdint.hE<gt>\n" |
| 7563 |
"#include E<lt>stdio.hE<gt>\n" |
| 7564 |
"#include E<lt>stdlib.hE<gt>\n" |
| 7565 |
"#include E<lt>string.hE<gt>\n" |
| 7566 |
"#include E<lt>sys/ioctl.hE<gt>\n" |
| 7567 |
"#include E<lt>sys/prctl.hE<gt>\n" |
| 7568 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 7569 |
"#include E<lt>sys/stat.hE<gt>\n" |
| 7570 |
"#include E<lt>sys/syscall.hE<gt>\n" |
| 7571 |
"#include E<lt>sys/types.hE<gt>\n" |
| 7572 |
"#include E<lt>sys/un.hE<gt>\n" |
| 7573 |
"#include E<lt>unistd.hE<gt>\n" |
| 7574 |
"\\&\n" |
| 7575 |
"/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" |
| 7576 |
" \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" |
| 7577 |
"\\&\n" |
| 7578 |
"static int\n" |
| 7579 |
"sendfd(int sockfd, int fd)\n" |
| 7580 |
"{\n" |
| 7581 |
" int data;\n" |
| 7582 |
" struct iovec iov;\n" |
| 7583 |
" struct msghdr msgh;\n" |
| 7584 |
" struct cmsghdr *cmsgp;\n" |
| 7585 |
"\\&\n" |
| 7586 |
" /* Allocate a char array of suitable size to hold the ancillary data.\n" |
| 7587 |
" However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" |
| 7588 |
" union to ensure that it is suitably aligned. */\n" |
| 7589 |
" union {\n" |
| 7590 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 7591 |
" /* Space large enough to hold an \\[aq]int\\[aq] */\n" |
| 7592 |
" struct cmsghdr align;\n" |
| 7593 |
" } controlMsg;\n" |
| 7594 |
"\\&\n" |
| 7595 |
" /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" |
| 7596 |
" destination socket when sending a datagram. However, we do not\n" |
| 7597 |
" need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" |
| 7598 |
"\\&\n" |
| 7599 |
" msgh.msg_name = NULL;\n" |
| 7600 |
" msgh.msg_namelen = 0;\n" |
| 7601 |
"\\&\n" |
| 7602 |
" /* On Linux, we must transmit at least one byte of real data in\n" |
| 7603 |
" order to send ancillary data. We transmit an arbitrary integer\n" |
| 7604 |
" whose value is ignored by recvfd(). */\n" |
| 7605 |
"\\&\n" |
| 7606 |
" msgh.msg_iov = &iov;\n" |
| 7607 |
" msgh.msg_iovlen = 1;\n" |
| 7608 |
" iov.iov_base = &data;\n" |
| 7609 |
" iov.iov_len = sizeof(int);\n" |
| 7610 |
" data = 12345;\n" |
| 7611 |
"\\&\n" |
| 7612 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 7613 |
"\\&\n" |
| 7614 |
" msgh.msg_control = controlMsg.buf;\n" |
| 7615 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 7616 |
"\\&\n" |
| 7617 |
" /* Set up ancillary data describing file descriptor to send */\n" |
| 7618 |
"\\&\n" |
| 7619 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 7620 |
" cmsgp-E<gt>cmsg_level = SOL_SOCKET;\n" |
| 7621 |
" cmsgp-E<gt>cmsg_type = SCM_RIGHTS;\n" |
| 7622 |
" cmsgp-E<gt>cmsg_len = CMSG_LEN(sizeof(int));\n" |
| 7623 |
" memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" |
| 7624 |
"\\&\n" |
| 7625 |
" /* Send real plus ancillary data */\n" |
| 7626 |
"\\&\n" |
| 7627 |
" if (sendmsg(sockfd, &msgh, 0) == -1)\n" |
| 7628 |
" return -1;\n" |
| 7629 |
"\\&\n" |
| 7630 |
" return 0;\n" |
| 7631 |
"}\n" |
| 7632 |
"\\&\n" |
| 7633 |
"/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" |
| 7634 |
" the received file descriptor on success, or -1 on error. */\n" |
| 7635 |
"\\&\n" |
| 7636 |
"static int\n" |
| 7637 |
"recvfd(int sockfd)\n" |
| 7638 |
"{\n" |
| 7639 |
" int data, fd;\n" |
| 7640 |
" ssize_t nr;\n" |
| 7641 |
" struct iovec iov;\n" |
| 7642 |
" struct msghdr msgh;\n" |
| 7643 |
"\\&\n" |
| 7644 |
" /* Allocate a char buffer for the ancillary data. See the comments\n" |
| 7645 |
" in sendfd() */\n" |
| 7646 |
" union {\n" |
| 7647 |
" char buf[CMSG_SPACE(sizeof(int))];\n" |
| 7648 |
" struct cmsghdr align;\n" |
| 7649 |
" } controlMsg;\n" |
| 7650 |
" struct cmsghdr *cmsgp;\n" |
| 7651 |
"\\&\n" |
| 7652 |
" /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" |
| 7653 |
" sending socket. However, we do not need this information. */\n" |
| 7654 |
"\\&\n" |
| 7655 |
" msgh.msg_name = NULL;\n" |
| 7656 |
" msgh.msg_namelen = 0;\n" |
| 7657 |
"\\&\n" |
| 7658 |
" /* Specify buffer for receiving real data */\n" |
| 7659 |
"\\&\n" |
| 7660 |
" msgh.msg_iov = &iov;\n" |
| 7661 |
" msgh.msg_iovlen = 1;\n" |
| 7662 |
" iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" |
| 7663 |
" iov.iov_len = sizeof(int);\n" |
| 7664 |
"\\&\n" |
| 7665 |
" /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" |
| 7666 |
"\\&\n" |
| 7667 |
" msgh.msg_control = controlMsg.buf;\n" |
| 7668 |
" msgh.msg_controllen = sizeof(controlMsg.buf);\n" |
| 7669 |
"\\&\n" |
| 7670 |
" /* Receive real plus ancillary data; real data is ignored */\n" |
| 7671 |
"\\&\n" |
| 7672 |
" nr = recvmsg(sockfd, &msgh, 0);\n" |
| 7673 |
" if (nr == -1)\n" |
| 7674 |
" return -1;\n" |
| 7675 |
"\\&\n" |
| 7676 |
" cmsgp = CMSG_FIRSTHDR(&msgh);\n" |
| 7677 |
"\\&\n" |
| 7678 |
" /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" |
| 7679 |
"\\&\n" |
| 7680 |
" if (cmsgp == NULL\n" |
| 7681 |
" || cmsgp-E<gt>cmsg_len != CMSG_LEN(sizeof(int))\n" |
| 7682 |
" || cmsgp-E<gt>cmsg_level != SOL_SOCKET\n" |
| 7683 |
" || cmsgp-E<gt>cmsg_type != SCM_RIGHTS)\n" |
| 7684 |
" {\n" |
| 7685 |
" errno = EINVAL;\n" |
| 7686 |
" return -1;\n" |
| 7687 |
" }\n" |
| 7688 |
"\\&\n" |
| 7689 |
" /* Return the received file descriptor to our caller */\n" |
| 7690 |
"\\&\n" |
| 7691 |
" memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" |
| 7692 |
" return fd;\n" |
| 7693 |
"}\n" |
| 7694 |
"\\&\n" |
| 7695 |
"static void\n" |
| 7696 |
"sigchldHandler(int sig)\n" |
| 7697 |
"{\n" |
| 7698 |
" char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" |
| 7699 |
"\\&\n" |
| 7700 |
" write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" |
| 7701 |
" _exit(EXIT_SUCCESS);\n" |
| 7702 |
"}\n" |
| 7703 |
"\\&\n" |
| 7704 |
"static int\n" |
| 7705 |
"seccomp(unsigned int operation, unsigned int flags, void *args)\n" |
| 7706 |
"{\n" |
| 7707 |
" return syscall(SYS_seccomp, operation, flags, args);\n" |
| 7708 |
"}\n" |
| 7709 |
"\\&\n" |
| 7710 |
"/* The following is the x86-64-specific BPF boilerplate code for checking\n" |
| 7711 |
" that the BPF program is running on the right architecture + ABI. At\n" |
| 7712 |
" completion of these instructions, the accumulator contains the system\n" |
| 7713 |
" call number. */\n" |
| 7714 |
"\\&\n" |
| 7715 |
"/* For the x32 ABI, all system call numbers have bit 30 set */\n" |
| 7716 |
"\\&\n" |
| 7717 |
"#define X32_SYSCALL_BIT 0x40000000\n" |
| 7718 |
"\\&\n" |
| 7719 |
"#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" |
| 7720 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 7721 |
" (offsetof(struct seccomp_data, arch))), \\[rs]\n" |
| 7722 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" |
| 7723 |
" BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" |
| 7724 |
" (offsetof(struct seccomp_data, nr))), \\[rs]\n" |
| 7725 |
" BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" |
| 7726 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" |
| 7727 |
"\\&\n" |
| 7728 |
"/* installNotifyFilter() installs a seccomp filter that generates\n" |
| 7729 |
" user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" |
| 7730 |
" calls mkdir(2); the filter allows all other system calls.\n" |
| 7731 |
"\\&\n" |
| 7732 |
" The function return value is a file descriptor from which the\n" |
| 7733 |
" user-space notifications can be fetched. */\n" |
| 7734 |
"\\&\n" |
| 7735 |
"static int\n" |
| 7736 |
"installNotifyFilter(void)\n" |
| 7737 |
"{\n" |
| 7738 |
" int notifyFd;\n" |
| 7739 |
"\\&\n" |
| 7740 |
" struct sock_filter filter[] = {\n" |
| 7741 |
" X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" |
| 7742 |
"\\&\n" |
| 7743 |
" /* mkdir() triggers notification to user-space supervisor */\n" |
| 7744 |
"\\&\n" |
| 7745 |
" BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" |
| 7746 |
" BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" |
| 7747 |
"\\&\n" |
| 7748 |
" /* Every other system call is allowed */\n" |
| 7749 |
"\\&\n" |
| 7750 |
" BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" |
| 7751 |
" };\n" |
| 7752 |
"\\&\n" |
| 7753 |
" struct sock_fprog prog = {\n" |
| 7754 |
" .len = countof(filter),\n" |
| 7755 |
" .filter = filter,\n" |
| 7756 |
" };\n" |
| 7757 |
"\\&\n" |
| 7758 |
" /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 7759 |
" as a result, seccomp() returns a notification file descriptor. */\n" |
| 7760 |
"\\&\n" |
| 7761 |
" notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" |
| 7762 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" |
| 7763 |
" if (notifyFd == -1)\n" |
| 7764 |
" err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" |
| 7765 |
"\\&\n" |
| 7766 |
" return notifyFd;\n" |
| 7767 |
"}\n" |
| 7768 |
"\\&\n" |
| 7769 |
"/* Close a pair of sockets created by socketpair() */\n" |
| 7770 |
"\\&\n" |
| 7771 |
"static void\n" |
| 7772 |
"closeSocketPair(int sockPair[2])\n" |
| 7773 |
"{\n" |
| 7774 |
" if (close(sockPair[0]) == -1)\n" |
| 7775 |
" err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" |
| 7776 |
" if (close(sockPair[1]) == -1)\n" |
| 7777 |
" err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" |
| 7778 |
"}\n" |
| 7779 |
"\\&\n" |
| 7780 |
"/* Implementation of the target process. Create a child process that:\n" |
| 7781 |
"\\&\n" |
| 7782 |
" (1) installs a seccomp filter with the\n" |
| 7783 |
" SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" |
| 7784 |
" (2) writes the seccomp notification file descriptor returned from\n" |
| 7785 |
" the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" |
| 7786 |
" (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" |
| 7787 |
"\\&\n" |
| 7788 |
" The function return value in the parent is the PID of the child\n" |
| 7789 |
" process; the child does not return from this function. */\n" |
| 7790 |
"\\&\n" |
| 7791 |
"static pid_t\n" |
| 7792 |
"targetProcess(int sockPair[2], char *argv[])\n" |
| 7793 |
"{\n" |
| 7794 |
" int notifyFd, s;\n" |
| 7795 |
" pid_t targetPid;\n" |
| 7796 |
"\\&\n" |
| 7797 |
" targetPid = fork();\n" |
| 7798 |
"\\&\n" |
| 7799 |
" if (targetPid == -1)\n" |
| 7800 |
" err(EXIT_FAILURE, \"fork\");\n" |
| 7801 |
"\\&\n" |
| 7802 |
" if (targetPid E<gt> 0) /* In parent, return PID of child */\n" |
| 7803 |
" return targetPid;\n" |
| 7804 |
"\\&\n" |
| 7805 |
" /* Child falls through to here */\n" |
| 7806 |
"\\&\n" |
| 7807 |
" printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" |
| 7808 |
"\\&\n" |
| 7809 |
" /* Install seccomp filter(s) */\n" |
| 7810 |
"\\&\n" |
| 7811 |
" if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" |
| 7812 |
" err(EXIT_FAILURE, \"prctl\");\n" |
| 7813 |
"\\&\n" |
| 7814 |
" notifyFd = installNotifyFilter();\n" |
| 7815 |
"\\&\n" |
| 7816 |
" /* Pass the notification file descriptor to the tracing process over\n" |
| 7817 |
" a UNIX domain socket */\n" |
| 7818 |
"\\&\n" |
| 7819 |
" if (sendfd(sockPair[0], notifyFd) == -1)\n" |
| 7820 |
" err(EXIT_FAILURE, \"sendfd\");\n" |
| 7821 |
"\\&\n" |
| 7822 |
" /* Notification and socket FDs are no longer needed in target */\n" |
| 7823 |
"\\&\n" |
| 7824 |
" if (close(notifyFd) == -1)\n" |
| 7825 |
" err(EXIT_FAILURE, \"close-target-notify-fd\");\n" |
| 7826 |
"\\&\n" |
| 7827 |
" closeSocketPair(sockPair);\n" |
| 7828 |
"\\&\n" |
| 7829 |
" /* Perform a mkdir() call for each of the command-line arguments */\n" |
| 7830 |
"\\&\n" |
| 7831 |
" for (char **ap = argv; *ap != NULL; ap++) {\n" |
| 7832 |
" printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" |
| 7833 |
"\\&\n" |
| 7834 |
" s = mkdir(*ap, 0700);\n" |
| 7835 |
" if (s == -1)\n" |
| 7836 |
" perror(\"T: ERROR: mkdir(2)\");\n" |
| 7837 |
" else\n" |
| 7838 |
" printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" |
| 7839 |
" }\n" |
| 7840 |
"\\&\n" |
| 7841 |
" printf(\"\\[rs]nT: terminating\\[rs]n\");\n" |
| 7842 |
" exit(EXIT_SUCCESS);\n" |
| 7843 |
"}\n" |
| 7844 |
"\\&\n" |
| 7845 |
"/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" |
| 7846 |
" operation is still valid. It will no longer be valid if the target\n" |
| 7847 |
" process has terminated or is no longer blocked in the system call that\n" |
| 7848 |
" generated the notification (because it was interrupted by a signal).\n" |
| 7849 |
"\\&\n" |
| 7850 |
" This operation can be used when doing such things as accessing\n" |
| 7851 |
" /proc/PID files in the target process in order to avoid TOCTOU race\n" |
| 7852 |
" conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" |
| 7853 |
" terminates and is reused by another process. */\n" |
| 7854 |
"\\&\n" |
| 7855 |
"static bool\n" |
| 7856 |
"cookieIsValid(int notifyFd, uint64_t id)\n" |
| 7857 |
"{\n" |
| 7858 |
" return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" |
| 7859 |
"}\n" |
| 7860 |
"\\&\n" |
| 7861 |
"/* Access the memory of the target process in order to fetch the\n" |
| 7862 |
" pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" |
| 7863 |
" \\[aq]req-E<gt>data.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" |
| 7864 |
" a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" |
| 7865 |
"\\&\n" |
| 7866 |
" Returns true if the pathname is successfully fetched, and false\n" |
| 7867 |
" otherwise. For possible causes of failure, see the comments below. */\n" |
| 7868 |
"\\&\n" |
| 7869 |
"static bool\n" |
| 7870 |
"getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" |
| 7871 |
" int argNum, char *path, size_t size)\n" |
| 7872 |
"{\n" |
| 7873 |
" int procMemFd;\n" |
| 7874 |
" char procMemPath[PATH_MAX];\n" |
| 7875 |
" ssize_t nread;\n" |
| 7876 |
"\\&\n" |
| 7877 |
" snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-E<gt>pid);\n" |
| 7878 |
"\\&\n" |
| 7879 |
" procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" |
| 7880 |
" if (procMemFd == -1)\n" |
| 7881 |
" return false;\n" |
| 7882 |
"\\&\n" |
| 7883 |
" /* Check that the process whose info we are accessing is still alive\n" |
| 7884 |
" and blocked in the system call that caused the notification.\n" |
| 7885 |
" If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" |
| 7886 |
" cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" |
| 7887 |
" descriptor that we opened corresponded to the process for which we\n" |
| 7888 |
" received a notification. If that process subsequently terminates,\n" |
| 7889 |
" then read() on that file descriptor will return 0 (EOF). */\n" |
| 7890 |
"\\&\n" |
| 7891 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 7892 |
" close(procMemFd);\n" |
| 7893 |
" return false;\n" |
| 7894 |
" }\n" |
| 7895 |
"\\&\n" |
| 7896 |
" /* Read bytes at the location containing the pathname argument */\n" |
| 7897 |
"\\&\n" |
| 7898 |
" nread = pread(procMemFd, path, size, req-E<gt>data.args[argNum]);\n" |
| 7899 |
"\\&\n" |
| 7900 |
" close(procMemFd);\n" |
| 7901 |
"\\&\n" |
| 7902 |
" if (nread E<lt>= 0)\n" |
| 7903 |
" return false;\n" |
| 7904 |
"\\&\n" |
| 7905 |
" /* Once again check that the notification ID is still valid. The\n" |
| 7906 |
" case we are particularly concerned about here is that just\n" |
| 7907 |
" before we fetched the pathname, the target\\[aq]s blocked system\n" |
| 7908 |
" call was interrupted by a signal handler, and after the handler\n" |
| 7909 |
" returned, the target carried on execution (past the interrupted\n" |
| 7910 |
" system call). In that case, we have no guarantees about what we\n" |
| 7911 |
" are reading, since the target\\[aq]s memory may have been arbitrarily\n" |
| 7912 |
" changed by subsequent operations. */\n" |
| 7913 |
"\\&\n" |
| 7914 |
" if (!cookieIsValid(notifyFd, req-E<gt>id)) {\n" |
| 7915 |
" perror(\"\\[rs]tS: notification ID check failed!!!\");\n" |
| 7916 |
" return false;\n" |
| 7917 |
" }\n" |
| 7918 |
"\\&\n" |
| 7919 |
" /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" |
| 7920 |
" we have no guarantees about what was in the memory of the target\n" |
| 7921 |
" process. (The memory may have been modified by another thread, or\n" |
| 7922 |
" even by an external attacking process.) We therefore treat the\n" |
| 7923 |
" buffer returned by pread() as untrusted input. The buffer should\n" |
| 7924 |
" contain a terminating null byte; if not, then we will trigger an\n" |
| 7925 |
" error for the target process. */\n" |
| 7926 |
"\\&\n" |
| 7927 |
" if (strnlen(path, nread) E<lt> nread)\n" |
| 7928 |
" return true;\n" |
| 7929 |
"\\&\n" |
| 7930 |
" return false;\n" |
| 7931 |
"}\n" |
| 7932 |
"\\&\n" |
| 7933 |
"/* Allocate buffers for the seccomp user-space notification request and\n" |
| 7934 |
" response structures. It is the caller\\[aq]s responsibility to free the\n" |
| 7935 |
" buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" |
| 7936 |
"\\&\n" |
| 7937 |
"static void\n" |
| 7938 |
"allocSeccompNotifBuffers(struct seccomp_notif **req,\n" |
| 7939 |
" struct seccomp_notif_resp **resp,\n" |
| 7940 |
" struct seccomp_notif_sizes *sizes)\n" |
| 7941 |
"{\n" |
| 7942 |
" size_t resp_size;\n" |
| 7943 |
"\\&\n" |
| 7944 |
" /* Discover the sizes of the structures that are used to receive\n" |
| 7945 |
" notifications and send notification responses, and allocate\n" |
| 7946 |
" buffers of those sizes. */\n" |
| 7947 |
"\\&\n" |
| 7948 |
" if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" |
| 7949 |
" err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" |
| 7950 |
"\\&\n" |
| 7951 |
" *req = malloc(sizes-E<gt>seccomp_notif);\n" |
| 7952 |
" if (*req == NULL)\n" |
| 7953 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" |
| 7954 |
"\\&\n" |
| 7955 |
" /* When allocating the response buffer, we must allow for the fact\n" |
| 7956 |
" that the user-space binary may have been built with user-space\n" |
| 7957 |
" headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" |
| 7958 |
" response buffer expected by the (older) kernel. Therefore, we\n" |
| 7959 |
" allocate a buffer that is the maximum of the two sizes. This\n" |
| 7960 |
" ensures that if the supervisor places bytes into the response\n" |
| 7961 |
" structure that are past the response size that the kernel expects,\n" |
| 7962 |
" then the supervisor is not touching an invalid memory location. */\n" |
| 7963 |
"\\&\n" |
| 7964 |
" resp_size = sizes-E<gt>seccomp_notif_resp;\n" |
| 7965 |
" if (sizeof(struct seccomp_notif_resp) E<gt> resp_size)\n" |
| 7966 |
" resp_size = sizeof(struct seccomp_notif_resp);\n" |
| 7967 |
"\\&\n" |
| 7968 |
" *resp = malloc(resp_size);\n" |
| 7969 |
" if (*resp == NULL)\n" |
| 7970 |
" err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" |
| 7971 |
"\\&\n" |
| 7972 |
"}\n" |
| 7973 |
"\\&\n" |
| 7974 |
"/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" |
| 7975 |
" descriptor, \\[aq]notifyFd\\[aq]. */\n" |
| 7976 |
"\\&\n" |
| 7977 |
"static void\n" |
| 7978 |
"handleNotifications(int notifyFd)\n" |
| 7979 |
"{\n" |
| 7980 |
" bool pathOK;\n" |
| 7981 |
" char path[PATH_MAX];\n" |
| 7982 |
" struct seccomp_notif *req;\n" |
| 7983 |
" struct seccomp_notif_resp *resp;\n" |
| 7984 |
" struct seccomp_notif_sizes sizes;\n" |
| 7985 |
"\\&\n" |
| 7986 |
" allocSeccompNotifBuffers(&req, &resp, &sizes);\n" |
| 7987 |
"\\&\n" |
| 7988 |
" /* Loop handling notifications */\n" |
| 7989 |
"\\&\n" |
| 7990 |
" for (;;) {\n" |
| 7991 |
"\\&\n" |
| 7992 |
" /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" |
| 7993 |
"\\&\n" |
| 7994 |
" memset(req, 0, sizes.seccomp_notif);\n" |
| 7995 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" |
| 7996 |
" if (errno == EINTR)\n" |
| 7997 |
" continue;\n" |
| 7998 |
" err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" |
| 7999 |
" }\n" |
| 8000 |
"\\&\n" |
| 8001 |
" printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" |
| 8002 |
" req-E<gt>id, req-E<gt>pid);\n" |
| 8003 |
"\\&\n" |
| 8004 |
" /* The only system call that can generate a notification event\n" |
| 8005 |
" is mkdir(2). Nevertheless, we check that the notified system\n" |
| 8006 |
" call is indeed mkdir() as kind of future-proofing of this\n" |
| 8007 |
" code in case the seccomp filter is later modified to\n" |
| 8008 |
" generate notifications for other system calls. */\n" |
| 8009 |
"\\&\n" |
| 8010 |
" if (req-E<gt>data.nr != SYS_mkdir) {\n" |
| 8011 |
" printf(\"\\[rs]tS: notification contained unexpected \"\n" |
| 8012 |
" \"system call number; bye!!!\\[rs]n\");\n" |
| 8013 |
" exit(EXIT_FAILURE);\n" |
| 8014 |
" }\n" |
| 8015 |
"\\&\n" |
| 8016 |
" pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" |
| 8017 |
"\\&\n" |
| 8018 |
" /* Prepopulate some fields of the response */\n" |
| 8019 |
"\\&\n" |
| 8020 |
" resp-E<gt>id = req-E<gt>id; /* Response includes notification ID */\n" |
| 8021 |
" resp-E<gt>flags = 0;\n" |
| 8022 |
" resp-E<gt>val = 0;\n" |
| 8023 |
"\\&\n" |
| 8024 |
" /* If getTargetPathname() failed, trigger an EINVAL error\n" |
| 8025 |
" response (sending this response may yield an error if the\n" |
| 8026 |
" failure occurred because the notification ID was no longer\n" |
| 8027 |
" valid); if the directory is in /tmp, then create it on behalf\n" |
| 8028 |
" of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" |
| 8029 |
" kernel to let the target process execute the mkdir();\n" |
| 8030 |
" otherwise, give an error for a directory pathname in any other\n" |
| 8031 |
" location. */\n" |
| 8032 |
"\\&\n" |
| 8033 |
" if (!pathOK) {\n" |
| 8034 |
" resp-E<gt>error = -EINVAL;\n" |
| 8035 |
" printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" |
| 8036 |
" strerror(-resp-E<gt>error));\n" |
| 8037 |
" } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" |
| 8038 |
" printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" |
| 8039 |
" path, req-E<gt>data.args[1]);\n" |
| 8040 |
"\\&\n" |
| 8041 |
" if (mkdir(path, req-E<gt>data.args[1]) == 0) {\n" |
| 8042 |
" resp-E<gt>error = 0; /* \"Success\" */\n" |
| 8043 |
" resp-E<gt>val = strlen(path); /* Used as return value of\n" |
| 8044 |
" mkdir() in target */\n" |
| 8045 |
" printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" |
| 8046 |
" resp-E<gt>val);\n" |
| 8047 |
" } else {\n" |
| 8048 |
"\\&\n" |
| 8049 |
" /* If mkdir() failed in the supervisor, pass the error\n" |
| 8050 |
" back to the target */\n" |
| 8051 |
"\\&\n" |
| 8052 |
" resp-E<gt>error = -errno;\n" |
| 8053 |
" printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" |
| 8054 |
" strerror(errno));\n" |
| 8055 |
" }\n" |
| 8056 |
" } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" |
| 8057 |
" resp-E<gt>error = resp-E<gt>val = 0;\n" |
| 8058 |
" resp-E<gt>flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" |
| 8059 |
" printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" |
| 8060 |
" } else {\n" |
| 8061 |
" resp-E<gt>error = -EOPNOTSUPP;\n" |
| 8062 |
" printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" |
| 8063 |
" strerror(-resp-E<gt>error));\n" |
| 8064 |
" }\n" |
| 8065 |
"\\&\n" |
| 8066 |
" /* Send a response to the notification */\n" |
| 8067 |
"\\&\n" |
| 8068 |
" printf(\"\\[rs]tS: sending response \"\n" |
| 8069 |
" \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" |
| 8070 |
" resp-E<gt>flags, resp-E<gt>val, resp-E<gt>error);\n" |
| 8071 |
"\\&\n" |
| 8072 |
" if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" |
| 8073 |
" if (errno == ENOENT)\n" |
| 8074 |
" printf(\"\\[rs]tS: response failed with ENOENT; \"\n" |
| 8075 |
" \"perhaps target process\\[aq]s syscall was \"\n" |
| 8076 |
" \"interrupted by a signal?\\[rs]n\");\n" |
| 8077 |
" else\n" |
| 8078 |
" perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" |
| 8079 |
" }\n" |
| 8080 |
"\\&\n" |
| 8081 |
" /* If the pathname is just \"/bye\", then the supervisor breaks out\n" |
| 8082 |
" of the loop and terminates. This allows us to see what happens\n" |
| 8083 |
" if the target process makes further calls to mkdir(2). */\n" |
| 8084 |
"\\&\n" |
| 8085 |
" if (strcmp(path, \"/bye\") == 0)\n" |
| 8086 |
" break;\n" |
| 8087 |
" }\n" |
| 8088 |
"\\&\n" |
| 8089 |
" free(req);\n" |
| 8090 |
" free(resp);\n" |
| 8091 |
" printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" |
| 8092 |
" exit(EXIT_FAILURE);\n" |
| 8093 |
"}\n" |
| 8094 |
"\\&\n" |
| 8095 |
"/* Implementation of the supervisor process:\n" |
| 8096 |
"\\&\n" |
| 8097 |
" (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" |
| 8098 |
" (2) handles notifications that arrive on that file descriptor. */\n" |
| 8099 |
"\\&\n" |
| 8100 |
"static void\n" |
| 8101 |
"supervisor(int sockPair[2])\n" |
| 8102 |
"{\n" |
| 8103 |
" int notifyFd;\n" |
| 8104 |
"\\&\n" |
| 8105 |
" notifyFd = recvfd(sockPair[1]);\n" |
| 8106 |
"\\&\n" |
| 8107 |
" if (notifyFd == -1)\n" |
| 8108 |
" err(EXIT_FAILURE, \"recvfd\");\n" |
| 8109 |
"\\&\n" |
| 8110 |
" closeSocketPair(sockPair); /* We no longer need the socket pair */\n" |
| 8111 |
"\\&\n" |
| 8112 |
" handleNotifications(notifyFd);\n" |
| 8113 |
"}\n" |
| 8114 |
"\\&\n" |
| 8115 |
"int\n" |
| 8116 |
"main(int argc, char *argv[])\n" |
| 8117 |
"{\n" |
| 8118 |
" int sockPair[2];\n" |
| 8119 |
" struct sigaction sa;\n" |
| 8120 |
"\\&\n" |
| 8121 |
" setbuf(stdout, NULL);\n" |
| 8122 |
"\\&\n" |
| 8123 |
" if (argc E<lt> 2) {\n" |
| 8124 |
" fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" |
| 8125 |
" exit(EXIT_FAILURE);\n" |
| 8126 |
" }\n" |
| 8127 |
"\\&\n" |
| 8128 |
" /* Create a UNIX domain socket that is used to pass the seccomp\n" |
| 8129 |
" notification file descriptor from the target process to the\n" |
| 8130 |
" supervisor process. */\n" |
| 8131 |
"\\&\n" |
| 8132 |
" if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" |
| 8133 |
" err(EXIT_FAILURE, \"socketpair\");\n" |
| 8134 |
"\\&\n" |
| 8135 |
" /* Create a child process--the \"target\"--that installs seccomp\n" |
| 8136 |
" filtering. The target process writes the seccomp notification\n" |
| 8137 |
" file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" |
| 8138 |
" each directory in the command-line arguments. */\n" |
| 8139 |
"\\&\n" |
| 8140 |
" (void) targetProcess(sockPair, &argv[optind]);\n" |
| 8141 |
"\\&\n" |
| 8142 |
" /* Catch SIGCHLD when the target terminates, so that the\n" |
| 8143 |
" supervisor can also terminate. */\n" |
| 8144 |
"\\&\n" |
| 8145 |
" sa.sa_handler = sigchldHandler;\n" |
| 8146 |
" sa.sa_flags = 0;\n" |
| 8147 |
" sigemptyset(&sa.sa_mask);\n" |
| 8148 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" |
| 8149 |
" err(EXIT_FAILURE, \"sigaction\");\n" |
| 8150 |
"\\&\n" |
| 8151 |
" supervisor(sockPair);\n" |
| 8152 |
"\\&\n" |
| 8153 |
" exit(EXIT_SUCCESS);\n" |
| 8154 |
"}\n" |
| 8155 |
|
| 8156 |
#. type: TH |
| 8157 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 8158 |
#, no-wrap |
| 8159 |
msgid "Linux man-pages (unreleased)" |
| 8160 |
msgstr "صفحات دليل لينكس (لم تصدر بعد)" |