| 1 |
.TH "seccomp_arch_add" 3 "15 June 2020" "[email protected]" "libseccomp Documentation" |
| 2 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 3 |
.SH NAME |
| 4 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 5 |
seccomp_arch_add, seccomp_arch_remove, seccomp_arch_exist, seccomp_arch_native \- Manage seccomp filter architectures |
| 6 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 7 |
.SH SYNOPSIS |
| 8 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 9 |
.nf |
| 10 |
.B #include <seccomp.h> |
| 11 |
.sp |
| 12 |
.B typedef void * scmp_filter_ctx; |
| 13 |
.sp |
| 14 |
.B #define SCMP_ARCH_NATIVE |
| 15 |
.B #define SCMP_ARCH_X86 |
| 16 |
.B #define SCMP_ARCH_X86_64 |
| 17 |
.B #define SCMP_ARCH_X32 |
| 18 |
.B #define SCMP_ARCH_ARM |
| 19 |
.B #define SCMP_ARCH_AARCH64 |
| 20 |
.B #define SCMP_ARCH_LOONGARCH64 |
| 21 |
.B #define SCMP_ARCH_M68K |
| 22 |
.B #define SCMP_ARCH_MIPS |
| 23 |
.B #define SCMP_ARCH_MIPS64 |
| 24 |
.B #define SCMP_ARCH_MIPS64N32 |
| 25 |
.B #define SCMP_ARCH_MIPSEL |
| 26 |
.B #define SCMP_ARCH_MIPSEL64 |
| 27 |
.B #define SCMP_ARCH_MIPSEL64N32 |
| 28 |
.B #define SCMP_ARCH_PPC |
| 29 |
.B #define SCMP_ARCH_PPC64 |
| 30 |
.B #define SCMP_ARCH_PPC64LE |
| 31 |
.B #define SCMP_ARCH_S390 |
| 32 |
.B #define SCMP_ARCH_S390X |
| 33 |
.B #define SCMP_ARCH_SH |
| 34 |
.B #define SCMP_ARCH_SHEB |
| 35 |
.B #define SCMP_ARCH_PARISC |
| 36 |
.B #define SCMP_ARCH_PARISC64 |
| 37 |
.B #define SCMP_ARCH_RISCV64 |
| 38 |
.sp |
| 39 |
.BI "uint32_t seccomp_arch_resolve_name(const char *" arch_name ");" |
| 40 |
.BI "uint32_t seccomp_arch_native();" |
| 41 |
.BI "int seccomp_arch_exist(const scmp_filter_ctx " ctx ", uint32_t " arch_token ");" |
| 42 |
.BI "int seccomp_arch_add(scmp_filter_ctx " ctx ", uint32_t " arch_token ");" |
| 43 |
.BI "int seccomp_arch_remove(scmp_filter_ctx " ctx ", uint32_t " arch_token ");" |
| 44 |
.sp |
| 45 |
Link with \fI\-lseccomp\fP. |
| 46 |
.fi |
| 47 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 48 |
.SH DESCRIPTION |
| 49 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 50 |
.P |
| 51 |
The |
| 52 |
.BR seccomp_arch_exist () |
| 53 |
function tests to see if a given architecture has been added to the seccomp |
| 54 |
filter in |
| 55 |
.IR ctx , |
| 56 |
where the |
| 57 |
.BR seccomp_arch_add () |
| 58 |
and |
| 59 |
.BR seccomp_arch_remove () |
| 60 |
add and remove, respectively, architectures from the seccomp filter. In all |
| 61 |
three functions, the architecture values given in |
| 62 |
.I arch_token |
| 63 |
should be the |
| 64 |
.BR SCMP_ARCH_* |
| 65 |
defined constants; with the |
| 66 |
.BR SCMP_ARCH_NATIVE |
| 67 |
constant always referring to the native compiled architecture. The |
| 68 |
.BR seccomp_arch_native () |
| 69 |
function returns the system's architecture such that it will match one of the |
| 70 |
.BR SCMP_ARCH_* |
| 71 |
constants. While the |
| 72 |
.BR seccomp_arch_resolve_name () |
| 73 |
function also returns a |
| 74 |
.BR SCMP_ARCH_* |
| 75 |
constant, the returned token matches the name of the architecture |
| 76 |
passed as an argument to the function. |
| 77 |
.P |
| 78 |
When a seccomp filter is initialized with the call to |
| 79 |
.BR seccomp_init (3) |
| 80 |
the native architecture is automatically added to the filter. |
| 81 |
.P |
| 82 |
While it is possible to remove all architectures from a filter, most of the |
| 83 |
libseccomp APIs will fail if the filter does not contain at least one |
| 84 |
architecture. |
| 85 |
.P |
| 86 |
When adding a new architecture to an existing filter, the existing rules will |
| 87 |
not be added to the new architecture. However, rules added after adding the |
| 88 |
new architecture will be added to all of the architectures in the filter. |
| 89 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 90 |
.SH RETURN VALUE |
| 91 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 92 |
The |
| 93 |
.BR seccomp_arch_add (), |
| 94 |
.BR seccomp_arch_remove (), |
| 95 |
and |
| 96 |
.BR seccomp_arch_exist () |
| 97 |
functions return zero on success or one of the following error codes on |
| 98 |
failure: |
| 99 |
.TP |
| 100 |
.B -EDOM |
| 101 |
Architecture specific failure. |
| 102 |
.TP |
| 103 |
.B -EEXIST |
| 104 |
In the case of |
| 105 |
.BR seccomp_arch_add () |
| 106 |
the architecture already exists and in the case of |
| 107 |
.BR seccomp_arch_remove () |
| 108 |
the architecture does not exist. |
| 109 |
.TP |
| 110 |
.B -EINVAL |
| 111 |
Invalid input, either the context or architecture token is invalid. |
| 112 |
.TP |
| 113 |
.B -ENOMEM |
| 114 |
The library was unable to allocate enough memory. |
| 115 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 116 |
.SH EXAMPLES |
| 117 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 118 |
.nf |
| 119 |
#include <seccomp.h> |
| 120 |
|
| 121 |
int main(int argc, char *argv[]) |
| 122 |
{ |
| 123 |
int rc = \-1; |
| 124 |
scmp_filter_ctx ctx; |
| 125 |
|
| 126 |
ctx = seccomp_init(SCMP_ACT_KILL); |
| 127 |
if (ctx == NULL) |
| 128 |
goto out; |
| 129 |
|
| 130 |
if (seccomp_arch_exist(ctx, SCMP_ARCH_X86) == \-EEXIST) { |
| 131 |
rc = seccomp_arch_add(ctx, SCMP_ARCH_X86); |
| 132 |
if (rc != 0) |
| 133 |
goto out_all; |
| 134 |
rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE); |
| 135 |
if (rc != 0) |
| 136 |
goto out_all; |
| 137 |
} |
| 138 |
|
| 139 |
/* ... */ |
| 140 |
|
| 141 |
out: |
| 142 |
seccomp_release(ctx); |
| 143 |
return \-rc; |
| 144 |
} |
| 145 |
.fi |
| 146 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 147 |
.SH NOTES |
| 148 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 149 |
.P |
| 150 |
While the seccomp filter can be generated independent of the kernel, kernel |
| 151 |
support is required to load and enforce the seccomp filter generated by |
| 152 |
libseccomp. |
| 153 |
.P |
| 154 |
The libseccomp project site, with more information and the source code |
| 155 |
repository, can be found at https://github.com/seccomp/libseccomp. This tool, |
| 156 |
as well as the libseccomp library, is currently under development, please |
| 157 |
report any bugs at the project site or directly to the author. |
| 158 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 159 |
.SH AUTHOR |
| 160 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 161 |
Paul Moore <[email protected]> |
| 162 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 163 |
.SH SEE ALSO |
| 164 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 165 |
.BR seccomp_init (3), |
| 166 |
.BR seccomp_reset (3), |
| 167 |
.BR seccomp_merge (3) |