| 1 |
.TH "seccomp_attr_set" 3 "21 September 2022" "[email protected]" "libseccomp Documentation" |
| 2 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 3 |
.SH NAME |
| 4 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 5 |
seccomp_attr_set, seccomp_attr_get \- Manage the seccomp filter attributes |
| 6 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 7 |
.SH SYNOPSIS |
| 8 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 9 |
.nf |
| 10 |
.B #include <seccomp.h> |
| 11 |
.sp |
| 12 |
.B typedef void * scmp_filter_ctx; |
| 13 |
.B enum scmp_filter_attr; |
| 14 |
.sp |
| 15 |
.BI "int seccomp_attr_set(scmp_filter_ctx " ctx "," |
| 16 |
.BI " enum scmp_filter_attr " attr ", uint32_t " value ");" |
| 17 |
.BI "int seccomp_attr_get(scmp_filter_ctx " ctx "," |
| 18 |
.BI " enum scmp_filter_attr " attr ", uint32_t *" value ");" |
| 19 |
.sp |
| 20 |
Link with \fI\-lseccomp\fP. |
| 21 |
.fi |
| 22 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 23 |
.SH DESCRIPTION |
| 24 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 25 |
.P |
| 26 |
The |
| 27 |
.BR seccomp_attr_set () |
| 28 |
function sets the different seccomp filter attributes while the |
| 29 |
.BR seccomp_attr_get () |
| 30 |
function fetches the filter attributes. The seccomp filter attributes are |
| 31 |
tunable values that affect how the library behaves when generating and loading |
| 32 |
the seccomp filter into the kernel. The attributes are reset to their default |
| 33 |
values whenever the filter is initialized or reset via |
| 34 |
.BR seccomp_init (3) |
| 35 |
or |
| 36 |
.BR seccomp_reset (3). |
| 37 |
.P |
| 38 |
The filter context |
| 39 |
.I ctx |
| 40 |
is the value returned by the call to |
| 41 |
.BR seccomp_init (3). |
| 42 |
.P |
| 43 |
Valid |
| 44 |
.I attr |
| 45 |
values are as follows: |
| 46 |
.TP |
| 47 |
.B SCMP_FLTATR_ACT_DEFAULT |
| 48 |
The default filter action as specified in the call to |
| 49 |
.BR seccomp_init (3) |
| 50 |
or |
| 51 |
.BR seccomp_reset (3). |
| 52 |
This attribute is read-only. |
| 53 |
.TP |
| 54 |
.B SCMP_FLTATR_ACT_BADARCH |
| 55 |
The filter action taken when the loaded filter does not match the architecture |
| 56 |
of the executing application. Defaults to the |
| 57 |
.B SCMP_ACT_KILL |
| 58 |
action. |
| 59 |
.TP |
| 60 |
.B SCMP_FLTATR_CTL_NNP |
| 61 |
A flag to specify if the NO_NEW_PRIVS functionality should be enabled before |
| 62 |
loading the seccomp filter into the kernel. Setting this to off |
| 63 |
.RI ( value |
| 64 |
== 0) results in no action, meaning that loading the seccomp filter into the |
| 65 |
kernel will fail if CAP_SYS_ADMIN is missing and NO_NEW_PRIVS has not been |
| 66 |
externally set. Defaults to on |
| 67 |
.RI ( value |
| 68 |
== 1). |
| 69 |
.TP |
| 70 |
.B SCMP_FLTATR_CTL_TSYNC |
| 71 |
A flag to specify if the kernel should attempt to synchronize the filters |
| 72 |
across all threads on |
| 73 |
.BR seccomp_load (3). |
| 74 |
If the kernel is unable to synchronize all of the thread then the load |
| 75 |
operation will fail. This flag is only available on Linux Kernel 3.17 or |
| 76 |
greater; attempting to enable this flag on earlier kernels will result in an |
| 77 |
error being returned. Defaults to off |
| 78 |
.RI ( value |
| 79 |
== 0). |
| 80 |
.TP |
| 81 |
.B SCMP_FLTATR_API_TSKIP |
| 82 |
A flag to specify if libseccomp should allow filter rules to be created for |
| 83 |
the -1 syscall. The -1 syscall value can be used by tracer programs to skip |
| 84 |
specific syscall invocations, see |
| 85 |
.BR seccomp (2) |
| 86 |
for more information. Defaults to off |
| 87 |
.RI ( value |
| 88 |
== 0). |
| 89 |
.TP |
| 90 |
.B SCMP_FLTATR_CTL_LOG |
| 91 |
A flag to specify if the kernel should log all filter actions taken except for |
| 92 |
the |
| 93 |
.BR SCMP_ACT_ALLOW |
| 94 |
action. Defaults to off |
| 95 |
.RI ( value |
| 96 |
== 0). |
| 97 |
.TP |
| 98 |
.B SCMP_FLTATR_CTL_SSB |
| 99 |
A flag to disable Speculative Store Bypass mitigations for this filter. |
| 100 |
Defaults to off |
| 101 |
.RI ( value |
| 102 |
== 0). |
| 103 |
.TP |
| 104 |
.B SCMP_FLTATR_CTL_OPTIMIZE |
| 105 |
A flag to specify the optimization level of the seccomp filter. By default |
| 106 |
libseccomp generates a set of sequential \'if\' statements for each rule in |
| 107 |
the filter. |
| 108 |
.BR seccomp_syscall_priority (3) |
| 109 |
can be used to prioritize the order for the default cause. The binary tree |
| 110 |
optimization sorts by syscall numbers and generates consistent |
| 111 |
.BR O(log\ n) |
| 112 |
filter traversal for every rule in the filter. The binary tree may be |
| 113 |
advantageous for large filters. Note that |
| 114 |
.BR seccomp_syscall_priority (3) |
| 115 |
is ignored when SCMP_FLTATR_CTL_OPTIMIZE == 2. |
| 116 |
.RS |
| 117 |
.P |
| 118 |
The different optimization levels are described below: |
| 119 |
.TP |
| 120 |
.B 0 |
| 121 |
Reserved value, not currently used. |
| 122 |
.TP |
| 123 |
.B 1 |
| 124 |
Rules sorted by priority and complexity (DEFAULT). |
| 125 |
.TP |
| 126 |
.B 2 |
| 127 |
Binary tree sorted by syscall number. |
| 128 |
.RE |
| 129 |
.TP |
| 130 |
.B SCMP_FLTATR_API_SYSRAWRC |
| 131 |
A flag to specify if libseccomp should pass system error codes back to the |
| 132 |
caller instead of the default -ECANCELED. Defaults to off |
| 133 |
.RI ( value |
| 134 |
== 0). |
| 135 |
.TP |
| 136 |
.B SCMP_FLTATR_CTL_WAITKILL |
| 137 |
A flag to specify if libseccomp should request wait killable semantics when |
| 138 |
possible. Defaults to off |
| 139 |
.RI ( value |
| 140 |
== 0). |
| 141 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 142 |
.SH RETURN VALUE |
| 143 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 144 |
Returns zero on success or one of the following error codes on |
| 145 |
failure: |
| 146 |
.TP |
| 147 |
.B -EACCES |
| 148 |
Setting the attribute with the given value is not allowed. |
| 149 |
.TP |
| 150 |
.B -EEXIST |
| 151 |
The attribute does not exist. |
| 152 |
.TP |
| 153 |
.B -EINVAL |
| 154 |
Invalid input, either the context or architecture token is invalid. |
| 155 |
.TP |
| 156 |
.B -EOPNOTSUPP |
| 157 |
The library doesn't support the particular operation. |
| 158 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 159 |
.SH EXAMPLES |
| 160 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 161 |
.nf |
| 162 |
#include <seccomp.h> |
| 163 |
|
| 164 |
int main(int argc, char *argv[]) |
| 165 |
{ |
| 166 |
int rc = \-1; |
| 167 |
scmp_filter_ctx ctx; |
| 168 |
|
| 169 |
ctx = seccomp_init(SCMP_ACT_ALLOW); |
| 170 |
if (ctx == NULL) |
| 171 |
goto out; |
| 172 |
|
| 173 |
/* ... */ |
| 174 |
|
| 175 |
rc = seccomp_attr_set(ctx, SCMP_FLTATR_ACT_BADARCH, SCMP_ACT_TRAP); |
| 176 |
if (rc < 0) |
| 177 |
goto out; |
| 178 |
|
| 179 |
/* ... */ |
| 180 |
|
| 181 |
out: |
| 182 |
seccomp_release(ctx); |
| 183 |
return \-rc; |
| 184 |
} |
| 185 |
.fi |
| 186 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 187 |
.SH NOTES |
| 188 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 189 |
.P |
| 190 |
While the seccomp filter can be generated independent of the kernel, kernel |
| 191 |
support is required to load and enforce the seccomp filter generated by |
| 192 |
libseccomp. |
| 193 |
.P |
| 194 |
The libseccomp project site, with more information and the source code |
| 195 |
repository, can be found at https://github.com/seccomp/libseccomp. This tool, |
| 196 |
as well as the libseccomp library, is currently under development, please |
| 197 |
report any bugs at the project site or directly to the author. |
| 198 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 199 |
.SH AUTHOR |
| 200 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 201 |
Paul Moore <[email protected]> |
| 202 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 203 |
.SH SEE ALSO |
| 204 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 205 |
.BR seccomp_init (3), |
| 206 |
.BR seccomp_reset (3), |
| 207 |
.BR seccomp_load (3), |
| 208 |
.BR seccomp (2) |