| 1 |
.TH "seccomp_init" 3 "30 May 2020" "[email protected]" "libseccomp Documentation" |
| 2 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 3 |
.SH NAME |
| 4 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 5 |
seccomp_init, seccomp_reset \- Initialize the seccomp filter state |
| 6 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 7 |
.SH SYNOPSIS |
| 8 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 9 |
.nf |
| 10 |
.B #include <seccomp.h> |
| 11 |
.sp |
| 12 |
.B typedef void * scmp_filter_ctx; |
| 13 |
.sp |
| 14 |
.BI "scmp_filter_ctx seccomp_init(uint32_t " def_action ");" |
| 15 |
.BI "int seccomp_reset(scmp_filter_ctx " ctx ", uint32_t " def_action ");" |
| 16 |
.sp |
| 17 |
Link with \fI\-lseccomp\fP. |
| 18 |
.fi |
| 19 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 20 |
.SH DESCRIPTION |
| 21 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 22 |
.P |
| 23 |
The |
| 24 |
.BR seccomp_init () |
| 25 |
and |
| 26 |
.BR seccomp_reset () |
| 27 |
functions (re)initialize the internal seccomp filter state, prepares it for |
| 28 |
use, and sets the default action based on the |
| 29 |
.I def_action |
| 30 |
parameter. The |
| 31 |
.BR seccomp_init () |
| 32 |
function must be called before any other libseccomp functions as the rest |
| 33 |
of the library API will fail if the filter context is not initialized properly. |
| 34 |
The |
| 35 |
.BR seccomp_reset () |
| 36 |
function releases the existing filter context state before reinitializing it |
| 37 |
and can only be called after a call to |
| 38 |
.BR seccomp_init () |
| 39 |
has succeeded. If |
| 40 |
.BR seccomp_reset () |
| 41 |
is called with a NULL filter, it resets the library's global task state, |
| 42 |
including any notification file descriptors retrieved by |
| 43 |
.BR seccomp_notify_fd (3). |
| 44 |
Normally this is not needed, but it may be required to continue using the |
| 45 |
library after a |
| 46 |
.BR fork () |
| 47 |
or |
| 48 |
.BR clone () |
| 49 |
call to ensure the API level and user notification state is properly reset. |
| 50 |
.P |
| 51 |
When the caller is finished configuring the seccomp filter and has loaded it |
| 52 |
into the kernel, the caller should call |
| 53 |
.BR seccomp_release (3) |
| 54 |
to release all of the filter context state. |
| 55 |
.P |
| 56 |
Valid |
| 57 |
.I def_action |
| 58 |
values are as follows: |
| 59 |
.TP |
| 60 |
.B SCMP_ACT_KILL |
| 61 |
The thread will be terminated by the kernel with SIGSYS when it calls a syscall |
| 62 |
that does not match any of the configured seccomp filter rules. The thread |
| 63 |
will not be able to catch the signal. |
| 64 |
.TP |
| 65 |
.B SCMP_ACT_KILL_PROCESS |
| 66 |
The entire process will be terminated by the kernel with SIGSYS when it calls a |
| 67 |
syscall that does not match any of the configured seccomp filter rules. |
| 68 |
.TP |
| 69 |
.B SCMP_ACT_TRAP |
| 70 |
The thread will be sent a SIGSYS signal when it calls a syscall that does not |
| 71 |
match any of the configured seccomp filter rules. It may catch this and change |
| 72 |
its behavior accordingly. When using SA_SIGINFO with |
| 73 |
.BR sigaction (2), |
| 74 |
si_code will be set to SYS_SECCOMP, si_syscall will be set to the syscall that |
| 75 |
failed the rules, and si_arch will be set to the AUDIT_ARCH for the active ABI. |
| 76 |
.TP |
| 77 |
.B SCMP_ACT_ERRNO(uint16_t errno) |
| 78 |
The thread will receive a return value of |
| 79 |
.I errno |
| 80 |
when it calls a syscall that does not match any of the configured seccomp filter |
| 81 |
rules. |
| 82 |
.TP |
| 83 |
.B SCMP_ACT_TRACE(uint16_t msg_num) |
| 84 |
If the thread is being traced and the tracing process specified the |
| 85 |
.B PTRACE_O_TRACESECCOMP |
| 86 |
option in the call to |
| 87 |
.BR ptrace (2), |
| 88 |
the tracing process will be notified, via |
| 89 |
.BR PTRACE_EVENT_SECCOMP , |
| 90 |
and the value provided in |
| 91 |
.I msg_num |
| 92 |
can be retrieved using the |
| 93 |
.B PTRACE_GETEVENTMSG |
| 94 |
option. |
| 95 |
.TP |
| 96 |
.B SCMP_ACT_LOG |
| 97 |
The seccomp filter will have no effect on the thread calling the syscall if it |
| 98 |
does not match any of the configured seccomp filter rules but the syscall will |
| 99 |
be logged. |
| 100 |
.TP |
| 101 |
.B SCMP_ACT_ALLOW |
| 102 |
The seccomp filter will have no effect on the thread calling the syscall if it |
| 103 |
does not match any of the configured seccomp filter rules. |
| 104 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 105 |
.SH RETURN VALUE |
| 106 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 107 |
The |
| 108 |
.BR seccomp_init () |
| 109 |
function returns a filter context on success, NULL on failure. The |
| 110 |
.BR seccomp_reset () |
| 111 |
function returns zero on success or one of the following error codes on |
| 112 |
failure: |
| 113 |
.TP |
| 114 |
.B -EINVAL |
| 115 |
Invalid input, either the context or action is invalid. |
| 116 |
.TP |
| 117 |
.B -ENOMEM |
| 118 |
The library was unable to allocate enough memory. |
| 119 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 120 |
.SH EXAMPLES |
| 121 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 122 |
.nf |
| 123 |
#include <seccomp.h> |
| 124 |
|
| 125 |
int main(int argc, char *argv[]) |
| 126 |
{ |
| 127 |
int rc = \-1; |
| 128 |
scmp_filter_ctx ctx; |
| 129 |
|
| 130 |
ctx = seccomp_init(SCMP_ACT_KILL); |
| 131 |
if (ctx == NULL) |
| 132 |
goto out; |
| 133 |
|
| 134 |
/* ... */ |
| 135 |
|
| 136 |
rc = seccomp_reset(ctx, SCMP_ACT_KILL); |
| 137 |
if (rc < 0) |
| 138 |
goto out; |
| 139 |
|
| 140 |
/* ... */ |
| 141 |
|
| 142 |
out: |
| 143 |
seccomp_release(ctx); |
| 144 |
return \-rc; |
| 145 |
} |
| 146 |
.fi |
| 147 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 148 |
.SH NOTES |
| 149 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 150 |
.P |
| 151 |
While the seccomp filter can be generated independent of the kernel, kernel |
| 152 |
support is required to load and enforce the seccomp filter generated by |
| 153 |
libseccomp. |
| 154 |
.P |
| 155 |
The libseccomp project site, with more information and the source code |
| 156 |
repository, can be found at https://github.com/seccomp/libseccomp. This tool, |
| 157 |
as well as the libseccomp library, is currently under development, please |
| 158 |
report any bugs at the project site or directly to the author. |
| 159 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 160 |
.SH AUTHOR |
| 161 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 162 |
Paul Moore <[email protected]> |
| 163 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 164 |
.SH SEE ALSO |
| 165 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 166 |
.BR seccomp_release (3) |