# Arabic translation of manpages # This file is distributed under the same license as the manpages-l10n package. # Copyright © of this file: # زايد السعيدي , 2026. msgid "" msgstr "" "Project-Id-Version: manpages-l10n 4.30.2\n" "POT-Creation-Date: 2026-06-05 06:42+0200\n" "PO-Revision-Date: 2026-05-17 17:43+0400\n" "Last-Translator: Zayed Al-Saidi \n" "Language-Team: Arabic \n" "Language: ar\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 " "&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" "X-Generator: Lokalize 23.08.5\n" #. type: TH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "seccomp_unotify" msgstr "seccomp_unotify" #. type: TH #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "2026-02-22" msgstr "22 فبراير 2026" #. type: TH #: archlinux debian-unstable #, no-wrap msgid "Linux man-pages 6.18" msgstr "صفحات دليل لينكس 6.18" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "NAME" msgstr "الاسم" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "seccomp_unotify - Seccomp user-space notification mechanism" msgstr "seccomp_unotify - آلية إشعار seccomp في فضاء المستخدم" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "LIBRARY" msgstr "المكتبة" #. type: Plain text #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "Standard C library (I,\\ I<-lc>)" msgstr "مكتبة سي المعيارية (I،\\ I<-lc>)" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SYNOPSIS" msgstr "موجز" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "B<#include Elinux/seccomp.hE>\n" "B<#include Elinux/filter.hE>\n" "B<#include Elinux/audit.hE>\n" msgstr "" "B<#include Elinux/seccomp.hE>\n" "B<#include Elinux/filter.hE>\n" "B<#include Elinux/audit.hE>\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "BIB<, unsigned int >IB<, void *>IB<);>\n" msgstr "BIB<, unsigned int >IB<, void *>IB<);>\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B<#include Esys/ioctl.hE>\n" msgstr "B<#include Esys/ioctl.hE>\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "BIB<, SECCOMP_IOCTL_NOTIF_RECV,>\n" "B< struct seccomp_notif *>IB<);>\n" "BIB<, SECCOMP_IOCTL_NOTIF_SEND,>\n" "B< struct seccomp_notif_resp *>IB<);>\n" "BIB<, SECCOMP_IOCTL_NOTIF_ID_VALID, __u64 *>IB<);>\n" "BIB<, SECCOMP_IOCTL_NOTIF_ADDFD,>\n" "B< struct seccomp_notif_addfd *>IB<);>\n" msgstr "" "BIB<, SECCOMP_IOCTL_NOTIF_RECV,>\n" "B< struct seccomp_notif *>IB<);>\n" "BIB<, SECCOMP_IOCTL_NOTIF_SEND,>\n" "B< struct seccomp_notif_resp *>IB<);>\n" "BIB<, SECCOMP_IOCTL_NOTIF_ID_VALID, __u64 *>IB<);>\n" "BIB<, SECCOMP_IOCTL_NOTIF_ADDFD,>\n" "B< struct seccomp_notif_addfd *>IB<);>\n" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "DESCRIPTION" msgstr "الوصف" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This page describes the user-space notification mechanism provided by the " "Secure Computing (seccomp) facility. As well as the use of the " "B flag, the B " "action value, and the B operation described in " "B(2), this mechanism involves the use of a number of related " "B(2) operations (described below)." msgstr "" "تصف هذه الصفحة آلية إشعار فضاء المستخدم التي توفرها وسيلة الحوسبة الآمنة " "(seccomp). بالإضافة إلى استخدام علامة B، " "وقيمة الإجراء B، وعملية B " "الموصوفة في B(2)، تتضمن هذه الآلية استخدام عدد من عمليات " "B(2) ذات الصلة (الموصوفة أدناه)." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Overview" msgstr "نظرة عامة" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In conventional usage of a seccomp filter, the decision about how to treat a " "system call is made by the filter itself. By contrast, the user-space " "notification mechanism allows the seccomp filter to delegate the handling of " "the system call to another user-space process. Note that this mechanism is " "explicitly B intended as a method implementing security policy; see " "NOTES." msgstr "" "في الاستخدام التقليدي لمرشح seccomp، يُتخذ القرار بشأن كيفية التعامل مع " "استدعاء النظام بواسطة المرشح نفسه. على النقيض من ذلك، تسمح آلية إشعار فضاء " "المستخدم لمرشح seccomp بتفويض معالجة استدعاء النظام إلى عملية أخرى في فضاء " "المستخدم. لاحظ أن هذه الآلية B<ليست> مخصصة صراحةً كطريقة لتنفيذ سياسة أمنية؛ " "انظر الملاحظات (NOTES)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the discussion that follows, the thread(s) on which the seccomp filter is " "installed is (are) referred to as the I, and the process that is " "notified by the user-space notification mechanism is referred to as the " "I." msgstr "" "في المناقشة التي تلي، يُشار إلى الخيط (أو الخيوط) التي ثُبت عليها مرشح seccomp " "باسم I<الهدف> (target)، ويُشار إلى العملية التي تُخطر بواسطة آلية إشعار فضاء " "المستخدم باسم I<المشرف> (supervisor)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A suitably privileged supervisor can use the user-space notification " "mechanism to perform actions on behalf of the target. The advantage of the " "user-space notification mechanism is that the supervisor will usually be " "able to retrieve information about the target and the performed system call " "that the seccomp filter itself cannot. (A seccomp filter is limited in the " "information it can obtain and the actions that it can perform because it is " "running on a virtual machine inside the kernel.)" msgstr "" "يمكن للمشرف الذي يتمتع بامتيازات مناسبة استخدام آلية إشعار فضاء المستخدم " "لتنفيذ إجراءات نيابة عن الهدف. تكمن ميزة آلية إشعار فضاء المستخدم في أن " "المشرف سيكون قادرًا عادةً على استرجاع معلومات حول الهدف واستدعاء النظام المنفذ " "التي لا يستطيع مرشح seccomp نفسه الوصول إليها. (مرشح seccomp محدود في " "المعلومات التي يمكنه الحصول عليها والإجراءات التي يمكنه القيام بها لأنه يعمل " "على جهاز افتراضي داخل النواة.)" #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "An overview of the steps performed by the target and the supervisor is as " "follows:" msgstr "نظرة عامة على الخطوات التي يقوم بها كل من الهدف والمشرف هي كما يلي:" #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(1)" msgstr "(1)" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The target establishes a seccomp filter in the usual manner, but with two " "differences:" msgstr "ينشئ الهدف مرشح seccomp بالطريقة المعتادة، ولكن مع اختلافين:" #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "\\[bu]" msgstr "\\[bu]" # # #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Is the last sentence above correct? #. Kees Cook (25 Oct 2020) notes: #. I like this limitation, but I expect that it'll need to change in the #. future. Even with LSMs, we see the need for arbitrary stacking, and the #. idea of there being only 1 supervisor will eventually break down. Right #. now there is only 1 because only container managers are using this #. feature. But if some daemon starts using it to isolate some thread, #. suddenly it might break if a container manager is trying to listen to it #. too, etc. I expect it won't be needed soon, but I do think it'll change. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B(2) I argument includes the flag " "B. Consequently, the return value of the " "(successful) B(2) call is a new \"listening\" file descriptor " "that can be used to receive notifications. Only one \"listening\" seccomp " "filter can be installed for a thread." msgstr "" "تتضمن وسيطة I في B(2) العلامة " "B. وبناءً على ذلك، تكون القيمة المعادة من " "استدعاء B(2) (الناجح) هي واصف ملف \"استماع\" جديد يمكن استخدامه " "لتلقي الإشعارات. يمكن تثبيت مرشح seccomp \"مستمع\" واحد فقط لكل خيط." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In cases where it is appropriate, the seccomp filter returns the action " "value B. This return value will trigger a " "notification event." msgstr "" "في الحالات المناسبة، يعيد مرشح seccomp قيمة الإجراء " "B. ستؤدي هذه القيمة المعادة إلى إطلاق حدث إشعار." #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(2)" msgstr "(2)" #. Jann Horn: #. Instead of using unix domain sockets to send the fd to the #. parent, I think you could also use clone3() with #. flags==CLONE_FILES|SIGCHLD, dup2() the seccomp fd to an fd #. that was reserved in the parent, call unshare(CLONE_FILES) #. in the child after setting up the seccomp fd, and wake #. up the parent with something like pthread_cond_signal()? #. I'm not sure whether that'd look better or worse in the #. end though, so maybe just ignore this comment. #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In order that the supervisor can obtain notifications using the listening " "file descriptor, (a duplicate of) that file descriptor must be passed from " "the target to the supervisor. One way in which this could be done is by " "passing the file descriptor over a UNIX domain socket connection between the " "target and the supervisor (using the B ancillary message type " "described in B(7)). Another way to do this is through the use of " "B(2)." msgstr "" "لكي يتمكن المشرف من الحصول على الإشعارات باستخدام واصف ملف الاستماع، يجب " "تمرير (نسخة من) واصف الملف هذا من الهدف إلى المشرف. إحدى الطرق التي يمكن من " "خلالها القيام بذلك هي تمرير واصف الملف عبر اتصال مقبس نطاق يونكس بين الهدف " "والمشرف (باستخدام نوع الرسالة الملحقة B الموصوفة في B(7)). " "طريقة أخرى للقيام بذلك هي من خلال استخدام B(2)." #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(3)" msgstr "(3)" #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The supervisor will receive notification events on the listening file " "descriptor. These events are returned as structures of type " "I. Because this structure and its size may evolve over " "kernel versions, the supervisor must first determine the size of this " "structure using the B(2) B operation, " "which returns a structure of type I. The supervisor " "allocates a buffer of size I bytes to " "receive notification events. In addition,the supervisor allocates another " "buffer of size I bytes for the " "response (a I structure) that it will provide to " "the kernel (and thus the target)." msgstr "" "سيتلقى المشرف أحداث الإشعار على واصف ملف الاستماع. تُعاد هذه الأحداث في هيئة " "هياكل من نوع I. ولأن هذا الهيكل وحجمه قد يتطوران عبر إصدارات " "النواة، يجب على المشرف أولاً تحديد حجم هذا الهيكل باستخدام عملية " "B في B(2)، والتي تعيد هيكلًا من نوع " "I. يخصص المشرف مخزنًا مؤقتًا بحجم I بايت لتلقي أحداث الإشعارات. بالإضافة إلى ذلك، يخصص المشرف " "مخزنًا مؤقتًا آخر بحجم I بايت " "للاستجابة (هيكل I) التي سيقدمها للنواة (وبالتالي " "للهدف)." #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(4)" msgstr "(4)" #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The target then performs its workload, which includes system calls that will " "be controlled by the seccomp filter. Whenever one of these system calls " "causes the filter to return the B action value, the " "kernel does I (yet) execute the system call; instead, execution of the " "target is temporarily blocked inside the kernel (in a sleep state that is " "interruptible by signals) and a notification event is generated on the " "listening file descriptor." msgstr "" "ثم ينفذ الهدف عبء عمله، والذي يتضمن استدعاءات النظام التي سيتحكم فيها مرشح " "seccomp. كلما تسبب أحد استدعاءات النظام هذه في إعادة المرشح لقيمة الإجراء " "B، فإن النواة I<لا> تنفذ (بعد) استدعاء النظام؛ وبدلاً " "من ذلك، يُحجب تنفيذ الهدف مؤقتًا داخل النواة (في حالة نوم قابلة للمقاطعة " "بواسطة الإشارات) ويُولد حدث إشعار على واصف ملف الاستماع." #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(5)" msgstr "(5)" # # # #. FIXME #. Christian Brauner: #. Do we support O_NONBLOCK with SECCOMP_IOCTL_NOTIF_RECV and if #. not should we? #. Michael Kerrisk: #. A quick test suggests that O_NONBLOCK has no effect on the blocking #. behavior of SECCOMP_IOCTL_NOTIF_RECV. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The supervisor can now repeatedly monitor the listening file descriptor for " "B-triggered events. To do this, the supervisor uses " "the B B(2) operation to read information " "about a notification event; this operation blocks until an event is " "available. The operation returns a I structure containing " "information about the system call that is being attempted by the target. " "(As described in NOTES, the file descriptor can also be monitored with " "B(2) أو " "B(2) أو B(7).)" #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(6)" msgstr "(6)" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The I structure returned by the B " "operation includes the same information (a I structure) that " "was passed to the seccomp filter. This information allows the supervisor to " "discover the system call number and the arguments for the target's system " "call. In addition, the notification event contains the ID of the thread " "that triggered the notification and a unique cookie value that is used in " "subsequent B and B " "operations." msgstr "" "يتضمن هيكل I الذي تعيده عملية B نفس " "المعلومات (هيكل I) التي مُررت إلى مرشح seccomp. تسمح هذه " "المعلومات للمشرف باكتشاف رقم استدعاء النظام ووسائط استدعاء نظام الهدف. " "بالإضافة إلى ذلك، يحتوي حدث الإشعار على معرف الخيط الذي أطلق الإشعار وقيمة " "\"كعكة\" (cookie) فريدة تُستخدم في عمليتي B و " "B اللاحقتين." #. Tycho Andersen mentioned that there are alternatives to /proc/PID/mem, #. such as ptrace() and /proc/PID/map_files #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The information in the notification can be used to discover the values of " "pointer arguments for the target's system call. (This is something that " "can't be done from within a seccomp filter.) One way in which the " "supervisor can do this is to open the corresponding ItidI file " "(see B(5)) and read bytes from the location that corresponds to one " "of the pointer arguments whose value is supplied in the notification event. " "(The supervisor must be careful to avoid a race condition that can occur " "when doing this; see the description of the B " "B(2) operation below.) In addition, the supervisor can access other " "system information that is visible in user space but which is not accessible " "from a seccomp filter." msgstr "" "يمكن استخدام المعلومات الواردة في الإشعار لاكتشاف قيم وسائط المؤشر لاستدعاء " "نظام الهدف. (هذا شيء لا يمكن القيام به من داخل مرشح seccomp.) إحدى الطرق " "التي يمكن للمشرف من خلالها القيام بذلك هي فتح ملف ItidI " "المقابل (انظر B(5)) وقراءة البايتات من الموقع الذي يقابل أحد وسائط " "المؤشر التي زُودت قيمتها في حدث الإشعار. (يجب على المشرف توخي الحذر لتجنب " "حالة التسابق التي يمكن أن تحدث عند القيام بذلك؛ انظر وصف عملية " "B في B(2) أدناه.) بالإضافة إلى ذلك، " "يمكن للمشرف الوصول إلى معلومات النظام الأخرى التي تظهر في فضاء المستخدم ولكن " "لا يمكن الوصول إليها من مرشح seccomp." #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(7)" msgstr "(7)" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Having obtained information as per the previous step, the supervisor may " "then choose to perform an action in response to the target's system call " "(which, as noted above, is not executed when the seccomp filter returns the " "B action value)." msgstr "" "بعد الحصول على المعلومات كما في الخطوة السابقة، قد يختار المشرف بعد ذلك " "تنفيذ إجراء استجابةً لاستدعاء نظام الهدف (والذي، كما لوحظ أعلاه، لا يُنفذ " "عندما يعيد مرشح seccomp قيمة الإجراء B)." #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "One example use case here relates to containers. The target may be located " "inside a container where it does not have sufficient capabilities to mount a " "filesystem in the container's mount namespace. However, the supervisor may " "be a more privileged process that does have sufficient capabilities to " "perform the mount operation." msgstr "" "أحد أمثلة حالات الاستخدام هنا يتعلق بالحاويات. قد يكون الهدف موجودًا داخل " "حاوية حيث لا يملك قدرات كافية لوصل نظام ملفات في مساحة اسم الوصل الخاصة " "بالحاوية. ومع ذلك، قد يكون المشرف عملية ذات امتيازات أعلى تملك القدرات " "الكافية لتنفيذ عملية الوصل." #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(8)" msgstr "(8)" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The supervisor then sends a response to the notification. The information " "in this response is used by the kernel to construct a return value for the " "target's system call and provide a value that will be assigned to the " "I variable of the target." msgstr "" "يرسل المشرف بعد ذلك استجابة للإشعار. تستخدم النواة المعلومات الواردة في هذه " "الاستجابة لبناء قيمة معادة لاستدعاء نظام الهدف وتوفير قيمة ستُسند إلى متغير " "I الخاص بالهدف." #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The response is sent using the B B(2) " "operation, which is used to transmit a I structure to " "the kernel. This structure includes a cookie value that the supervisor " "obtained in the I structure returned by the " "B operation. This cookie value allows the kernel " "to associate the response with the target. This structure must include the " "cookie value that the supervisor obtained in the I structure " "returned by the B operation; the cookie allows the " "kernel to associate the response with the target." msgstr "" "تُرسل الاستجابة باستخدام عملية B في B(2)، " "والتي تُستخدم لنقل هيكل I إلى النواة. يتضمن هذا الهيكل " "قيمة الكعكة التي حصل عليها المشرف في هيكل I الذي أعادته عملية " "B. تسمح قيمة الكعكة هذه للنواة بربط الاستجابة " "بالهدف. يجب أن يتضمن هذا الهيكل قيمة الكعكة التي حصل عليها المشرف في هيكل " "I الذي أعادته عملية B؛ تسمح الكعكة " "للنواة بربط الاستجابة بالهدف." #. type: IP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "(9)" msgstr "(9)" #. ------------------------------------- #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Once the notification has been sent, the system call in the target thread " "unblocks, returning the information that was provided by the supervisor in " "the notification response." msgstr "" "بمجرد إرسال الإشعار، يُلغى حجب استدعاء النظام في خيط الهدف، ويعيد المعلومات " "التي قدمها المشرف في استجابة الإشعار." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "As a variation on the last two steps, the supervisor can send a response " "that tells the kernel that it should execute the target thread's system " "call; see the discussion of B, below." msgstr "" "كبديل للخطوتين الأخيرتين، يمكن للمشرف إرسال استجابة تخبر النواة بوجوب تنفيذ " "استدعاء نظام خيط الهدف؛ انظر مناقشة B " "أدناه." #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "IOCTL OPERATIONS" msgstr "عمليات IOCTL" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The following B(2) operations are supported by the seccomp user-" "space notification file descriptor. For each of these operations, the first " "(file descriptor) argument of B(2) is the listening file descriptor " "returned by a call to B(2) with the " "B flag." msgstr "" "عمليات B(2) التالية مدعومة من قبل واصف ملف إشعار فضاء مستخدم seccomp. " "لكل من هذه العمليات، تكون الوسيطة الأولى (واصف الملف) لـ B(2) هي واصف " "ملف الاستماع الذي أعاده استدعاء B(2) مع علامة " "B." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SECCOMP_IOCTL_NOTIF_RECV" msgstr "SECCOMP_IOCTL_NOTIF_RECV" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B operation (available since Linux 5.0) is " "used to obtain a user-space notification event. If no such event is " "currently pending, the operation blocks until an event occurs. The third " "B(2) argument is a pointer to a structure of the following form " "which contains information about the event. This structure must be zeroed " "out before the call." msgstr "" "تُستخدم عملية B (متوفرة منذ لينكس 5.0) للحصول على " "حدث إشعار في فضاء المستخدم. إذا لم يكن هناك مثل هذا الحدث معلقًا حاليًا، تُحجب " "العملية حتى يقع حدث. الوسيطة الثالثة لـ B(2) هي مؤشر لهيكل بالشكل " "التالي يحتوي على معلومات حول الحدث. يجب تصفير هذا الهيكل قبل الاستدعاء." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "struct seccomp_notif {\n" " __u64 id; /* Cookie */\n" " __u32 pid; /* TID of target thread */\n" " __u32 flags; /* Currently unused (0) */\n" " struct seccomp_data data; /* See seccomp(2) */\n" "};\n" msgstr "" "struct seccomp_notif {\n" " __u64 id; /* كعكة */\n" " __u32 pid; /* TID لخيط الهدف */\n" " __u32 flags; /* غير مستخدم حاليا (0) */\n" " struct seccomp_data data; /* انظر seccomp(2) */\n" "};\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "The fields in this structure are as follows:" msgstr "الحقول في هذا الهيكل هي كما يلي:" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is a cookie for the notification. Each such cookie is guaranteed to be " "unique for the corresponding seccomp filter." msgstr "" "هذه هي كعكة للإشعار. يُضمن أن تكون كل كعكة من هذا القبيل فريدة لمرشح seccomp " "المقابل." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The cookie can be used with the B B(2) " "operation described below." msgstr "" "يمكن استخدام الكعكة مع عملية B في B(2) " "الموصوفة أدناه." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "When returning a notification response to the kernel, the supervisor must " "include the cookie value in the I structure that is " "specified as the argument of the B operation." msgstr "" "عند إرجاع استجابة إشعار إلى النواة، يجب على المشرف تضمين قيمة الكعكة في هيكل " "I المحدد كوسيطة لعملية B." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is the thread ID of the target thread that triggered the notification " "event." msgstr "هذا هو معرف الخيط لخيط الهدف الذي أطلق حدث الإشعار." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is a bit mask of flags providing further information on the event. In " "the current implementation, this field is always zero." msgstr "" "هذا قناع بتات للعلامات التي توفر معلومات إضافية حول الحدث. في التنفيذ " "الحالي، هذا الحقل دائمًا صفر." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is a I structure containing information about the system " "call that triggered the notification. This is the same structure that is " "passed to the seccomp filter. See B(2) for details of this " "structure." msgstr "" "هذا هيكل I يحتوي على معلومات حول استدعاء النظام الذي أطلق " "الإشعار. هذا هو نفس الهيكل الذي يُمرر إلى مرشح seccomp. انظر B(2) " "للحصول على تفاصيل حول هذا الهيكل." #. type: Plain text #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "" "On success, this operation returns 0; on failure, -1 is returned, and " "I is set to indicate the error. This operation can fail with the " "following errors:" msgstr "" "عند النجاح، تعيد هذه العملية 0؛ وعند الفشل، تُعاد -1، ويُضبط I للإشارة " "إلى الخطأ. يمكن أن تفشل هذه العملية بالأخطاء التالية:" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B (since Linux 5.5)" msgstr "B (منذ لينكس 5.5)" #. commit 2882d53c9c6f3b8311d225062522f03772cf0179 #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The I structure that was passed to the call contained nonzero " "fields." msgstr "هيكل I الذي مُرر إلى الاستدعاء احتوى على حقول غير صفرية." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" # # # # # #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. From my experiments, #. it appears that if a SECCOMP_IOCTL_NOTIF_RECV is done after #. the target thread terminates, then the ioctl() simply #. blocks (rather than returning an error to indicate that the #. target no longer exists). #. I found that surprising, and it required some contortions in #. the example program. It was not possible to code my SIGCHLD #. handler (which reaps the zombie when the worker/target #. terminates) to simply set a flag checked in the main #. handleNotifications() loop, since this created an #. unavoidable race where the child might terminate just after #. I had checked the flag, but before I blocked (forever!) in the #. SECCOMP_IOCTL_NOTIF_RECV operation. Instead, I had to code #. the signal handler to simply call _exit(2) in order to #. terminate the parent process (the supervisor). #. Is this expected behavior? It seems to me rather #. desirable that SECCOMP_IOCTL_NOTIF_RECV should give an error #. if the target has terminated. #. Jann posted a patch to rectify this, but there was no response #. (Lore link: https://bit.ly/3jvUBxk) to his question about fixing #. this issue. (I've tried building with the patch, but encountered #. an issue with the target process entering D state after a signal.) #. For now, this behavior is documented in BUGS. #. Kees Cook commented: Let's change [this] ASAP! #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The target thread was killed by a signal as the notification information was " "being generated, or the target's (blocked) system call was interrupted by a " "signal handler." msgstr "" "قُتل خيط الهدف بواسطة إشارة أثناء إنشاء معلومات الإشعار، أو قوطع استدعاء نظام " "الهدف (المحجوب) بواسطة معالج إشارة." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SECCOMP_IOCTL_NOTIF_ID_VALID" msgstr "SECCOMP_IOCTL_NOTIF_ID_VALID" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B operation (available since Linux 5.0) is " "used to check that a notification ID returned by an earlier " "B operation is still valid (i.e., that the target " "still exists and its system call is still blocked waiting for a response)." msgstr "" "تُستخدم عملية B (متوفرة منذ لينكس 5.0) للتحقق " "من أن معرف الإشعار الذي أعادته عملية B سابقة لا " "يزال صالحًا (أي أن الهدف لا يزال موجودًا واستدعاء نظامه لا يزال محجوبًا في " "انتظار استجابة)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The third B(2) argument is a pointer to the cookie (I) returned " "by the B operation." msgstr "" "الوسيطة الثالثة لـ B(2) هي مؤشر للكعكة (I) التي أعادتها عملية " "B." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This operation is necessary to avoid race conditions that can occur when the " "I returned by the B operation terminates, and " "that process ID is reused by another process. An example of this kind of " "race is the following" msgstr "" "هذه العملية ضرورية لتجنب حالات التسابق التي يمكن أن تحدث عندما ينتهي الـ " "I الذي أعادته عملية B، ويُعاد استخدام معرف " "العملية هذا بواسطة عملية أخرى. مثال على هذا النوع من التسابق هو ما يلي" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A notification is generated on the listening file descriptor. The returned " "I contains the TID of the target thread (in the I field " "of the structure)." msgstr "" "يُنشأ إشعار على واصف ملف الاستماع. يحتوي هيكل I المُرجع على " "معرف الخيط (TID) للخيط الهدف (في حقل I الخاص بالهيكل)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "The target terminates." msgstr "ينتهي الهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Another thread or process is created on the system that by chance reuses the " "TID that was freed when the target terminated." msgstr "" "يُنشأ خيط أو عملية أخرى على النظام تُعيد استخدام TID الذي حُرّر عند انتهاء الهدف " "عن طريق المصادفة." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The supervisor B(2)s the ItidI file for the TID obtained " "in step 1, with the intention of (say) inspecting the memory location(s) " "that containing the argument(s) of the system call that triggered the " "notification in step 1." msgstr "" "يفتح المشرف عبر B(2) ملف ItidI لـ TID الذي حُصل عليه في " "الخطوة 1، بقصد فحص مواقع الذاكرة التي تحتوي على وسيط (أو وسائط) استدعاء " "النظام الذي أطلق الإشعار في الخطوة 1." #. Jann Horn: #. the PID can be reused, but the /proc/$pid directory is #. internally not associated with the numeric PID, but, #. conceptually speaking, with a specific incarnation of the #. PID, or something like that. (Actually, it is associated #. with the "struct pid", which is not reused, instead of the #. numeric PID. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the above scenario, the risk is that the supervisor may try to access the " "memory of a process other than the target. This race can be avoided by " "following the call to B(2) with a B " "operation to verify that the process that generated the notification is " "still alive. (Note that if the target terminates after the latter step, a " "subsequent B(2) from the file descriptor may return 0, indicating end " "of file.)" msgstr "" "في السيناريو أعلاه، يكمن الخطر في أن المشرف قد يحاول الوصول إلى ذاكرة عملية " "أخرى غير الهدف. يمكن تجنب حالة السباق هذه بإتباع استدعاء B(2) بعملية " "B للتحقق من أن العملية التي أنشأت الإشعار لا " "تزال حية. (لاحظ أنه إذا انتهى الهدف بعد الخطوة الأخيرة، فإن أي B(2) " "لاحقة من واصف الملف قد تُرجع 0، مما يشير إلى نهاية الملف)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "See NOTES for a discussion of other cases where " "B checks must be performed." msgstr "" "انظر الملاحظات لمناقشة الحالات الأخرى التي يجب فيها إجراء فحوصات " "B." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "On success (i.e., the notification ID is still valid), this operation " "returns 0. On failure (i.e., the notification ID is no longer valid), -1 is " "returned, and I is set to B." msgstr "" "عند النجاح (أي أن معرف الإشعار لا يزال صالحاً)، تُرجع هذه العملية 0. وعند " "الفشل (أي أن معرف الإشعار لم يعد صالحاً)، يُرجع -1، ويُضبط I على " "B." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SECCOMP_IOCTL_NOTIF_SEND" msgstr "SECCOMP_IOCTL_NOTIF_SEND" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B operation (available since Linux 5.0) is " "used to send a notification response back to the kernel. The third " "B(2) argument of this structure is a pointer to a structure of the " "following form:" msgstr "" "تُستخدم عملية B (المتوفرة منذ لينكس 5.0) لإرسال رد " "إشعار إلى النواة. وسيط B(2) الثالث لهذا الهيكل هو مؤشر إلى هيكل " "بالشكل التالي:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "struct seccomp_notif_resp {\n" " __u64 id; /* Cookie value */\n" " __s64 val; /* Success return value */\n" " __s32 error; /* 0 (success) or negative error number */\n" " __u32 flags; /* See below */\n" "};\n" msgstr "" "struct seccomp_notif_resp {\n" " __u64 id; /* قيمة الكوكيز */\n" " __s64 val; /* قيمة النجاح المرجعة */\n" " __s32 error; /* 0 (نجاح) أو رقم خطأ سالب */\n" " __u32 flags; /* انظر أدناه */\n" "};\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "The fields of this structure are as follows:" msgstr "حقول هذا الهيكل هي كالتالي:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is the cookie value that was obtained using the " "B operation. This cookie value allows the kernel " "to correctly associate this response with the system call that triggered the " "user-space notification." msgstr "" "هذه هي قيمة الكوكيز التي حُصل عليها باستخدام عملية " "B. تسمح قيمة الكوكيز هذه للنواة بربط هذا الرد بشكل " "صحيح مع استدعاء النظام الذي أطلق إشعار مساحة المستخدم." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is the value that will be used for a spoofed success return for the " "target's system call; see below." msgstr "" "هذه هي القيمة التي ستُستخدم لرد نجاح زائف لاستدعاء نظام الهدف؛ انظر أدناه." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This is the value that will be used as the error number (I) for a " "spoofed error return for the target's system call; see below." msgstr "" "هذه هي القيمة التي ستُستخدم كرقم خطأ (I) لرد خطأ زائف لاستدعاء نظام " "الهدف؛ انظر أدناه." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "This is a bit mask that includes zero or more of the following flags:" msgstr "هذا قناع بتات يتضمن صفراً أو أكثر من اللصائق التالية:" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B (since Linux 5.5)" msgstr "B (منذ لينكس 5.5)" #. commit fb3c5386b382d4097476ce9647260fc89b34afdb #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "Tell the kernel to execute the target's system call." msgstr "إخبار النواة بتنفيذ استدعاء نظام الهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "Two kinds of response are possible:" msgstr "يوجد نوعان ممكنان من الردود:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A response to the kernel telling it to execute the target's system call. In " "this case, the I field includes B " "and the I and I fields must be zero." msgstr "" "رد للنواة يخبرها بتنفيذ استدعاء نظام الهدف. في هذه الحالة، يتضمن حقل " "I العلامة B ويجب أن يكون الحقلان " "I و I صفرين." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This kind of response can be useful in cases where the supervisor needs to " "do deeper analysis of the target's system call than is possible from a " "seccomp filter (e.g., examining the values of pointer arguments), and, " "having decided that the system call does not require emulation by the " "supervisor, the supervisor wants the system call to be executed normally in " "the target." msgstr "" "هذا النوع من الردود يكون مفيداً في الحالات التي يحتاج فيها المشرف إلى إجراء " "تحليل أعمق لاستدعاء نظام الهدف مما هو ممكن من مرشح seccomp (مثل فحص قيم " "وسائط المؤشرات)، وبعد أن يقرر المشرف أن استدعاء النظام لا يتطلب محاكاة، يريد " "المشرف تنفيذ استدعاء النظام بشكل طبيعي في الهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B flag should be used with caution; " "see NOTES." msgstr "" "يجب استخدام وسم B بحذر؛ انظر الملاحظات." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A spoofed return value for the target's system call. In this case, the " "kernel does not execute the target's system call, instead causing the system " "call to return a spoofed value as specified by fields of the " "I structure. The supervisor should set the fields of " "this structure as follows:" msgstr "" "قيمة مرجعة زائفة لاستدعاء نظام الهدف. في هذه الحالة، لا تنفذ النواة استدعاء " "نظام الهدف، وبدلاً من ذلك تجعل استدعاء النظام يُرجع قيمة زائفة كما هو محدد في " "حقول هيكل I. يجب على المشرف ضبط حقول هذا الهيكل كما يلي:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "I does not contain B." msgstr "لا يحتوي I على B." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "I is set either to 0 for a spoofed \"success\" return or to a " "negative error number for a spoofed \"failure\" return. In the former case, " "the kernel causes the target's system call to return the value specified in " "the I field. In the latter case, the kernel causes the target's system " "call to return -1, and I is assigned the negated I value." msgstr "" "يُضبط I إما على 0 لرد \"نجاح\" زائف أو على رقم خطأ سالب لرد \"فشل\" " "زائف. في الحالة الأولى، تجعل النواة استدعاء نظام الهدف يُرجع القيمة المحددة " "في حقل I. وفي الحالة الثانية، تجعل النواة استدعاء نظام الهدف يُرجع -1، " "ويُسند إلى I قيمة I المنفية." # # # #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. Kees Cook suggested: #. Strictly speaking, this is architecture specific, but #. all architectures do it this way. Should seccomp enforce #. val == 0 when err != 0 ? #. Christian Brauner #. Feels like it should, at least for the SEND ioctl where we already #. verify that val and err are both 0 when CONTINUE is specified (as you #. pointed out correctly above). #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "I is set to a value that will be used as the return value for a spoofed " "\"success\" return for the target's system call. The value in this field is " "ignored if the I field contains a nonzero value." msgstr "" "يُضبط I على قيمة ستُستخدم كقيمة مرجعة لرد \"نجاح\" زائف لاستدعاء نظام " "الهدف. تُتجاهل القيمة في هذا الحقل إذا احتوى حقل I على قيمة غير صفرية." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "A response to this notification has already been sent." msgstr "أُرسل رد على هذا الإشعار بالفعل." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "An invalid value was specified in the I" msgstr "حُددت قيمة غير صالحة في حقل I." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The I field contained B, and the " "I or I field was not zero." msgstr "" "احتوى حقل I على B، ولم يكن حقل " "I أو I صفراً." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The blocked system call in the target has been interrupted by a signal " "handler or the target has terminated." msgstr "" "قوطع استدعاء النظام المحجوب في الهدف بواسطة معالج إشارة أو أن الهدف قد انتهى." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SECCOMP_IOCTL_NOTIF_ADDFD" msgstr "SECCOMP_IOCTL_NOTIF_ADDFD" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B operation (available since Linux 5.9) " "allows the supervisor to install a file descriptor into the target's file " "descriptor table. Much like the use of B messages described in " "B(7), this operation is semantically equivalent to duplicating a file " "descriptor from the supervisor's file descriptor table into the target's " "file descriptor table." msgstr "" "تسمح عملية B (المتوفرة منذ لينكس 5.9) للمشرف " "بتثبيت واصف ملف في جدول واصفات ملفات الهدف. تشبه هذه العملية إلى حد كبير " "استخدام رسائل B الموصوفة في B(7)، وهي مكافئة دلالياً لنسخ " "واصف ملف من جدول واصفات ملفات المشرف إلى جدول واصفات ملفات الهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B operation permits the supervisor to emulate " "a target system call (such as B(2) or B(2)) that generates " "a file descriptor. The supervisor can perform the system call that " "generates the file descriptor (and associated open file description) and " "then use this operation to allocate a file descriptor that refers to the " "same open file description in the target. (For an explanation of open file " "descriptions, see B(2).)" msgstr "" "تسمح عملية B للمشرف بمحاكاة استدعاء نظام للهدف " "(مثل B(2) أو B(2)) الذي يُولد واصف ملف. يمكن للمشرف تنفيذ " "استدعاء النظام الذي يُولد واصف الملف (ووصف الملف المفتوح المرتبط به) ثم " "استخدام هذه العملية لتخصيص واصف ملف يشير إلى نفس وصف الملف المفتوح في الهدف. " "(لشرح أوصاف الملفات المفتوحة، انظر B(2))." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Once this operation has been performed, the supervisor can close its copy of " "the file descriptor." msgstr "بمجرد تنفيذ هذه العملية، يمكن للمشرف إغلاق نسخته من واصف الملف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the target, the received file descriptor is subject to the same Linux " "Security Module (LSM) checks as are applied to a file descriptor that is " "received in an B ancillary message. If the file descriptor " "refers to a socket, it inherits the cgroup version 1 network controller " "settings (I and I) of the target." msgstr "" "في الهدف، يخضع واصف الملف المستلم لنفس فحوصات وحدة أمن لينكس (LSM) التي تُطبق " "على واصف ملف مستلم في رسالة B إضافية. إذا كان واصف الملف يشير " "إلى مقبس، فإنه يرث إعدادات متحكم الشبكة للمجموعة التقسيمية (cgroup) الإصدار " "1 (I و I) الخاصة بالهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The third B(2) argument is a pointer to a structure of the following " "form:" msgstr "وسيط B(2) الثالث هو مؤشر إلى هيكل بالشكل التالي:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "struct seccomp_notif_addfd {\n" " __u64 id; /* Cookie value */\n" " __u32 flags; /* Flags */\n" " __u32 srcfd; /* Local file descriptor number */\n" " __u32 newfd; /* 0 or desired file descriptor\n" " number in target */\n" " __u32 newfd_flags; /* Flags to set on target file\n" " descriptor */\n" "};\n" msgstr "" "struct seccomp_notif_addfd {\n" " __u64 id; /* قيمة الكوكيز */\n" " __u32 flags; /* اللصائق */\n" " __u32 srcfd; /* رقم واصف الملف المحلي */\n" " __u32 newfd; /* 0 أو رقم واصف الملف المطلوب\n" " في الهدف */\n" " __u32 newfd_flags; /* اللصائق المراد ضبطها على واصف ملف\n" " الهدف */\n" "};\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This field should be set to the notification ID (cookie value) that was " "obtained via B." msgstr "" "يجب ضبط هذا الحقل على معرف الإشعار (قيمة الكوكيز) التي حُصل عليها عبر " "B." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This field is a bit mask of flags that modify the behavior of the " "operation. Currently, only one flag is supported:" msgstr "" "هذا الحقل عبارة عن قناع بتات من اللصائق التي تعدل سلوك العملية. حالياً، تُدعم " "لصيقة واحدة فقط:" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "When allocating the file descriptor in the target, use the file descriptor " "number specified in the I field." msgstr "" "عند تخصيص واصف الملف في الهدف، استخدم رقم واصف الملف المحدد في حقل I." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B (since Linux 5.14)" msgstr "B (منذ لينكس 5.14)" #. commit 0ae71c7720e3ae3aabd2e8a072d27f7bd173d25c #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Perform the equivalent of B plus " "B as an atomic operation. On successful " "invocation, the target process's I will be 0 and the return value " "will be the file descriptor number that was allocated in the target. If " "allocating the file descriptor in the target fails, the target's system call " "continues to be blocked until a successful response is sent." msgstr "" "تنفيذ ما يعادل B بالإضافة إلى " "B كعملية ذرية. عند الاستدعاء الناجح، سيكون " "I لعملية الهدف 0 وستكون القيمة المرجعة هي رقم واصف الملف الذي خُصص في " "الهدف. إذا فشل تخصيص واصف الملف في الهدف، يستمر حجب استدعاء نظام الهدف حتى " "يُرسل رد ناجح." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This field should be set to the number of the file descriptor in the " "supervisor that is to be duplicated." msgstr "يجب ضبط هذا الحقل على رقم واصف الملف في المشرف المراد نسخه." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This field determines which file descriptor number is allocated in the " "target. If the B flag is set, then this field " "specifies which file descriptor number should be allocated. If this file " "descriptor number is already open in the target, it is atomically closed and " "reused. If the descriptor duplication fails due to an LSM check, or if " "I is not a valid file descriptor, the file descriptor I will " "not be closed in the target process." msgstr "" "يحدد هذا الحقل رقم واصف الملف الذي يُخصص في الهدف. إذا ضُبطت الوسم " "B، فإن هذا الحقل يحدد رقم واصف الملف الذي يجب " "تخصيصه. إذا كان رقم واصف الملف هذا مفتوحاً بالفعل في الهدف، فسيُغلق ويُعاد " "استخدامه ذرياً. إذا فشل نسخ الواصف بسبب فحص LSM، أو إذا لم يكن I واصف " "ملف صالحاً، فلن يُغلق واصف الملف I في عملية الهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the B flag it not set, then this field must be " "0, and the kernel allocates the lowest unused file descriptor number in the " "target." msgstr "" "إذا لم تُضبط الوسم B، فيجب أن يكون هذا الحقل 0، " "وتقوم النواة بتخصيص أقل رقم واصف ملف غير مستخدم في الهدف." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "I" msgstr "I" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This field is a bit mask specifying flags that should be set on the file " "descriptor that is received in the target process. Currently, only the " "following flag is implemented:" msgstr "" "هذا الحقل عبارة عن قناع بتات يحدد اللصائق التي يجب ضبطها على واصف الملف " "المستلم في عملية الهدف. حالياً، تُنفذ اللصيقة التالية فقط:" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "Set the close-on-exec flag on the received file descriptor." msgstr "ضبط وسم الغلق عند التنفيذ على واصف الملف المستلم." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "On success, this B(2) call returns the number of the file descriptor " "that was allocated in the target. Assuming that the emulated system call is " "one that returns a file descriptor as its function result (e.g., " "B(2)), this value can be used as the return value (I) " "that is supplied in the response that is subsequently sent with the " "B operation." msgstr "" "عند النجاح، يُرجع استدعاء B(2) هذا رقم واصف الملف الذي خُصص في الهدف. " "بافتراض أن استدعاء النظام الذي تمت محاكاته هو استدعاء يُرجع واصف ملف كتيجة " "لدالته (مثل B(2))، يمكن استخدام هذه القيمة كقيمة مرجعة (I) " "التي تُوفر في الرد الذي يُرسل لاحقًا بعملية B." #. type: Plain text #: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron #: opensuse-leap-16-1 opensuse-tumbleweed msgid "On error, -1 is returned and I is set to indicate the error." msgstr "عند حدوث خطأ، يُرجع -1 ويُضبط I للإشارة إلى الخطأ." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "This operation can fail with the following errors:" msgstr "يمكن أن تفشل هذه العملية بالأخطاء التالية:" #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Allocating the file descriptor in the target would cause the target's " "B limit to be exceeded (see B(2))." msgstr "" "سيؤدي تخصيص واصف الملف في الهدف إلى تجاوز حد B للهدف (انظر " "B(2))." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the flag B is used, this means the operation " "can't proceed until other B requests are " "processed." msgstr "" "إذا استُخدمت اللصيقة B، فهذا يعني أن العملية لا " "يمكن أن تستمر حتى تُعالج طلبات B الأخرى." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The user-space notification specified in the I field exists but has not " "yet been fetched (by a B) or has already been " "responded to (by a B)." msgstr "" "إشعار مساحة المستخدم المحدد في حقل I موجود ولكنه لم يُجلب بعد (بواسطة " "B) أو تم الرد عليه بالفعل (بواسطة " "B)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "An invalid flag was specified in the I or I field, or " "the I field is nonzero and the B flag was " "not specified in the I field." msgstr "" "حُددت لصيقة غير صالحة في حقل I أو I، أو أن حقل I " "غير صفري ولم تُحدد اللصيقة B في حقل I." #. type: TP #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "B" msgstr "B" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The file descriptor number specified in I exceeds the limit specified " "in I." msgstr "" "يتجاوز رقم واصف الملف المحدد في I الحد المحدد في I." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Here is some sample code (with error handling omitted) that uses the " "B operation (here, to emulate a call to " "B(2)):" msgstr "" "إليك بعض التعليمات البرمجية النموذجية (مع حذف معالجة الأخطاء) التي تستخدم " "عملية B (هنا، لمحاكاة استدعاء لـ B(2)):" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "int fd, removeFd;\n" "\\&\n" "fd = openat(req-Edata.args[0], path, req-Edata.args[2],\n" " req-Edata.args[3]);\n" "\\&\n" "struct seccomp_notif_addfd addfd;\n" "addfd.id = req-Eid; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n" "addfd.srcfd = fd;\n" "addfd.newfd = 0;\n" "addfd.flags = 0;\n" "addfd.newfd_flags = O_CLOEXEC;\n" "\\&\n" "targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" "\\&\n" "close(fd); /* No longer needed in supervisor */\n" "\\&\n" "struct seccomp_notif_resp *resp;\n" " /* Code to allocate 'resp' omitted */\n" "resp-Eid = req-Eid;\n" "resp-Eerror = 0; /* \"Success\" */\n" "resp-Eval = targetFd;\n" "resp-Eflags = 0;\n" "ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" msgstr "" "int fd, removeFd;\n" "\\&\n" "fd = openat(req-Edata.args[0], path, req-Edata.args[2],\n" " req-Edata.args[3]);\n" "\\&\n" "struct seccomp_notif_addfd addfd;\n" "addfd.id = req-Eid; /* الكوكيز من SECCOMP_IOCTL_NOTIF_RECV */\n" "addfd.srcfd = fd;\n" "addfd.newfd = 0;\n" "addfd.flags = 0;\n" "addfd.newfd_flags = O_CLOEXEC;\n" "\\&\n" "targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" "\\&\n" "close(fd); /* لم تعد هناك حاجة إليه في المشرف */\n" "\\&\n" "struct seccomp_notif_resp *resp;\n" " /* كود تخصيص 'resp' محذوف */\n" "resp-Eid = req-Eid;\n" "resp-Eerror = 0; /* \"نجاح\" */\n" "resp-Eval = targetFd;\n" "resp-Eflags = 0;\n" "ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "NOTES" msgstr "ملاحظات" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "One example use case for the user-space notification mechanism is to allow a " "container manager (a process which is typically running with more privilege " "than the processes inside the container) to mount block devices or create " "device nodes for the container. The mount use case provides an example of " "where the B B(2) operation is " "useful. Upon receiving a notification for the B(2) system call, the " "container manager (the \"supervisor\") can distinguish a request to mount a " "block filesystem (which would not be possible for a \"target\" process " "inside the container) and mount that file system. If, on the other hand, " "the container manager detects that the operation could be performed by the " "process inside the container (e.g., a mount of a B(5) filesystem), " "it can notify the kernel that the target process's B(2) system call " "can continue." msgstr "" "أحد الأمثلة على حالة استخدام آلية إشعار مساحة المستخدم هو السماح لمدير " "الحاوية (عملية تعمل عادةً بامتيازات أكثر من العمليات داخل الحاوية) بوصل " "الأجهزة الكتلية أو إنشاء عقد الأجهزة للحاوية. توفر حالة استخدام الوصل مثالاً " "على فائدة عملية B B(2). عند استلام " "إشعار لاستدعاء النظام B(2)، يمكن لمدير الحاوية (\"المشرف\") التمييز " "بين طلب لوصل نظام ملفات كتلي (والذي لن يكون ممكناً لعملية \"هدف\" داخل " "الحاوية) ووصل نظام الملفات هذا. ومن ناحية أخرى، إذا اكتشف مدير الحاوية أن " "العملية يمكن تنفيذها بواسطة العملية داخل الحاوية (على سبيل المثال، وصل نظام " "ملفات B(5))، فيمكنه إخطار النواة بأن استدعاء نظام B(2) لعملية " "الهدف يمكن أن يستمر." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "select()/poll()/epoll semantics" msgstr "دلالات select()/poll()/epoll" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The file descriptor returned when B(2) is employed with the " "B flag can be monitored using B(2), " "B(7), and B(2). تشير هذه الواجهات إلى أن واصف الملف جاهز كما يلي:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "When a notification is pending, these interfaces indicate that the file " "descriptor is readable. Following such an indication, a subsequent " "B B(2) will not block, returning either " "information about a notification or else failing with the error B if " "the target has been killed by a signal or its system call has been " "interrupted by a signal handler." msgstr "" "عندما يكون الإشعار معلقاً، تشير هذه الواجهات إلى أن واصف الملف قابل للقراءة. " "وعقب هذا المؤشر، لن تحظر عملية B B(2) " "اللاحقة، حيث ستعيد إما معلومات حول الإشعار أو تفشل مع الخطأ B إذا قُتل " "الهدف بواسطة إشارة أو قوطع استدعاء النظام الخاص به بواسطة معالج إشارة." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "After the notification has been received (i.e., by the " "B B(2) operation), these interfaces " "indicate that the file descriptor is writable, meaning that a notification " "response can be sent using the B B(2) " "operation." msgstr "" "بعد تلقي الإشعار (أي بواسطة عملية B B(2))، " "تشير هذه الواجهات إلى أن واصف الملف قابل للكتابة، مما يعني أنه يمكن إرسال " "استجابة إشعار باستخدام عملية B B(2)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "After the last thread using the filter has terminated and been reaped using " "B(2) (or similar), the file descriptor indicates an end-of-file " "condition (readable in B(2)؛ و " "B/B في B(2)/ B(2))." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Design goals; use of SECCOMP_USER_NOTIF_FLAG_CONTINUE" msgstr "أهداف التصميم؛ استخدام SECCOMP_USER_NOTIF_FLAG_CONTINUE" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The intent of the user-space notification feature is to allow system calls " "to be performed on behalf of the target. The target's system call should " "either be handled by the supervisor or allowed to continue normally in the " "kernel (where standard security policies will be applied)." msgstr "" "الغرض من ميزة إشعار مساحة المستخدم هو السماح بإجراء استدعاءات النظام نيابة " "عن الهدف. ينبغي إما أن يتولى المشرف معالجة استدعاء نظام الهدف أو يُسمح له " "بالاستمرار بشكل طبيعي في النواة (حيث ستُطبق سياسات الأمان القياسية)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "B: this mechanism must not be used to make security policy " "decisions about the system call, which would be inherently race-prone for " "reasons described next." msgstr "" "B<ملاحظة هامة>: يجب عدم استخدام هذه الآلية لاتخاذ قرارات سياسة الأمان بشأن " "استدعاء النظام، وهو ما سيكون عرضة لسباق البيانات بطبيعته لأسباب موصوفة لاحقًا." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The B flag must be used with caution. If " "set by the supervisor, the target's system call will continue. However, " "there is a time-of-check, time-of-use race here, since an attacker could " "exploit the interval of time where the target is blocked waiting on the " "\"continue\" response to do things such as rewriting the system call " "arguments." msgstr "" "يجب استخدام العلم B بحذر. إذا ضبطه المشرف، " "فسيستمر استدعاء نظام الهدف. ومع ذلك، يوجد سباق \"وقت التحقق مقابل وقت " "الاستخدام\" هنا، حيث يمكن لمهاجم استغلال الفاصل الزمني الذي يكون فيه الهدف " "محظوراً بانتظار استجابة \"الاستمرار\" للقيام بأمور مثل إعادة كتابة وسائط " "استدعاء النظام." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Note furthermore that a user-space notifier can be bypassed if the existing " "filters allow the use of B(2) or B(2) to install a filter " "that returns an action value with a higher precedence than " "B (see B(2))." msgstr "" "لاحظ علاوة على ذلك أنه يمكن تجاوز مُخطِر مساحة المستخدم إذا سمحت المرشحات " "الحالية باستخدام B(2) أو B(2) لتثبيت مرشح يعيد قيمة إجراء " "ذات أسبقية أعلى من B (راجع B(2))." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "It should thus be absolutely clear that the seccomp user-space notification " "mechanism B be used to implement a security policy! It should only " "ever be used in scenarios where a more privileged process supervises the " "system calls of a lesser privileged target to get around kernel-enforced " "security restrictions when the supervisor deems this safe. In other words, " "in order to continue a system call, the supervisor should be sure that " "another security mechanism or the kernel itself will sufficiently block the " "system call if its arguments are rewritten to something unsafe." msgstr "" "لذا ينبغي أن يكون واضحاً تماماً أن آلية إشعار مساحة مستخدم seccomp B<لا يمكن> " "استخدامها لتنفيذ سياسة أمان! يجب استخدامها فقط في السيناريوهات التي تتوفر " "فيها عملية أكثر امتيازاً تشرف على استدعاءات نظام هدف أقل امتيازاً للالتفاف على " "قيود الأمان التي تفرضها النواة عندما يرى المشرف أن هذا آمن. وبعبارة أخرى، من " "أجل مواصلة استدعاء نظام، يجب أن يتأكد المشرف من أن آلية أمان أخرى أو النواة " "نفسها ستحظر استدعاء النظام بشكل كافٍ إذا أُعيدت كتابة وسائطه إلى شيء غير آمن." #. type: SS #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "Caveats regarding the use of" msgstr "تحذيرات بشأن استخدام" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "ItidI The discussion above noted the need to use the " "B B(2) when opening the ItidI file of the target to avoid the possibility of accessing the memory of " "the wrong process in the event that the target terminates and its ID is " "recycled by another (unrelated) thread. However, the use of this " "B(2) operation is also necessary in other situations, as explained " "in the following paragraphs." msgstr "" "أشار النقاش أعلاه في ItidI إلى الحاجة لاستخدام B(2) " "B عند فتح ملف ItidI الخاص بالهدف " "لتجنب إمكانية الوصول إلى ذاكرة العملية الخاطئة في حال انتهاء الهدف وإعادة " "تدوير معرفه بواسطة خيط آخر (غير ذي صلة). ومع ذلك، فإن استخدام عملية " "B(2) هذه ضروري أيضًا في مواقف أخرى، كما هو موضح في الفقرات التالية." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Consider the following scenario, where the supervisor tries to read the " "pathname argument of a target's blocked B(2) system call:" msgstr "" "تأمل السيناريو التالي، حيث يحاول المشرف قراءة وسيط مسار استدعاء نظام " "B(2) المحظور للهدف:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "From one of its functions (I), the target calls B(2), which " "triggers a user-space notification and causes the target to block." msgstr "" "من إحدى وظائفه (I)، يستدعي الهدف B(2)، مما يطلق إشعار مساحة " "مستخدم ويتسبب في حظر الهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The supervisor receives the notification, opens ItidI, and " "(successfully) performs the B check." msgstr "" "يتلقى المشرف الإشعار، ويفتح ItidI، ويجري فحص " "B (بنجاح)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "The target receives a signal, which causes the B(2) to abort." msgstr "يتلقى الهدف إشارة، مما يتسبب في إجهاض B(2)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "The signal handler executes in the target, and returns." msgstr "يُنفذ معالج الإشارة في الهدف، ثم يعود." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Upon return from the handler, the execution of I resumes, and it " "returns (and perhaps other functions are called, overwriting the memory that " "had been used for the stack frame of I)." msgstr "" "عند العودة من المعالج، يُستأنف تنفيذ I)، وتعود (وربما تُستدعى وظائف " "أخرى، مما يعيد الكتابة فوق الذاكرة التي كانت تُستخدم لإطار مكدس I)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Using the address provided in the notification information, the supervisor " "reads from the target's memory location that used to contain the pathname." msgstr "" "باستخدام العنوان الموفر في معلومات الإشعار، يقرأ المشرف من موقع ذاكرة الهدف " "الذي كان يحتوي على المسار." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The supervisor now calls B(2) with some arbitrary bytes obtained in " "the previous step." msgstr "" "يستدعي المشرف الآن B(2) مع بعض البايتات العشوائية التي حُصل عليها في " "الخطوة السابقة." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The conclusion from the above scenario is this: since the target's blocked " "system call may be interrupted by a signal handler, the supervisor must be " "written to expect that the target may abandon its system call at B " "time; in such an event, any information that the supervisor obtained from " "the target's memory must be considered invalid." msgstr "" "الاستنتاج من السيناريو أعلاه هو كالتالي: بما أن استدعاء نظام الهدف المحظور " "قد يقاطعه معالج إشارة، يجب كتابة المشرف ليتوقع أن الهدف قد يتخلى عن استدعاء " "النظام الخاص به في B<أي> وقت؛ وفي مثل هذه الحالة، يجب اعتبار أي معلومات حصل " "عليها المشرف من ذاكرة الهدف غير صالحة." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "To prevent such scenarios, every read from the target's memory must be " "separated from use of the bytes so obtained by a " "B check. In the above example, the check " "would be placed between the two final steps. An example of such a check is " "shown in EXAMPLES." msgstr "" "لمنع مثل هذه السيناريوهات، يجب فصل كل عملية قراءة من ذاكرة الهدف عن استخدام " "البايتات التي حُصل عليها بفحص B. وفي المثال " "أعلاه، سيوضع الفحص بين الخطوتين الأخيرتين. يظهر مثال على هذا الفحص في قسم " "\"أمثلة\"." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Following on from the above, it should be clear that a write by the " "supervisor into the target's memory can B be considered safe." msgstr "" "بناءً على ما سبق، ينبغي أن يكون واضحاً أن الكتابة بواسطة المشرف في ذاكرة الهدف " "لا يمكن B<أبداً> اعتبارها آمنة." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Caveats regarding blocking system calls" msgstr "تحذيرات بشأن حظر استدعاءات النظام" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Suppose that the target performs a blocking system call (e.g., " "B(2)) that the supervisor should handle. The supervisor might then " "in turn execute the same blocking system call." msgstr "" "افترض أن الهدف يجري استدعاء نظام حاصراً (مثل B(2)) ينبغي أن يعالجه " "المشرف. قد ينفذ المشرف بدوره نفس استدعاء النظام الحاصر." #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed msgid "" "In this scenario, it is important to note that if the target's system call " "is now interrupted by a signal, the supervisor is I informed of this. " "If the supervisor does not take suitable steps to actively discover that the " "target's system call has been canceled, various difficulties can occur. " "Taking the example of B(2), the supervisor might remain blocked in " "its B(2) holding a port number that the target (which, after the " "interruption by the signal handler, perhaps closed its listening socket) " "might expect to be able to reuse in a B(2) call." msgstr "" "في هذا السيناريو، من المهم ملاحظة أنه إذا قوطع استدعاء نظام الهدف الآن " "بواسطة إشارة، فإن المشرف I<لا> يُخطر بذلك. وإذا لم يتخذ المشرف خطوات مناسبة " "لاكتشاف إلغاء استدعاء نظام الهدف بنشاط، فقد تحدث صعوبات مختلفة. وبالأخذ " "بمثال B(2)، قد يظل المشرف محظوراً في B(2) الخاص به ممسكاً برقم " "منفذ قد يتوقع الهدف (الذي ربما أغلق مقبس الاستماع الخاص به بعد مقاطعته من " "معالج الإشارة) أن يتمكن من إعادة استخدامه في استدعاء B(2)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Therefore, when the supervisor wishes to emulate a blocking system call, it " "must do so in such a way that it gets informed if the target's system call " "is interrupted by a signal handler. For example, if the supervisor itself " "executes the same blocking system call, then it could employ a separate " "thread that uses the B operation to check if " "the target is still blocked in its system call. Alternatively, in the " "B(2) example, the supervisor might use B(2) to monitor both " "the notification file descriptor (so as to discover when the target's " "B(2) call has been interrupted) and the listening file descriptor " "(so as to know when a connection is available)." msgstr "" "لذلك، عندما يرغب المشرف في محاكاة استدعاء نظام حاصر، يجب أن يفعل ذلك بطريقة " "تجعله يُخطر إذا قوطع استدعاء نظام الهدف بواسطة معالج إشارة. على سبيل المثال، " "إذا نفذ المشرف نفسه نفس استدعاء النظام الحاصر، فيمكنه حينئذٍ توظيف خيط منفصل " "يستخدم عملية B للتحقق مما إذا كان الهدف لا " "يزال محظوراً في استدعاء النظام الخاص به. وبدلاً من ذلك، في مثال B(2)، " "قد يستخدم المشرف B(2) لمراقبة كل من واصف ملف الإشعار (لاكتشاف وقت " "مقاطعة استدعاء B(2) للهدف) وواصف ملف الاستماع (لمعرفة وقت توفر " "اتصال)." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the target's system call is interrupted, the supervisor must take care to " "release resources (e.g., file descriptors) that it acquired on behalf of " "the target." msgstr "" "إذا قوطع استدعاء نظام الهدف، يجب على المشرف توخي الحذر لتحرير الموارد (مثل " "واصفات الملفات) التي حصل عليها نيابة عن الهدف." #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Interaction with SA_RESTART signal handlers" msgstr "التفاعل مع معالجات إشارة SA_RESTART" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "Consider the following scenario:" msgstr "تأمل السيناريو التالي:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The target process has used B(2) to install a signal handler " "with the B flag." msgstr "" "استخدمت العملية الهدف B(2) لتثبيت معالج إشارة مع العلم " "B." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The target has made a system call that triggered a seccomp user-space " "notification and the target is currently blocked until the supervisor sends " "a notification response." msgstr "" "أجرى الهدف استدعاء نظام أطلق إشعار مساحة مستخدم seccomp، والهدف محظور حالياً " "حتى يرسل المشرف استجابة إشعار." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "A signal is delivered to the target and the signal handler is executed." msgstr "سُلّمت إشارة إلى الهدف ونُفذ معالج الإشارة." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "When (if) the supervisor attempts to send a notification response, the " "B B(2)) operation will fail with the " "B error." msgstr "" "عندما (إذا) حاول المشرف إرسال استجابة إشعار، ستفشل عملية B(2) " "B مع الخطأ B." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In this scenario, the kernel will restart the target's system call. " "Consequently, the supervisor will receive another user-space notification. " "Thus, depending on how many times the blocked system call is interrupted by " "a signal handler, the supervisor may receive multiple notifications for the " "same instance of a system call in the target." msgstr "" "في هذا السيناريو، ستعيد النواة تشغيل استدعاء نظام الهدف. وبناءً على ذلك، " "سيتلقى المشرف إشعاراً آخر في مساحة المستخدم. وهكذا، اعتماداً على عدد مرات " "مقاطعة استدعاء النظام المحظور بواسطة معالج إشارة، قد يتلقى المشرف إشعارات " "متعددة لنفس نسخة استدعاء النظام في الهدف." # # #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. FIXME #. About the above, Kees Cook commented: #. Does this need fixing? I imagine the correct behavior for this case #. would be a response to _SEND of EINPROGRESS and the target would see #. EINTR normally? #. I mean, it's not like seccomp doesn't already expose weirdness with #. syscall restarts. Not even arm64 compat agrees[3] with arm32 in this #. regard. :( #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "One oddity is that system call restarting as described in this scenario will " "occur even for the blocking system calls listed in B(7) that would " "B normally be restarted by the B flag." msgstr "" "من الأمور الغريبة أن إعادة تشغيل استدعاء النظام كما هو موضح في هذا السيناريو " "ستحدث حتى بالنسبة لاستدعاءات النظام الحاصرة المدرجة في B(7) والتي لا " "يُعاد تشغيلها B<أبداً> في العادة بواسطة العلم B." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "Furthermore, if the supervisor response is a file descriptor added with " "B, then the flag B can " "be used to atomically add the file descriptor and return that value, making " "sure no file descriptors are inadvertently leaked into the target." msgstr "" "علاوة على ذلك، إذا كانت استجابة المشرف هي واصف ملف أُضيف باستخدام " "B، فيمكن حينئذٍ استخدام العلم " "B لإضافة واصف الملف وإعادة تلك القيمة ذرياً، مما " "يضمن عدم تسرب أي واصفات ملفات عن غير قصد إلى الهدف." #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "BUGS" msgstr "العلل" # #. #-#-#-#-# archlinux: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #. #-#-#-#-# debian-trixie: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #. #-#-#-#-# debian-unstable: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #. #-#-#-#-# fedora-44: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #. #-#-#-#-# fedora-rawhide: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #. #-#-#-#-# mageia-cauldron: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #. #-#-#-#-# opensuse-leap-16-1: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #. #-#-#-#-# opensuse-tumbleweed: seccomp_unotify.2.pot (PACKAGE VERSION) #-#-#-#-# #. or a poll/epoll/select #. FIXME #. Comment from Kees Cook: #. I want this fixed. It caused me no end of pain when building the #. selftests, and ended up spawning my implementing a global test timeout #. in kselftest. :P Before the usage counter refactor, there was no sane #. way to deal with this, but now I think we're close. #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If a B B(2) operation is performed after " "the target terminates, then the B(2) call simply blocks (rather than " "returning an error to indicate that the target no longer exists)." msgstr "" "إذا أُجريت عملية B B(2) بعد انتهاء الهدف، " "فإن استدعاء B(2) يحظر ببساطة (بدلاً من إعادة خطأ يشير إلى أن الهدف لم " "يعد موجوداً)." #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "EXAMPLES" msgstr "أمثلة" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The (somewhat contrived) program shown below demonstrates the use of the " "interfaces described in this page. The program creates a child process that " "serves as the \"target\" process. The child process installs a seccomp " "filter that returns the B action value if a call is " "made to B(2). The child process then calls B(2) once for " "each of the supplied command-line arguments, and reports the result returned " "by the call. After processing all arguments, the child process terminates." msgstr "" "يوضح البرنامج الموضح أدناه (المصمم لغرض العرض) استخدام الواجهات الموصوفة في " "هذه الصفحة. ينشئ البرنامج عملية ابنة تعمل كعملية \"هدف\". تثبت العملية " "الابنة مرشح seccomp يعيد قيمة إجراء B إذا أُجري " "استدعاء لـ B(2). ثم تستدعي العملية الابنة B(2) مرة واحدة لكل " "وسيط من وسائط سطر الأوامر الموفرة، وتبلغ عن النتيجة التي أعادها الاستدعاء. " "وبعد معالجة كافة الوسائط، تنتهي العملية الابنة." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "The parent process acts as the supervisor, listening for the notifications " "that are generated when the target process calls B(2). When such a " "notification occurs, the supervisor examines the memory of the target " "process (using IpidI) to discover the pathname argument that " "was supplied to the B(2) call, and performs one of the following " "actions:" msgstr "" "تعمل العملية الأب كمشرف، حيث تستمع للإشعارات التي تُولّد عندما تستدعي العملية " "الهدف B(2). وعند حدوث مثل هذا الإشعار، يفحص المشرف ذاكرة العملية " "الهدف (باستخدام IpidI) لاكتشاف وسيط المسار الذي وُفر لاستدعاء " "B(2)، وينفذ أحد الإجراءات التالية:" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the pathname begins with the prefix \"/tmp/\", then the supervisor " "attempts to create the specified directory, and then spoofs a return for the " "target process based on the return value of the supervisor's B(2) " "call. In the event that that call succeeds, the spoofed success return " "value is the length of the pathname." msgstr "" "إذا بدأ المسار بالبادئة \"/tmp/\"، يحاول المشرف إنشاء الدليل المحدد، ثم يزيف " "عودة للعملية الهدف بناءً على القيمة المعادة من استدعاء B(2) الخاص " "بالمشرف. وفي حال نجاح ذلك الاستدعاء، تكون قيمة العودة الناجحة المزيفة هي طول " "المسار." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the pathname begins with \"./\" (i.e., it is a relative pathname), the " "supervisor sends a B response to the " "kernel to say that the kernel should execute the target process's " "B(2) call." msgstr "" "إذا بدأ المسار بـ \"./\" (أي أنه مسار نسبي)، يرسل المشرف استجابة " "B إلى النواة للإشارة إلى أنه يجب على " "النواة تنفيذ استدعاء B(2) للعملية الهدف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the pathname begins with some other prefix, the supervisor spoofs an " "error return for the target process, so that the target process's " "B(2) call appears to fail with the error B (\"Operation " "not supported\"). Additionally, if the specified pathname is exactly \"/" "bye\", then the supervisor terminates." msgstr "" "إذا بدأ المسار ببادئة أخرى، يزيف المشرف عودة خطأ للعملية الهدف، لكي يبدو أن " "استدعاء B(2) للعملية الهدف قد فشل مع الخطأ B (\"العملية " "غير مدعومة\"). بالإضافة إلى ذلك، إذا كان المسار المحدد هو \"/bye\" بالضبط، " "فينتهي المشرف." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "This program can be used to demonstrate various aspects of the behavior of " "the seccomp user-space notification mechanism. To help aid such " "demonstrations, the program logs various messages to show the operation of " "the target process (lines prefixed \"T:\") and the supervisor (indented " "lines prefixed \"S:\")." msgstr "" "يمكن استخدام هذا البرنامج لتوضيح جوانب مختلفة من سلوك آلية إشعار مساحة " "مستخدم seccomp. وللمساعدة في مثل هذه العروض التوضيحية، يسجل البرنامج رسائل " "متنوعة لإظهار عملية العملية الهدف (السطور المسبوقة بـ \"T:\") والمشرف " "(السطور المزاحة والمسبوقة بـ \"S:\")." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the following example, the target attempts to create the directory I. Upon receiving the notification, the supervisor creates the directory " "on the target's behalf, and spoofs a success return to be received by the " "target process's B(2) call." msgstr "" "في المثال التالي، يحاول الهدف إنشاء الدليل I. وعند تلقي الإشعار، " "ينشئ المشرف الدليل نيابة عن الهدف، ويزيف عودة ناجحة ليتلقاها استدعاء " "B(2) للعملية الهدف." #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "$B< ./seccomp_unotify /tmp/x>;\n" "T: PID = 23168\n" "\\&\n" "T: about to mkdir(\"/tmp/x\")\n" " S: got notification (ID 0x17445c4a0f4e0e3c) for PID 23168\n" " S: executing: mkdir(\"/tmp/x\", 0700)\n" " S: success! spoofed return = 6\n" " S: sending response (flags = 0; val = 6; error = 0)\n" "T: SUCCESS: mkdir(2) returned 6\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$B< ./seccomp_unotify /tmp/x>;\n" "T: PID = 23168\n" "\\&\n" "T: على وشك إجراء mkdir(\"/tmp/x\")\n" " S: جُلب إشعار (ID 0x17445c4a0f4e0e3c) لـ PID 23168\n" " S: جارِ تنفيذ: mkdir(\"/tmp/x\", 0700)\n" " S: نجاح! عودة مزيفة = 6\n" " S: جارِ إرسال استجابة (flags = 0; val = 6; error = 0)\n" "T: نجاح: mkdir(2) أعاد 6\n" "\\&\n" "T: جارِ الإنهاء\n" " S: انتهى الهدف؛ وداعاً\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the above output, note that the spoofed return value seen by the target " "process is 6 (the length of the pathname I), whereas a normal " "B(2) call returns 0 on success." msgstr "" "في المخرجات أعلاه، لاحظ أن قيمة العودة المزيفة التي تراها العملية الهدف هي 6 " "(طول المسار I)، بينما يعيد استدعاء B(2) العادي 0 عند النجاح." #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the next example, the target attempts to create a directory using the " "relative pathname I<./sub>. Since this pathname starts with \"./\", the " "supervisor sends a B response to the " "kernel, and the kernel then (successfully) executes the target process's " "B(2) call." msgstr "" "في المثال التالي، يحاول الهدف إنشاء دليل باستخدام المسار النسبي I<./sub>. " "وبما أن هذا المسار يبدأ بـ \"./\"، يرسل المشرف استجابة " "B إلى النواة، وتنفذ النواة حينئذٍ (بنجاح) " "استدعاء B(2) للعملية الهدف." #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "$B< ./seccomp_unotify ./sub>;\n" "T: PID = 23204\n" "\\&\n" "T: about to mkdir(\"./sub\")\n" " S: got notification (ID 0xddb16abe25b4c12) for PID 23204\n" " S: target can execute system call\n" " S: sending response (flags = 0x1; val = 0; error = 0)\n" "T: SUCCESS: mkdir(2) returned 0\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$B< ./seccomp_unotify ./sub>;\n" "T: PID = 23204\n" "\\&\n" "T: على وشك إجراء mkdir(\"./sub\")\n" " S: جُلب إشعار (ID 0xddb16abe25b4c12) لـ PID 23204\n" " S: يمكن للهدف تنفيذ استدعاء النظام\n" " S: جارِ إرسال استجابة (flags = 0x1; val = 0; error = 0)\n" "T: نجاح: mkdir(2) أعاد 0\n" "\\&\n" "T: جارِ الإنهاء\n" " S: انتهى الهدف؛ وداعاً\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the target process attempts to create a directory with a pathname that " "doesn't start with \".\" and doesn't begin with the prefix \"/tmp/\", then " "the supervisor spoofs an error return (B, \"Operation not " "supported\") for the target's B(2) call (which is not executed):" msgstr "" "إذا حاولت العملية الهدف إنشاء دليل بمسار لا يبدأ بـ \".\" ولا يبدأ بالبادئة " "\"/tmp/\"، فإن المشرف يزيف عودة خطأ (B، \"العملية غير مدعومة\") " "لاستدعاء B(2) للهدف (الذي لا يُنفذ):" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "$B< ./seccomp_unotify /xxx>;\n" "T: PID = 23178\n" "\\&\n" "T: about to mkdir(\"/xxx\")\n" " S: got notification (ID 0xe7dc095d1c524e80) for PID 23178\n" " S: spoofing error response (Operation not supported)\n" " S: sending response (flags = 0; val = 0; error = -95)\n" "T: ERROR: mkdir(2): Operation not supported\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$B< ./seccomp_unotify /xxx>;\n" "T: PID = 23178\n" "\\&\n" "T: على وشك إجراء mkdir(\"/xxx\")\n" " S: جُلب إشعار (ID 0xe7dc095d1c524e80) لـ PID 23178\n" " S: جارِ تزييف استجابة خطأ (العملية غير مدعومة)\n" " S: جارِ إرسال استجابة (flags = 0; val = 0; error = -95)\n" "T: خطأ: mkdir(2): العملية غير مدعومة\n" "\\&\n" "T: جارِ الإنهاء\n" " S: انتهى الهدف؛ وداعاً\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "In the next example, the target process attempts to create a directory with " "the pathname B. Upon receiving the notification, the " "supervisor attempts to create that directory, but the B(2) call " "fails because the directory B does not exist. Consequently, " "the supervisor spoofs an error return that passes the error that it received " "back to the target process's B(2) call." msgstr "" "في المثال التالي، تحاول العملية الهدف إنشاء دليل بالمسار B. وعند تلقي الإشعار، يحاول المشرف إنشاء ذلك الدليل، ولكن يفشل استدعاء " "B(2) لأن الدليل B غير موجود. وبناءً على ذلك، يزيف " "المشرف عودة خطأ تمرر الخطأ الذي تلقاه مرة أخرى إلى استدعاء B(2) " "للعملية الهدف." #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "$B< ./seccomp_unotify /tmp/nosuchdir/b>;\n" "T: PID = 23199\n" "\\&\n" "T: about to mkdir(\"/tmp/nosuchdir/b\")\n" " S: got notification (ID 0x8744454293506046) for PID 23199\n" " S: executing: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" " S: failure! (errno = 2; No such file or directory)\n" " S: sending response (flags = 0; val = 0; error = -2)\n" "T: ERROR: mkdir(2): No such file or directory\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$B< ./seccomp_unotify /tmp/nosuchdir/b>;\n" "T: PID = 23199\n" "\\&\n" "T: على وشك إجراء mkdir(\"/tmp/nosuchdir/b\")\n" " S: جُلب إشعار (ID 0x8744454293506046) لـ PID 23199\n" " S: جارِ تنفيذ: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" " S: فشل! (errno = 2; لا يوجد ملف أو دليل كهذا)\n" " S: جارِ إرسال استجابة (flags = 0; val = 0; error = -2)\n" "T: خطأ: mkdir(2): لا يوجد ملف أو دليل كهذا\n" "\\&\n" "T: جارِ الإنهاء\n" " S: انتهى الهدف؛ وداعاً\n" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "If the supervisor receives a notification and sees that the argument of the " "target's B(2) is the string \"/bye\", then (as well as spoofing an " "B error), the supervisor terminates. If the target process " "subsequently executes another B(2) that triggers its seccomp filter " "to return the B action value, then the kernel causes " "the target process's system call to fail with the error B " "(\"Function not implemented\"). This is demonstrated by the following " "example:" msgstr "" "إذا تلقى المشرف إشعارًا ورأى أن وسيط B(2) الخاص بالهدف هو السلسلة \"/" "bye\"، فحينئذٍ ينهي المشرف عمله (بالإضافة إلى تزييف خطأ B). وإذا " "نفذت عملية الهدف لاحقًا B(2) أخرى تحفز مرشح seccomp الخاص بها ليعيد " "قيمة الإجراء B، فتتسبب النواة في فشل استدعاء النظام " "لعملية الهدف بخطأ B (\"الوظيفة غير مفعلة\"). ويُوضح ذلك في المثال " "التالي:" #. type: Plain text #: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 #: opensuse-tumbleweed #, no-wrap msgid "" "$B< ./seccomp_unotify /bye /tmp/y>;\n" "T: PID = 23185\n" "\\&\n" "T: about to mkdir(\"/bye\")\n" " S: got notification (ID 0xa81236b1d2f7b0f4) for PID 23185\n" " S: spoofing error response (Operation not supported)\n" " S: sending response (flags = 0; val = 0; error = -95)\n" " S: terminating **********\n" "T: ERROR: mkdir(2): Operation not supported\n" "\\&\n" "T: about to mkdir(\"/tmp/y\")\n" "T: ERROR: mkdir(2): Function not implemented\n" "\\&\n" "T: terminating\n" msgstr "" "$B< ./seccomp_unotify /bye /tmp/y>;\n" "T: PID = 23185\n" "\\&\n" "T: على وشك إجراء mkdir(\"/bye\")\n" " S: جُلب إشعار (ID 0xa81236b1d2f7b0f4) لـ PID 23185\n" " S: جارِ تزييف استجابة خطأ (العملية غير مدعومة)\n" " S: جارِ إرسال استجابة (flags = 0; val = 0; error = -95)\n" " S: جارِ الإنهاء **********\n" "T: خطأ: mkdir(2): العملية غير مدعومة\n" "\\&\n" "T: على وشك إجراء mkdir(\"/tmp/y\")\n" "T: خطأ: mkdir(2): الوظيفة غير منفذة\n" "\\&\n" "T: جارِ الإنهاء\n" #. type: SS #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Program source" msgstr "مصدر البرنامج" #. type: Plain text #: archlinux debian-unstable opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estdcountof.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "#define streq(...) (strcmp(__VA_ARGS__) == 0)\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = countof(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process. Create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t size)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, size, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (streq(path, \"/bye\"))\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estdcountof.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "#define streq(...) (strcmp(__VA_ARGS__) == 0)\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = countof(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process. Create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t size)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, size, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (streq(path, \"/bye\"))\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" #. SRC END #. type: SH #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "SEE ALSO" msgstr "انظر أيضًا" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "B(2), B(2), B(2), B(2)" msgstr "B(2)، B(2)، B(2)، B(2)" #. type: Plain text #: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide #: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed msgid "" "A further example program can be found in the kernel source file I." msgstr "" "يمكن العثور على مزيد من الأمثلة في ملف مصدر النواة I." #. type: TH #: debian-trixie #, no-wrap msgid "2024-06-15" msgstr "15 يونيو 2024" #. type: TH #: debian-trixie #, no-wrap msgid "Linux man-pages 6.9.1" msgstr "صفحات دليل لينكس 6.9.1" #. type: Plain text #: debian-trixie msgid "Standard C library (I, I<-lc>)" msgstr "مكتبة سي المعيارية (I، I<-lc>)" #. type: Plain text #: debian-trixie msgid "" "On success, this operation returns 0; on failure, -1 is returned, and " "I is set to indicate the cause of the error. This operation can fail " "with the following errors:" msgstr "" "عند النجاح، تعيد هذه العملية 0؛ وعند الفشل، تُعاد -1، ويُضبط I للإشارة " "إلى سبب الخطأ. يمكن أن تفشل هذه العملية بالأخطاء التالية:" #. type: Plain text #: debian-trixie msgid "" "On error, -1 is returned and I is set to indicate the cause of the " "error." msgstr "عند الخطأ، تُعاد القيمة -1 ويُضبط I للإشارة إلى سبب الخطأ." #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "int fd, removeFd;\n" "\\&\n" "fd = openat(req-Edata.args[0], path, req-Edata.args[2],\n" " req-Edata.args[3]);\n" "\\&\n" "struct seccomp_notif_addfd addfd;\n" "addfd.id = req-Eid; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n" "addfd.srcfd = fd;\n" "addfd.newfd = 0;\n" "addfd.flags = 0;\n" "addfd.newfd_flags = O_CLOEXEC;\n" "\\&\n" "targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" "\\&\n" "close(fd); /* No longer needed in supervisor */\n" "\\&\n" "struct seccomp_notif_resp *resp;\n" " /* Code to allocate 'resp' omitted */\n" "resp-Eid = req-Eid;\n" "resp-Eerror = 0; /* \"Success\" */\n" "resp-Eval = targetFd;\n" "resp-Eflags = 0;\n" "ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" msgstr "" "int fd, removeFd;\n" "\\&\n" "fd = openat(req-Edata.args[0], path, req-Edata.args[2],\n" " req-Edata.args[3]);\n" "\\&\n" "struct seccomp_notif_addfd addfd;\n" "addfd.id = req-Eid; /* Cookie from SECCOMP_IOCTL_NOTIF_RECV */\n" "addfd.srcfd = fd;\n" "addfd.newfd = 0;\n" "addfd.flags = 0;\n" "addfd.newfd_flags = O_CLOEXEC;\n" "\\&\n" "targetFd = ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);\n" "\\&\n" "close(fd); /* No longer needed in supervisor */\n" "\\&\n" "struct seccomp_notif_resp *resp;\n" " /* Code to allocate 'resp' omitted */\n" "resp-Eid = req-Eid;\n" "resp-Eerror = 0; /* \"Success\" */\n" "resp-Eval = targetFd;\n" "resp-Eflags = 0;\n" "ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp);\n" #. type: SS #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "Caveats regarding the use of ItidI" msgstr "تحذيرات بشأن استخدام ItidI" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "The discussion above noted the need to use the " "B B(2) when opening the ItidI file of the target to avoid the possibility of accessing the memory of " "the wrong process in the event that the target terminates and its ID is " "recycled by another (unrelated) thread. However, the use of this " "B(2) operation is also necessary in other situations, as explained " "in the following paragraphs." msgstr "" "أشارت المناقشة أعلاه إلى الحاجة لاستخدام B " "B(2) عند فتح ملف ItidI الخاص بالمستهدف لتجنب إمكانية " "الوصول إلى ذاكرة عملية خاطئة في حال انتهى المستهدف وأعيد استخدام معرّفه " "بواسطة خيط معالجة آخر (غير ذي صلة). ومع ذلك، فإن استخدام عملية B(2) " "هذه ضروري أيضًا في مواقف أخرى، كما هو موضح في الفقرات التالية." #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide msgid "" "In this scenario, it is important to note that if the target's system call " "is now interrupted by a signal, the supervisor is I informed of this. " "If the supervisor does not take suitable steps to actively discover that the " "target's system call has been canceled, various difficulties can occur. " "Taking the example of B(2), the supervisor might remain blocked in " "its B(2) holding a port number that the target (which, after the " "interruption by the signal handler, perhaps closed its listening socket) " "might expect to be able to reuse in a B(2) call." msgstr "" "في هذا السيناريو، من المهم ملاحظة أنه إذا قوطع نداء نظام المستهدف الآن " "بواسطة إشارة، فإن المشرف I<لا> يُبلغ بذلك. إذا لم يتخذ المشرف خطوات مناسبة " "لاكتشاف أن نداء نظام المستهدف قد أُلغي بشكل نشط، فقد تحدث صعوبات مختلفة. " "وبأخذ B(2) كمثال، قد يظل المشرف محجوبًا في نداء B(2) الخاص به " "وهو يحمل رقم منفذ قد يتوقع المستهدف (الذي ربما أغلق مقبس الاستماع الخاص به " "بعد مقاطعته بواسطة معالج الإشارة) أن يتمكن من إعادة استخدامه في نداء " "B(2)." #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "$ B<./seccomp_unotify /tmp/x>\n" "T: PID = 23168\n" "\\&\n" "T: about to mkdir(\"/tmp/x\")\n" " S: got notification (ID 0x17445c4a0f4e0e3c) for PID 23168\n" " S: executing: mkdir(\"/tmp/x\", 0700)\n" " S: success! spoofed return = 6\n" " S: sending response (flags = 0; val = 6; error = 0)\n" "T: SUCCESS: mkdir(2) returned 6\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$ B<./seccomp_unotify /tmp/x>\n" "T: PID = 23168\n" "\\&\n" "T: على وشك تنفيذ mkdir(\"/tmp/x\")\n" " S: استُلم إشعار (ID 0x17445c4a0f4e0e3c) لـ PID 23168\n" " S: يجري تنفيذ: mkdir(\"/tmp/x\", 0700)\n" " S: نجاح! القيمة الراجعة المزيفة = 6\n" " S: يجري إرسال الاستجابة (flags = 0; val = 6; error = 0)\n" "T: نجاح: أعاد mkdir(2) القيمة 6\n" "\\&\n" "T: يجري الإنهاء\n" " S: انتهى المستهدف؛ وداعًا\n" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "$ B<./seccomp_unotify ./sub>\n" "T: PID = 23204\n" "\\&\n" "T: about to mkdir(\"./sub\")\n" " S: got notification (ID 0xddb16abe25b4c12) for PID 23204\n" " S: target can execute system call\n" " S: sending response (flags = 0x1; val = 0; error = 0)\n" "T: SUCCESS: mkdir(2) returned 0\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$ B<./seccomp_unotify ./sub>\n" "T: PID = 23204\n" "\\&\n" "T: على وشك تنفيذ mkdir(\"./sub\")\n" " S: استُلم إشعار (ID 0xddb16abe25b4c12) لـ PID 23204\n" " S: يمكن للمستهدف تنفيذ نداء النظام\n" " S: يجري إرسال الاستجابة (flags = 0x1; val = 0; error = 0)\n" "T: نجاح: أعاد mkdir(2) القيمة 0\n" "\\&\n" "T: يجري الإنهاء\n" " S: انتهى المستهدف؛ وداعًا\n" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "$ B<./seccomp_unotify /xxx>\n" "T: PID = 23178\n" "\\&\n" "T: about to mkdir(\"/xxx\")\n" " S: got notification (ID 0xe7dc095d1c524e80) for PID 23178\n" " S: spoofing error response (Operation not supported)\n" " S: sending response (flags = 0; val = 0; error = -95)\n" "T: ERROR: mkdir(2): Operation not supported\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$ B<./seccomp_unotify /xxx>\n" "T: PID = 23178\n" "\\&\n" "T: على وشك تنفيذ mkdir(\"/xxx\")\n" " S: استُلم إشعار (ID 0xe7dc095d1c524e80) لـ PID 23178\n" " S: تزييف استجابة خطأ (العملية غير مدعومة)\n" " S: يجري إرسال الاستجابة (flags = 0; val = 0; error = -95)\n" "T: خطأ: mkdir(2): العملية غير مدعومة\n" "\\&\n" "T: يجري الإنهاء\n" " S: انتهى المستهدف؛ وداعًا\n" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "$ B<./seccomp_unotify /tmp/nosuchdir/b>\n" "T: PID = 23199\n" "\\&\n" "T: about to mkdir(\"/tmp/nosuchdir/b\")\n" " S: got notification (ID 0x8744454293506046) for PID 23199\n" " S: executing: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" " S: failure! (errno = 2; No such file or directory)\n" " S: sending response (flags = 0; val = 0; error = -2)\n" "T: ERROR: mkdir(2): No such file or directory\n" "\\&\n" "T: terminating\n" " S: target has terminated; bye\n" msgstr "" "$ B<./seccomp_unotify /tmp/nosuchdir/b>\n" "T: PID = 23199\n" "\\&\n" "T: على وشك تنفيذ mkdir(\"/tmp/nosuchdir/b\")\n" " S: استُلم إشعار (ID 0x8744454293506046) لـ PID 23199\n" " S: يجري تنفيذ: mkdir(\"/tmp/nosuchdir/b\", 0700)\n" " S: فشل! (errno = 2; لا يوجد ملف أو دليل بهذا الاسم)\n" " S: يجري إرسال الاستجابة (flags = 0; val = 0; error = -2)\n" "T: خطأ: mkdir(2): لا يوجد ملف أو دليل بهذا الاسم\n" "\\&\n" "T: يجري الإنهاء\n" " S: انتهى المستهدف؛ وداعًا\n" #. type: Plain text #: debian-trixie fedora-44 fedora-rawhide #, no-wrap msgid "" "$ B<./seccomp_unotify /bye /tmp/y>\n" "T: PID = 23185\n" "\\&\n" "T: about to mkdir(\"/bye\")\n" " S: got notification (ID 0xa81236b1d2f7b0f4) for PID 23185\n" " S: spoofing error response (Operation not supported)\n" " S: sending response (flags = 0; val = 0; error = -95)\n" " S: terminating **********\n" "T: ERROR: mkdir(2): Operation not supported\n" "\\&\n" "T: about to mkdir(\"/tmp/y\")\n" "T: ERROR: mkdir(2): Function not implemented\n" "\\&\n" "T: terminating\n" msgstr "" "$ B<./seccomp_unotify /bye /tmp/y>\n" "T: PID = 23185\n" "\\&\n" "T: على وشك تنفيذ mkdir(\"/bye\")\n" " S: استُلم إشعار (ID 0xa81236b1d2f7b0f4) لـ PID 23185\n" " S: تزييف استجابة خطأ (العملية غير مدعومة)\n" " S: يجري إرسال الاستجابة (flags = 0; val = 0; error = -95)\n" " S: يجري الإنهاء **********\n" "T: خطأ: mkdir(2): العملية غير مدعومة\n" "\\&\n" "T: على وشك تنفيذ mkdir(\"/tmp/y\")\n" "T: خطأ: mkdir(2): الوظيفة غير مُنفذة\n" "\\&\n" "T: يجري الإنهاء\n" #. type: Plain text #: debian-trixie #, no-wrap msgid "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = ARRAY_SIZE(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process; create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]len\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t len)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, len, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (strcmp(path, \"/bye\") == 0)\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = ARRAY_SIZE(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process; create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]len\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t len)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, len, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (strcmp(path, \"/bye\") == 0)\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" #. type: TH #: fedora-44 fedora-rawhide #, no-wrap msgid "2024-11-17" msgstr "17 نوفمبر 2024" #. type: TH #: fedora-44 fedora-rawhide #, no-wrap msgid "Linux man-pages 6.13" msgstr "صفحات دليل لينكس 6.13" #. type: Plain text #: fedora-44 fedora-rawhide #, no-wrap msgid "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = ARRAY_SIZE(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process; create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t size)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, size, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (strcmp(path, \"/bye\") == 0)\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = ARRAY_SIZE(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process; create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t size)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, size, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (strcmp(path, \"/bye\") == 0)\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" #. type: TH #: mageia-cauldron #, no-wrap msgid "2026-02-10" msgstr "10 فبراير 2026" #. type: TH #: mageia-cauldron #, no-wrap msgid "Linux man-pages 6.17" msgstr "صفحات دليل لينكس 6.17" #. type: Plain text #: mageia-cauldron #, no-wrap msgid "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estdcountof.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = countof(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process. Create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t size)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, size, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (strcmp(path, \"/bye\") == 0)\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" "#define _GNU_SOURCE\n" "#include Eerr.hE\n" "#include Eerrno.hE\n" "#include Efcntl.hE\n" "#include Elimits.hE\n" "#include Elinux/audit.hE\n" "#include Elinux/filter.hE\n" "#include Elinux/seccomp.hE\n" "#include Esignal.hE\n" "#include Estdbool.hE\n" "#include Estdcountof.hE\n" "#include Estddef.hE\n" "#include Estdint.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/ioctl.hE\n" "#include Esys/prctl.hE\n" "#include Esys/socket.hE\n" "#include Esys/stat.hE\n" "#include Esys/syscall.hE\n" "#include Esys/types.hE\n" "#include Esys/un.hE\n" "#include Eunistd.hE\n" "\\&\n" "/* Send the file descriptor \\[aq]fd\\[aq] over the connected UNIX domain socket\n" " \\[aq]sockfd\\[aq]. Returns 0 on success, or -1 on error. */\n" "\\&\n" "static int\n" "sendfd(int sockfd, int fd)\n" "{\n" " int data;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* Allocate a char array of suitable size to hold the ancillary data.\n" " However, since this buffer is in reality a \\[aq]struct cmsghdr\\[aq], use a\n" " union to ensure that it is suitably aligned. */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " /* Space large enough to hold an \\[aq]int\\[aq] */\n" " struct cmsghdr align;\n" " } controlMsg;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to specify the address of the\n" " destination socket when sending a datagram. However, we do not\n" " need to use this field because \\[aq]sockfd\\[aq] is a connected socket. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* On Linux, we must transmit at least one byte of real data in\n" " order to send ancillary data. We transmit an arbitrary integer\n" " whose value is ignored by recvfd(). */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data;\n" " iov.iov_len = sizeof(int);\n" " data = 12345;\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Set up ancillary data describing file descriptor to send */\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" " cmsgp-Ecmsg_level = SOL_SOCKET;\n" " cmsgp-Ecmsg_type = SCM_RIGHTS;\n" " cmsgp-Ecmsg_len = CMSG_LEN(sizeof(int));\n" " memcpy(CMSG_DATA(cmsgp), &fd, sizeof(int));\n" "\\&\n" " /* Send real plus ancillary data */\n" "\\&\n" " if (sendmsg(sockfd, &msgh, 0) == -1)\n" " return -1;\n" "\\&\n" " return 0;\n" "}\n" "\\&\n" "/* Receive a file descriptor on a connected UNIX domain socket. Returns\n" " the received file descriptor on success, or -1 on error. */\n" "\\&\n" "static int\n" "recvfd(int sockfd)\n" "{\n" " int data, fd;\n" " ssize_t nr;\n" " struct iovec iov;\n" " struct msghdr msgh;\n" "\\&\n" " /* Allocate a char buffer for the ancillary data. See the comments\n" " in sendfd() */\n" " union {\n" " char buf[CMSG_SPACE(sizeof(int))];\n" " struct cmsghdr align;\n" " } controlMsg;\n" " struct cmsghdr *cmsgp;\n" "\\&\n" " /* The \\[aq]msg_name\\[aq] field can be used to obtain the address of the\n" " sending socket. However, we do not need this information. */\n" "\\&\n" " msgh.msg_name = NULL;\n" " msgh.msg_namelen = 0;\n" "\\&\n" " /* Specify buffer for receiving real data */\n" "\\&\n" " msgh.msg_iov = &iov;\n" " msgh.msg_iovlen = 1;\n" " iov.iov_base = &data; /* Real data is an \\[aq]int\\[aq] */\n" " iov.iov_len = sizeof(int);\n" "\\&\n" " /* Set \\[aq]msghdr\\[aq] fields that describe ancillary data */\n" "\\&\n" " msgh.msg_control = controlMsg.buf;\n" " msgh.msg_controllen = sizeof(controlMsg.buf);\n" "\\&\n" " /* Receive real plus ancillary data; real data is ignored */\n" "\\&\n" " nr = recvmsg(sockfd, &msgh, 0);\n" " if (nr == -1)\n" " return -1;\n" "\\&\n" " cmsgp = CMSG_FIRSTHDR(&msgh);\n" "\\&\n" " /* Check the validity of the \\[aq]cmsghdr\\[aq] */\n" "\\&\n" " if (cmsgp == NULL\n" " || cmsgp-Ecmsg_len != CMSG_LEN(sizeof(int))\n" " || cmsgp-Ecmsg_level != SOL_SOCKET\n" " || cmsgp-Ecmsg_type != SCM_RIGHTS)\n" " {\n" " errno = EINVAL;\n" " return -1;\n" " }\n" "\\&\n" " /* Return the received file descriptor to our caller */\n" "\\&\n" " memcpy(&fd, CMSG_DATA(cmsgp), sizeof(int));\n" " return fd;\n" "}\n" "\\&\n" "static void\n" "sigchldHandler(int sig)\n" "{\n" " char msg[] = \"\\[rs]tS: target has terminated; bye\\[rs]n\";\n" "\\&\n" " write(STDOUT_FILENO, msg, sizeof(msg) - 1);\n" " _exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "static int\n" "seccomp(unsigned int operation, unsigned int flags, void *args)\n" "{\n" " return syscall(SYS_seccomp, operation, flags, args);\n" "}\n" "\\&\n" "/* The following is the x86-64-specific BPF boilerplate code for checking\n" " that the BPF program is running on the right architecture + ABI. At\n" " completion of these instructions, the accumulator contains the system\n" " call number. */\n" "\\&\n" "/* For the x32 ABI, all system call numbers have bit 30 set */\n" "\\&\n" "#define X32_SYSCALL_BIT 0x40000000\n" "\\&\n" "#define X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, arch))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 0, 2), \\[rs]\n" " BPF_STMT(BPF_LD | BPF_W | BPF_ABS, \\[rs]\n" " (offsetof(struct seccomp_data, nr))), \\[rs]\n" " BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, X32_SYSCALL_BIT, 0, 1), \\[rs]\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS)\n" "\\&\n" "/* installNotifyFilter() installs a seccomp filter that generates\n" " user-space notifications (SECCOMP_RET_USER_NOTIF) when the process\n" " calls mkdir(2); the filter allows all other system calls.\n" "\\&\n" " The function return value is a file descriptor from which the\n" " user-space notifications can be fetched. */\n" "\\&\n" "static int\n" "installNotifyFilter(void)\n" "{\n" " int notifyFd;\n" "\\&\n" " struct sock_filter filter[] = {\n" " X86_64_CHECK_ARCH_AND_LOAD_SYSCALL_NR,\n" "\\&\n" " /* mkdir() triggers notification to user-space supervisor */\n" "\\&\n" " BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_mkdir, 0, 1),\n" " BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_USER_NOTIF),\n" "\\&\n" " /* Every other system call is allowed */\n" "\\&\n" " BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),\n" " };\n" "\\&\n" " struct sock_fprog prog = {\n" " .len = countof(filter),\n" " .filter = filter,\n" " };\n" "\\&\n" " /* Install the filter with the SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " as a result, seccomp() returns a notification file descriptor. */\n" "\\&\n" " notifyFd = seccomp(SECCOMP_SET_MODE_FILTER,\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"seccomp-install-notify-filter\");\n" "\\&\n" " return notifyFd;\n" "}\n" "\\&\n" "/* Close a pair of sockets created by socketpair() */\n" "\\&\n" "static void\n" "closeSocketPair(int sockPair[2])\n" "{\n" " if (close(sockPair[0]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-0\");\n" " if (close(sockPair[1]) == -1)\n" " err(EXIT_FAILURE, \"closeSocketPair-close-1\");\n" "}\n" "\\&\n" "/* Implementation of the target process. Create a child process that:\n" "\\&\n" " (1) installs a seccomp filter with the\n" " SECCOMP_FILTER_FLAG_NEW_LISTENER flag;\n" " (2) writes the seccomp notification file descriptor returned from\n" " the previous step onto the UNIX domain socket, \\[aq]sockPair[0]\\[aq];\n" " (3) calls mkdir(2) for each element of \\[aq]argv\\[aq].\n" "\\&\n" " The function return value in the parent is the PID of the child\n" " process; the child does not return from this function. */\n" "\\&\n" "static pid_t\n" "targetProcess(int sockPair[2], char *argv[])\n" "{\n" " int notifyFd, s;\n" " pid_t targetPid;\n" "\\&\n" " targetPid = fork();\n" "\\&\n" " if (targetPid == -1)\n" " err(EXIT_FAILURE, \"fork\");\n" "\\&\n" " if (targetPid E 0) /* In parent, return PID of child */\n" " return targetPid;\n" "\\&\n" " /* Child falls through to here */\n" "\\&\n" " printf(\"T: PID = %ld\\[rs]n\", (long) getpid());\n" "\\&\n" " /* Install seccomp filter(s) */\n" "\\&\n" " if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))\n" " err(EXIT_FAILURE, \"prctl\");\n" "\\&\n" " notifyFd = installNotifyFilter();\n" "\\&\n" " /* Pass the notification file descriptor to the tracing process over\n" " a UNIX domain socket */\n" "\\&\n" " if (sendfd(sockPair[0], notifyFd) == -1)\n" " err(EXIT_FAILURE, \"sendfd\");\n" "\\&\n" " /* Notification and socket FDs are no longer needed in target */\n" "\\&\n" " if (close(notifyFd) == -1)\n" " err(EXIT_FAILURE, \"close-target-notify-fd\");\n" "\\&\n" " closeSocketPair(sockPair);\n" "\\&\n" " /* Perform a mkdir() call for each of the command-line arguments */\n" "\\&\n" " for (char **ap = argv; *ap != NULL; ap++) {\n" " printf(\"\\[rs]nT: about to mkdir(\\[rs]\"%s\\[rs]\")\\[rs]n\", *ap);\n" "\\&\n" " s = mkdir(*ap, 0700);\n" " if (s == -1)\n" " perror(\"T: ERROR: mkdir(2)\");\n" " else\n" " printf(\"T: SUCCESS: mkdir(2) returned %d\\[rs]n\", s);\n" " }\n" "\\&\n" " printf(\"\\[rs]nT: terminating\\[rs]n\");\n" " exit(EXIT_SUCCESS);\n" "}\n" "\\&\n" "/* Check that the notification ID provided by a SECCOMP_IOCTL_NOTIF_RECV\n" " operation is still valid. It will no longer be valid if the target\n" " process has terminated or is no longer blocked in the system call that\n" " generated the notification (because it was interrupted by a signal).\n" "\\&\n" " This operation can be used when doing such things as accessing\n" " /proc/PID files in the target process in order to avoid TOCTOU race\n" " conditions where the PID that is returned by SECCOMP_IOCTL_NOTIF_RECV\n" " terminates and is reused by another process. */\n" "\\&\n" "static bool\n" "cookieIsValid(int notifyFd, uint64_t id)\n" "{\n" " return ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_ID_VALID, &id) == 0;\n" "}\n" "\\&\n" "/* Access the memory of the target process in order to fetch the\n" " pathname referred to by the system call argument \\[aq]argNum\\[aq] in\n" " \\[aq]req-Edata.args[]\\[aq]. The pathname is returned in \\[aq]path\\[aq],\n" " a buffer of \\[aq]size\\[aq] bytes allocated by the caller.\n" "\\&\n" " Returns true if the pathname is successfully fetched, and false\n" " otherwise. For possible causes of failure, see the comments below. */\n" "\\&\n" "static bool\n" "getTargetPathname(struct seccomp_notif *req, int notifyFd,\n" " int argNum, char *path, size_t size)\n" "{\n" " int procMemFd;\n" " char procMemPath[PATH_MAX];\n" " ssize_t nread;\n" "\\&\n" " snprintf(procMemPath, sizeof(procMemPath), \"/proc/%d/mem\", req-Epid);\n" "\\&\n" " procMemFd = open(procMemPath, O_RDONLY | O_CLOEXEC);\n" " if (procMemFd == -1)\n" " return false;\n" "\\&\n" " /* Check that the process whose info we are accessing is still alive\n" " and blocked in the system call that caused the notification.\n" " If the SECCOMP_IOCTL_NOTIF_ID_VALID operation (performed in\n" " cookieIsValid()) succeeded, we know that the /proc/PID/mem file\n" " descriptor that we opened corresponded to the process for which we\n" " received a notification. If that process subsequently terminates,\n" " then read() on that file descriptor will return 0 (EOF). */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " close(procMemFd);\n" " return false;\n" " }\n" "\\&\n" " /* Read bytes at the location containing the pathname argument */\n" "\\&\n" " nread = pread(procMemFd, path, size, req-Edata.args[argNum]);\n" "\\&\n" " close(procMemFd);\n" "\\&\n" " if (nread E= 0)\n" " return false;\n" "\\&\n" " /* Once again check that the notification ID is still valid. The\n" " case we are particularly concerned about here is that just\n" " before we fetched the pathname, the target\\[aq]s blocked system\n" " call was interrupted by a signal handler, and after the handler\n" " returned, the target carried on execution (past the interrupted\n" " system call). In that case, we have no guarantees about what we\n" " are reading, since the target\\[aq]s memory may have been arbitrarily\n" " changed by subsequent operations. */\n" "\\&\n" " if (!cookieIsValid(notifyFd, req-Eid)) {\n" " perror(\"\\[rs]tS: notification ID check failed!!!\");\n" " return false;\n" " }\n" "\\&\n" " /* Even if the target\\[aq]s system call was not interrupted by a signal,\n" " we have no guarantees about what was in the memory of the target\n" " process. (The memory may have been modified by another thread, or\n" " even by an external attacking process.) We therefore treat the\n" " buffer returned by pread() as untrusted input. The buffer should\n" " contain a terminating null byte; if not, then we will trigger an\n" " error for the target process. */\n" "\\&\n" " if (strnlen(path, nread) E nread)\n" " return true;\n" "\\&\n" " return false;\n" "}\n" "\\&\n" "/* Allocate buffers for the seccomp user-space notification request and\n" " response structures. It is the caller\\[aq]s responsibility to free the\n" " buffers returned via \\[aq]req\\[aq] and \\[aq]resp\\[aq]. */\n" "\\&\n" "static void\n" "allocSeccompNotifBuffers(struct seccomp_notif **req,\n" " struct seccomp_notif_resp **resp,\n" " struct seccomp_notif_sizes *sizes)\n" "{\n" " size_t resp_size;\n" "\\&\n" " /* Discover the sizes of the structures that are used to receive\n" " notifications and send notification responses, and allocate\n" " buffers of those sizes. */\n" "\\&\n" " if (seccomp(SECCOMP_GET_NOTIF_SIZES, 0, sizes) == -1)\n" " err(EXIT_FAILURE, \"seccomp-SECCOMP_GET_NOTIF_SIZES\");\n" "\\&\n" " *req = malloc(sizes-Eseccomp_notif);\n" " if (*req == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif\");\n" "\\&\n" " /* When allocating the response buffer, we must allow for the fact\n" " that the user-space binary may have been built with user-space\n" " headers where \\[aq]struct seccomp_notif_resp\\[aq] is bigger than the\n" " response buffer expected by the (older) kernel. Therefore, we\n" " allocate a buffer that is the maximum of the two sizes. This\n" " ensures that if the supervisor places bytes into the response\n" " structure that are past the response size that the kernel expects,\n" " then the supervisor is not touching an invalid memory location. */\n" "\\&\n" " resp_size = sizes-Eseccomp_notif_resp;\n" " if (sizeof(struct seccomp_notif_resp) E resp_size)\n" " resp_size = sizeof(struct seccomp_notif_resp);\n" "\\&\n" " *resp = malloc(resp_size);\n" " if (*resp == NULL)\n" " err(EXIT_FAILURE, \"malloc-seccomp_notif_resp\");\n" "\\&\n" "}\n" "\\&\n" "/* Handle notifications that arrive via the SECCOMP_RET_USER_NOTIF file\n" " descriptor, \\[aq]notifyFd\\[aq]. */\n" "\\&\n" "static void\n" "handleNotifications(int notifyFd)\n" "{\n" " bool pathOK;\n" " char path[PATH_MAX];\n" " struct seccomp_notif *req;\n" " struct seccomp_notif_resp *resp;\n" " struct seccomp_notif_sizes sizes;\n" "\\&\n" " allocSeccompNotifBuffers(&req, &resp, &sizes);\n" "\\&\n" " /* Loop handling notifications */\n" "\\&\n" " for (;;) {\n" "\\&\n" " /* Wait for next notification, returning info in \\[aq]*req\\[aq] */\n" "\\&\n" " memset(req, 0, sizes.seccomp_notif);\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_RECV, req) == -1) {\n" " if (errno == EINTR)\n" " continue;\n" " err(EXIT_FAILURE, \"\\[rs]tS: ioctl-SECCOMP_IOCTL_NOTIF_RECV\");\n" " }\n" "\\&\n" " printf(\"\\[rs]tS: got notification (ID %#llx) for PID %d\\[rs]n\",\n" " req-Eid, req-Epid);\n" "\\&\n" " /* The only system call that can generate a notification event\n" " is mkdir(2). Nevertheless, we check that the notified system\n" " call is indeed mkdir() as kind of future-proofing of this\n" " code in case the seccomp filter is later modified to\n" " generate notifications for other system calls. */\n" "\\&\n" " if (req-Edata.nr != SYS_mkdir) {\n" " printf(\"\\[rs]tS: notification contained unexpected \"\n" " \"system call number; bye!!!\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " pathOK = getTargetPathname(req, notifyFd, 0, path, sizeof(path));\n" "\\&\n" " /* Prepopulate some fields of the response */\n" "\\&\n" " resp-Eid = req-Eid; /* Response includes notification ID */\n" " resp-Eflags = 0;\n" " resp-Eval = 0;\n" "\\&\n" " /* If getTargetPathname() failed, trigger an EINVAL error\n" " response (sending this response may yield an error if the\n" " failure occurred because the notification ID was no longer\n" " valid); if the directory is in /tmp, then create it on behalf\n" " of the supervisor; if the pathname starts with \\[aq].\\[aq], tell the\n" " kernel to let the target process execute the mkdir();\n" " otherwise, give an error for a directory pathname in any other\n" " location. */\n" "\\&\n" " if (!pathOK) {\n" " resp-Eerror = -EINVAL;\n" " printf(\"\\[rs]tS: spoofing error for invalid pathname (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " } else if (strncmp(path, \"/tmp/\", strlen(\"/tmp/\")) == 0) {\n" " printf(\"\\[rs]tS: executing: mkdir(\\[rs]\"%s\\[rs]\", %#llo)\\[rs]n\",\n" " path, req-Edata.args[1]);\n" "\\&\n" " if (mkdir(path, req-Edata.args[1]) == 0) {\n" " resp-Eerror = 0; /* \"Success\" */\n" " resp-Eval = strlen(path); /* Used as return value of\n" " mkdir() in target */\n" " printf(\"\\[rs]tS: success! spoofed return = %lld\\[rs]n\",\n" " resp-Eval);\n" " } else {\n" "\\&\n" " /* If mkdir() failed in the supervisor, pass the error\n" " back to the target */\n" "\\&\n" " resp-Eerror = -errno;\n" " printf(\"\\[rs]tS: failure! (errno = %d; %s)\\[rs]n\", errno,\n" " strerror(errno));\n" " }\n" " } else if (strncmp(path, \"./\", strlen(\"./\")) == 0) {\n" " resp-Eerror = resp-Eval = 0;\n" " resp-Eflags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;\n" " printf(\"\\[rs]tS: target can execute system call\\[rs]n\");\n" " } else {\n" " resp-Eerror = -EOPNOTSUPP;\n" " printf(\"\\[rs]tS: spoofing error response (%s)\\[rs]n\",\n" " strerror(-resp-Eerror));\n" " }\n" "\\&\n" " /* Send a response to the notification */\n" "\\&\n" " printf(\"\\[rs]tS: sending response \"\n" " \"(flags = %#x; val = %lld; error = %d)\\[rs]n\",\n" " resp-Eflags, resp-Eval, resp-Eerror);\n" "\\&\n" " if (ioctl(notifyFd, SECCOMP_IOCTL_NOTIF_SEND, resp) == -1) {\n" " if (errno == ENOENT)\n" " printf(\"\\[rs]tS: response failed with ENOENT; \"\n" " \"perhaps target process\\[aq]s syscall was \"\n" " \"interrupted by a signal?\\[rs]n\");\n" " else\n" " perror(\"ioctl-SECCOMP_IOCTL_NOTIF_SEND\");\n" " }\n" "\\&\n" " /* If the pathname is just \"/bye\", then the supervisor breaks out\n" " of the loop and terminates. This allows us to see what happens\n" " if the target process makes further calls to mkdir(2). */\n" "\\&\n" " if (strcmp(path, \"/bye\") == 0)\n" " break;\n" " }\n" "\\&\n" " free(req);\n" " free(resp);\n" " printf(\"\\[rs]tS: terminating **********\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" "}\n" "\\&\n" "/* Implementation of the supervisor process:\n" "\\&\n" " (1) obtains the notification file descriptor from \\[aq]sockPair[1]\\[aq]\n" " (2) handles notifications that arrive on that file descriptor. */\n" "\\&\n" "static void\n" "supervisor(int sockPair[2])\n" "{\n" " int notifyFd;\n" "\\&\n" " notifyFd = recvfd(sockPair[1]);\n" "\\&\n" " if (notifyFd == -1)\n" " err(EXIT_FAILURE, \"recvfd\");\n" "\\&\n" " closeSocketPair(sockPair); /* We no longer need the socket pair */\n" "\\&\n" " handleNotifications(notifyFd);\n" "}\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int sockPair[2];\n" " struct sigaction sa;\n" "\\&\n" " setbuf(stdout, NULL);\n" "\\&\n" " if (argc E 2) {\n" " fprintf(stderr, \"At least one pathname argument is required\\[rs]n\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " /* Create a UNIX domain socket that is used to pass the seccomp\n" " notification file descriptor from the target process to the\n" " supervisor process. */\n" "\\&\n" " if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockPair) == -1)\n" " err(EXIT_FAILURE, \"socketpair\");\n" "\\&\n" " /* Create a child process--the \"target\"--that installs seccomp\n" " filtering. The target process writes the seccomp notification\n" " file descriptor onto \\[aq]sockPair[0]\\[aq] and then calls mkdir(2) for\n" " each directory in the command-line arguments. */\n" "\\&\n" " (void) targetProcess(sockPair, &argv[optind]);\n" "\\&\n" " /* Catch SIGCHLD when the target terminates, so that the\n" " supervisor can also terminate. */\n" "\\&\n" " sa.sa_handler = sigchldHandler;\n" " sa.sa_flags = 0;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1)\n" " err(EXIT_FAILURE, \"sigaction\");\n" "\\&\n" " supervisor(sockPair);\n" "\\&\n" " exit(EXIT_SUCCESS);\n" "}\n" #. type: TH #: opensuse-leap-16-1 opensuse-tumbleweed #, no-wrap msgid "Linux man-pages (unreleased)" msgstr "صفحات دليل لينكس (لم تصدر بعد)"