| 1 |
.TH "seccomp_notify_alloc" 3 "30 May 2020" "[email protected]" "libseccomp Documentation" |
| 2 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 3 |
.SH NAME |
| 4 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 5 |
seccomp_notify_alloc, seccomp_notify_free, seccomp_notify_receive, |
| 6 |
seccomp_notify_respond, seccomp_notify_id_valid, seccomp_notify_fd \- Manage seccomp notifications |
| 7 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 8 |
.SH SYNOPSIS |
| 9 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 10 |
.nf |
| 11 |
.B #include <seccomp.h> |
| 12 |
.sp |
| 13 |
.BI "int seccomp_notify_alloc(struct seccomp_notif **" req ", struct seccomp_notif_resp **" resp ")" |
| 14 |
.BI "void seccomp_notify_free(struct seccomp_notif *" req ", struct seccomp_notif_resp *" resp ")" |
| 15 |
.BI "int seccomp_notify_receive(int " fd ", struct seccomp_notif *" req ")" |
| 16 |
.BI "int seccomp_notify_respond(int " fd ", struct seccomp_notif_resp *" resp ")" |
| 17 |
.BI "int seccomp_notify_id_valid(int " fd ", uint64_t " id ")" |
| 18 |
.BI "int seccomp_notify_fd(const scmp_filter_ctx " ctx ")" |
| 19 |
.sp |
| 20 |
Link with \fI\-lseccomp\fP. |
| 21 |
.fi |
| 22 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 23 |
.SH DESCRIPTION |
| 24 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 25 |
.P |
| 26 |
The |
| 27 |
.BR seccomp_notify_alloc () |
| 28 |
function dynamically allocates enough memory for a seccomp notification and |
| 29 |
response. Note that one should always use these functions and not depend on the |
| 30 |
structure sizes in headers, since the size can vary depending on the kernel |
| 31 |
version. This function takes care to ask the kernel how big each structure |
| 32 |
should be, and allocates the right amount of memory. The |
| 33 |
.BR seccomp_notify_free () |
| 34 |
function frees memory allocated by |
| 35 |
.BR seccomp_notify_alloc (). |
| 36 |
.P |
| 37 |
The |
| 38 |
.BR seccomp_notify_receive () |
| 39 |
function receives a notification from a seccomp notify fd (obtained from |
| 40 |
.BR seccomp_notify_fd ()). |
| 41 |
.P |
| 42 |
The |
| 43 |
.BR seccomp_notify_respond () |
| 44 |
function sends a response to a particular notification. The id field should be |
| 45 |
the same as the id from the request, so that the kernel knows which request |
| 46 |
this response corresponds to. |
| 47 |
.P |
| 48 |
The |
| 49 |
.BR seccomp_notify_id_valid () |
| 50 |
function checks to see if the syscall from a particular notification request is |
| 51 |
still valid, i.e. if the task is still alive. See NOTES below for details on |
| 52 |
race conditions. |
| 53 |
.P |
| 54 |
The |
| 55 |
.BR seccomp_notify_fd () |
| 56 |
returns the notification fd of a filter after it has been loaded. |
| 57 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 58 |
.SH RETURN VALUE |
| 59 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 60 |
The |
| 61 |
.BR seccomp_notify_fd () |
| 62 |
returns the notification fd of the loaded filter, -1 if a notification fd has |
| 63 |
not yet been created, and -EINVAL if the filter context is invalid. |
| 64 |
.P |
| 65 |
The |
| 66 |
.BR seccomp_notify_id_valid () |
| 67 |
returns 0 if the id is valid, and -ENOENT if it is not. |
| 68 |
.P |
| 69 |
The |
| 70 |
.BR seccomp_notify_alloc (), |
| 71 |
.BR seccomp_notify_receive (), |
| 72 |
and |
| 73 |
.BR seccomp_notify_respond () |
| 74 |
functions return zero on success, or one of the following error codes on |
| 75 |
failure: |
| 76 |
.TP |
| 77 |
.B -ECANCELED |
| 78 |
There was a system failure beyond the control of the library, check the |
| 79 |
\fIerrno\fP value for more information. |
| 80 |
.TP |
| 81 |
.B -EFAULT |
| 82 |
Internal libseccomp failure. |
| 83 |
.TP |
| 84 |
.B -ENOMEM |
| 85 |
The library was unable to allocate enough memory. |
| 86 |
.TP |
| 87 |
.B -EOPNOTSUPP |
| 88 |
The library doesn't support the particular operation. |
| 89 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 90 |
.SH NOTES |
| 91 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 92 |
.P |
| 93 |
Care should be taken to avoid two different time of check/time of use errors. |
| 94 |
First, after opening any resources relevant to the pid for a notification (e.g. |
| 95 |
/proc/pid/mem for reading tracee memory to make policy decisions), applications |
| 96 |
should call |
| 97 |
.BR seccomp_notify_id_valid () |
| 98 |
to make sure that the resources the application has opened correspond to the |
| 99 |
right pid, i.e. that the pid didn't die and a different task take its place. |
| 100 |
.P |
| 101 |
Second, the classic time of check/time of use issue with seccomp memory should |
| 102 |
also be avoided: applications should copy any memory they wish to use to make |
| 103 |
decisions from the tracee into its own address space before applying any policy |
| 104 |
decisions, since a multi-threaded tracee may edit the memory at any time, |
| 105 |
including after it's used to make a policy decision. |
| 106 |
.P |
| 107 |
A complete example of how to avoid these two races is available in the Linux |
| 108 |
Kernel source tree at |
| 109 |
.BR /samples/seccomp/user-trap.c. |
| 110 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 111 |
.SH AUTHOR |
| 112 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 113 |
Tycho Andersen <[email protected]> |
| 114 |
.\" ////////////////////////////////////////////////////////////////////////// |