| 1 |
.TH "seccomp_merge" 3 "30 May 2020" "[email protected]" "libseccomp Documentation" |
| 2 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 3 |
.SH NAME |
| 4 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 5 |
seccomp_merge \- Merge two seccomp filters |
| 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 "int seccomp_merge(scmp_filter_ctx " dst ", scmp_filter_ctx " src ");" |
| 15 |
.sp |
| 16 |
Link with \fI\-lseccomp\fP. |
| 17 |
.fi |
| 18 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 19 |
.SH DESCRIPTION |
| 20 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 21 |
.P |
| 22 |
The |
| 23 |
.BR seccomp_merge () |
| 24 |
function merges the seccomp filter in |
| 25 |
.I src |
| 26 |
with the filter in |
| 27 |
.I dst |
| 28 |
and stores the resulting in the |
| 29 |
.I dst |
| 30 |
filter. If successful, the |
| 31 |
.I src |
| 32 |
seccomp filter is released and all internal memory associated with the filter |
| 33 |
is freed; there is no need to call |
| 34 |
.BR seccomp_release (3) |
| 35 |
on |
| 36 |
.I src |
| 37 |
and the caller should discard any references to the filter. |
| 38 |
.P |
| 39 |
In order to merge two seccomp filters, both filters must have the same |
| 40 |
attribute values and no overlapping architectures. |
| 41 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 42 |
.SH RETURN VALUE |
| 43 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 44 |
Returns zero on success or one of the following error codes on |
| 45 |
failure: |
| 46 |
.TP |
| 47 |
.B -EDOM |
| 48 |
Unable to merge the filters due to architecture issues, e.g. byte endian |
| 49 |
mismatches. |
| 50 |
.TP |
| 51 |
.B -EEXIST |
| 52 |
The architecture already exists in the filter. |
| 53 |
.TP |
| 54 |
.B -EINVAL |
| 55 |
One of the filters is invalid. |
| 56 |
.TP |
| 57 |
.B -ENOMEM |
| 58 |
The library was unable to allocate enough memory. |
| 59 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 60 |
.SH EXAMPLES |
| 61 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 62 |
.nf |
| 63 |
#include <seccomp.h> |
| 64 |
|
| 65 |
int main(int argc, char *argv[]) |
| 66 |
{ |
| 67 |
int rc = \-1; |
| 68 |
scmp_filter_ctx ctx_32, ctx_64; |
| 69 |
|
| 70 |
ctx_32 = seccomp_init(SCMP_ACT_KILL); |
| 71 |
if (ctx_32 == NULL) |
| 72 |
goto out_all; |
| 73 |
ctx_64 = seccomp_init(SCMP_ACT_KILL); |
| 74 |
if (ctx_64 == NULL) |
| 75 |
goto out_all; |
| 76 |
|
| 77 |
if (seccomp_arch_exist(ctx_32, SCMP_ARCH_X86) == \-EEXIST) { |
| 78 |
rc = seccomp_arch_add(ctx_32, SCMP_ARCH_X86); |
| 79 |
if (rc != 0) |
| 80 |
goto out_all; |
| 81 |
rc = seccomp_arch_remove(ctx_32, SCMP_ARCH_NATIVE); |
| 82 |
if (rc != 0) |
| 83 |
goto out_all; |
| 84 |
} |
| 85 |
if (seccomp_arch_exist(ctx_64, SCMP_ARCH_X86_64) == \-EEXIST) { |
| 86 |
rc = seccomp_arch_add(ctx_64, SCMP_ARCH_X86_64); |
| 87 |
if (rc != 0) |
| 88 |
goto out_all; |
| 89 |
rc = seccomp_arch_remove(ctx_64, SCMP_ARCH_NATIVE); |
| 90 |
if (rc != 0) |
| 91 |
goto out_all; |
| 92 |
} |
| 93 |
|
| 94 |
/* ... */ |
| 95 |
|
| 96 |
rc = seccomp_merge(ctx_64, ctx_32); |
| 97 |
if (rc != 0) |
| 98 |
goto out_all; |
| 99 |
|
| 100 |
/* NOTE: the 'ctx_32' filter is no longer valid at this point */ |
| 101 |
|
| 102 |
/* ... */ |
| 103 |
|
| 104 |
out: |
| 105 |
seccomp_release(ctx_64); |
| 106 |
return \-rc; |
| 107 |
out_all: |
| 108 |
seccomp_release(ctx_32); |
| 109 |
goto out; |
| 110 |
} |
| 111 |
.fi |
| 112 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 113 |
.SH NOTES |
| 114 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 115 |
.P |
| 116 |
While the seccomp filter can be generated independent of the kernel, kernel |
| 117 |
support is required to load and enforce the seccomp filter generated by |
| 118 |
libseccomp. |
| 119 |
.P |
| 120 |
The libseccomp project site, with more information and the source code |
| 121 |
repository, can be found at https://github.com/seccomp/libseccomp. This tool, |
| 122 |
as well as the libseccomp library, is currently under development, please |
| 123 |
report any bugs at the project site or directly to the author. |
| 124 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 125 |
.SH AUTHOR |
| 126 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 127 |
Paul Moore <[email protected]> |
| 128 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 129 |
.SH SEE ALSO |
| 130 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 131 |
.BR seccomp_init (3), |
| 132 |
.BR seccomp_reset (3), |
| 133 |
.BR seccomp_arch_add (3), |
| 134 |
.BR seccomp_arch_remove (3), |
| 135 |
.BR seccomp_attr_get (3), |
| 136 |
.BR seccomp_attr_set (3) |