1seccomp_arch_add(3) libseccomp Documentation seccomp_arch_add(3)
2
3
4
6 seccomp_arch_add, seccomp_arch_remove, seccomp_arch_exist, sec‐
7 comp_arch_native - Manage seccomp filter architectures
8
10 #include <seccomp.h>
11
12 typedef void * scmp_filter_ctx;
13
14 #define SCMP_ARCH_NATIVE
15 #define SCMP_ARCH_X86
16 #define SCMP_ARCH_X86_64
17
18 uint32_t seccomp_arch_resolve_name(const char *arch_name);
19 uint32_t seccomp_arch_native();
20 int seccomp_arch_exist(const scmp_filter_ctx ctx, uint32_t arch_token);
21 int seccomp_arch_add(scmp_filter_ctx ctx, uint32_t arch_token);
22 int seccomp_arch_remove(scmp_filter_ctx ctx, uint32_t arch_token);
23
24 Link with -lseccomp.
25
27 The seccomp_arch_exist() function tests to see if a given architecture
28 has been added to the seccomp filter in ctx , where the sec‐
29 comp_arch_add() and seccomp_arch_remove() add and remove, respectively,
30 architectures from the seccomp filter. In all three functions, the
31 architecture values given in arch_token should be the SCMP_ARCH_*
32 defined constants; with the SCMP_ARCH_NATIVE constant always referring
33 to the native compiled architecture. The seccomp_arch_native() func‐
34 tion returns the system's architecture such that it will match one of
35 the SCMP_ARCH_* constants. While the seccomp_arch_resolve_name() func‐
36 tion also returns a SCMP_ARCH_* constant, the returned token matches
37 the name of the architecture passed as an argument to the function.
38
39 When a seccomp filter is initialized with the call to seccomp_init(3)
40 the native architecture is automatically added to the filter.
41
42 While it is possible to remove all architectures from a filter, most of
43 the libseccomp APIs will fail if the filter does not contain at least
44 one architecture.
45
46 When adding a new architecture to an existing filter, the existing
47 rules will not be added to the new architecture. However, rules added
48 after adding the new architecture will be added to all of the architec‐
49 tures in the filter.
50
52 The seccomp_arch_add() and seccomp_arch_remove() functions return zero
53 on success, negative errno values on failure. The seccomp_arch_exist()
54 function returns zero if the architecture exists, -EEXIST if it does
55 not, and other negative errno values on failure.
56
58 #include <seccomp.h>
59
60 int main(int argc, char *argv[])
61 {
62 int rc = -1;
63 scmp_filter_ctx ctx;
64
65 ctx = seccomp_init(SCMP_ACT_KILL);
66 if (ctx == NULL)
67 goto out;
68
69 if (seccomp_arch_exist(ctx, SCMP_ARCH_X86) == -EEXIST) {
70 rc = seccomp_arch_add(ctx, SCMP_ARCH_X86);
71 if (rc != 0)
72 goto out_all;
73 rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
74 if (rc != 0)
75 goto out_all;
76 }
77
78 /* ... */
79
80 out:
81 seccomp_release(ctx);
82 return -rc;
83 }
84
86 While the seccomp filter can be generated independent of the kernel,
87 kernel support is required to load and enforce the seccomp filter gen‐
88 erated by libseccomp.
89
90 The libseccomp project site, with more information and the source code
91 repository, can be found at https://github.com/seccomp/libseccomp.
92 This tool, as well as the libseccomp library, is currently under devel‐
93 opment, please report any bugs at the project site or directly to the
94 author.
95
97 Paul Moore <paul@paul-moore.com>
98
100 seccomp_init(3), seccomp_reset(3), seccom_merge(3)
101
102
103
104paul@paul-moore.com 7 May 2014 seccomp_arch_add(3)