Debian Codegraph @

doc/man/man3/seccomp_export_bpf.3

raw
1 .TH "seccomp_export_bpf" 3 "30 May 2020" "[email protected]" "libseccomp Documentation"
2 .\" //////////////////////////////////////////////////////////////////////////
3 .SH NAME
4 .\" //////////////////////////////////////////////////////////////////////////
5 seccomp_export_bpf, seccomp_export_pfc \- Export the seccomp filter
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_export_bpf(const scmp_filter_ctx " ctx ", int " fd ");"
15 .BI "int seccomp_export_pfc(const scmp_filter_ctx " ctx ", int " fd ");"
16 .BI "int seccomp_export_bpf_mem(const scmp_filter_ctx " ctx ", void *" buf ", size_t *" len ");"
17 .sp
18 Link with \fI\-lseccomp\fP.
19 .fi
20 .\" //////////////////////////////////////////////////////////////////////////
21 .SH DESCRIPTION
22 .\" //////////////////////////////////////////////////////////////////////////
23 .P
24 The
25 .BR seccomp_export_bpf ()
26 and
27 .BR seccomp_export_pfc ()
28 functions generate and output the current seccomp filter in either BPF (Berkeley
29 Packet Filter) or PFC (Pseudo Filter Code). The output of
30 .BR seccomp_export_bpf ()
31 is suitable for loading into the kernel, while the output of
32 .BR seccomp_export_pfc ()
33 is human readable and is intended primarily as a debugging tool for developers
34 using libseccomp. Both functions write the filter to the
35 .I fd
36 file descriptor.
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 While the two output formats are guaranteed to be functionally equivalent for
44 the given seccomp filter configuration, the filter instructions, and their
45 ordering, are not guaranteed to be the same in both the BPF and PFC formats.
46 .P
47 The
48 .BR seccomp_export_bpf_mem ()
49 function is largely the same as
50 .BR seccomp_export_bpf (),
51 but instead of writing to a file descriptor, the program will be written to the
52 .I buf
53 pointer provided by the caller. The
54 .I len
55 argument must be initialized with the size of the
56 .I buf
57 buffer. If the program was valid,
58 .I len
59 will be updated with its size in bytes. If
60 .I buf
61 was too small to hold the program,
62 .I len
63 can be consulted to determine the required size. Passing a NULL
64 .I buf
65 may also be used to query the required size ahead of time.
66 .\" //////////////////////////////////////////////////////////////////////////
67 .SH RETURN VALUE
68 .\" //////////////////////////////////////////////////////////////////////////
69 Return zero on success or one of the following error codes on
70 failure:
71 .TP
72 .B -ECANCELED
73 There was a system failure beyond the control of the library.
74 .TP
75 .B -EFAULT
76 Internal libseccomp failure.
77 .TP
78 .B -EINVAL
79 Invalid input, either the context or architecture token is invalid.
80 .TP
81 .B -ENOMEM
82 The library was unable to allocate enough memory.
83 .TP
84 .B -ERANGE
85 The provided buffer was too small.
86 .P
87 If the \fISCMP_FLTATR_API_SYSRAWRC\fP filter attribute is non-zero then
88 additional error codes may be returned to the caller; these additional error
89 codes are the negative \fIerrno\fP values returned by the system. Unfortunately
90 libseccomp can make no guarantees about these return values.
91 .\" //////////////////////////////////////////////////////////////////////////
92 .SH EXAMPLES
93 .\" //////////////////////////////////////////////////////////////////////////
94 .nf
95 #include <seccomp.h>
96
97 int main(int argc, char *argv[])
98 {
99 int rc = \-1;
100 scmp_filter_ctx ctx;
101 int filter_fd;
102
103 ctx = seccomp_init(SCMP_ACT_KILL);
104 if (ctx == NULL)
105 goto out;
106
107 /* ... */
108
109 filter_fd = open("/tmp/seccomp_filter.bpf", O_WRONLY);
110 if (filter_fd == \-1) {
111 rc = \-errno;
112 goto out;
113 }
114
115 rc = seccomp_export_bpf(ctx, filter_fd);
116 if (rc < 0) {
117 close(filter_fd);
118 goto out;
119 }
120 close(filter_fd);
121
122 /* ... */
123
124 out:
125 seccomp_release(ctx);
126 return \-rc;
127 }
128 .fi
129 .\" //////////////////////////////////////////////////////////////////////////
130 .SH NOTES
131 .\" //////////////////////////////////////////////////////////////////////////
132 .P
133 While the seccomp filter can be generated independent of the kernel, kernel
134 support is required to load and enforce the seccomp filter generated by
135 libseccomp.
136 .P
137 The libseccomp project site, with more information and the source code
138 repository, can be found at https://github.com/seccomp/libseccomp. This tool,
139 as well as the libseccomp library, is currently under development, please
140 report any bugs at the project site or directly to the author.
141 .\" //////////////////////////////////////////////////////////////////////////
142 .SH AUTHOR
143 .\" //////////////////////////////////////////////////////////////////////////
144 Paul Moore <[email protected]>
145 .\" //////////////////////////////////////////////////////////////////////////
146 .SH SEE ALSO
147 .\" //////////////////////////////////////////////////////////////////////////
148 .BR seccomp_init (3),
149 .BR seccomp_release (3)
150