Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_disco_bundle_generated_fd_bundle_tile_seccomp_h
3 : #define HEADER_fd_src_disco_bundle_generated_fd_bundle_tile_seccomp_h
4 :
5 : #include "../../../../src/util/fd_util_base.h"
6 : #include <linux/audit.h>
7 : #include <linux/capability.h>
8 : #include <linux/filter.h>
9 : #include <linux/seccomp.h>
10 : #include <linux/bpf.h>
11 : #include <sys/syscall.h>
12 : #include <signal.h>
13 : #include <stddef.h>
14 :
15 : #if defined(__i386__)
16 : # define ARCH_NR AUDIT_ARCH_I386
17 : #elif defined(__x86_64__)
18 : # define ARCH_NR AUDIT_ARCH_X86_64
19 : #elif defined(__aarch64__)
20 : # define ARCH_NR AUDIT_ARCH_AARCH64
21 : #else
22 : # error "Target architecture is unsupported by seccomp."
23 : #endif
24 : static const unsigned int sock_filter_policy_fd_bundle_tile_instr_cnt = 91;
25 :
26 0 : static void populate_sock_filter_policy_fd_bundle_tile( ulong out_cnt, struct sock_filter * out, uint logfile_fd, uint keylog_fd, uint etc_hosts_fd, uint etc_resolv_conf) {
27 0 : FD_TEST( out_cnt >= 91 );
28 0 : struct sock_filter filter[91] = {
29 : /* Check: Jump to RET_KILL_PROCESS if the script's arch != the runtime arch */
30 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, arch ) ) ),
31 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 87 ),
32 : /* loading syscall number in accumulator */
33 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) ) ),
34 : /* simply allow read */
35 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_read, /* RET_ALLOW */ 86, 0 ),
36 : /* allow recvmsg based on expression */
37 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_recvmsg, /* check_recvmsg */ 18, 0 ),
38 : /* simply allow write */
39 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* RET_ALLOW */ 84, 0 ),
40 : /* allow writev based on expression */
41 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_writev, /* check_writev */ 20, 0 ),
42 : /* allow sendmsg based on expression */
43 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendmsg, /* check_sendmsg */ 23, 0 ),
44 : /* allow sendto based on expression */
45 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendto, /* check_sendto */ 28, 0 ),
46 : /* allow fsync based on expression */
47 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 29, 0 ),
48 : /* allow socket based on expression */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_socket, /* check_socket */ 30, 0 ),
50 : /* simply allow connect */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_connect, /* RET_ALLOW */ 78, 0 ),
52 : /* allow shutdown based on expression */
53 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_shutdown, /* check_shutdown */ 46, 0 ),
54 : /* simply allow close */
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_close, /* RET_ALLOW */ 76, 0 ),
56 : /* allow fcntl based on expression */
57 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fcntl, /* check_fcntl */ 46, 0 ),
58 : /* allow bind based on expression */
59 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_bind, /* check_bind */ 49, 0 ),
60 : /* simply allow poll */
61 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_poll, /* RET_ALLOW */ 73, 0 ),
62 : /* allow setsockopt based on expression */
63 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_setsockopt, /* check_setsockopt */ 51, 0 ),
64 : /* simply allow getsockname */
65 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_getsockname, /* RET_ALLOW */ 71, 0 ),
66 : /* simply allow getpid */
67 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_getpid, /* RET_ALLOW */ 70, 0 ),
68 : /* simply allow getrandom */
69 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_getrandom, /* RET_ALLOW */ 69, 0 ),
70 : /* allow lseek based on expression */
71 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_lseek, /* check_lseek */ 59, 0 ),
72 : /* none of the syscalls matched */
73 0 : { BPF_JMP | BPF_JA, 0, 0, /* RET_KILL_PROCESS */ 66 },
74 : // check_recvmsg:
75 : /* load syscall argument 2 in accumulator */
76 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
77 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, MSG_NOSIGNAL|MSG_DONTWAIT, /* RET_ALLOW */ 65, /* lbl_1 */ 0 ),
78 : // lbl_1:
79 : /* load syscall argument 2 in accumulator */
80 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
81 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* RET_ALLOW */ 63, /* RET_KILL_PROCESS */ 62 ),
82 : // check_writev:
83 : /* load syscall argument 0 in accumulator */
84 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
85 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, keylog_fd, /* lbl_2 */ 0, /* RET_KILL_PROCESS */ 60 ),
86 : // lbl_2:
87 : /* load syscall argument 2 in accumulator */
88 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
89 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 2, /* RET_ALLOW */ 59, /* RET_KILL_PROCESS */ 58 ),
90 : // check_sendmsg:
91 : /* load syscall argument 2 in accumulator */
92 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
93 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, MSG_NOSIGNAL|MSG_DONTWAIT, /* RET_ALLOW */ 57, /* lbl_3 */ 0 ),
94 : // lbl_3:
95 : /* load syscall argument 2 in accumulator */
96 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
97 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, MSG_FASTOPEN|MSG_NOSIGNAL, /* RET_ALLOW */ 55, /* lbl_4 */ 0 ),
98 : // lbl_4:
99 : /* load syscall argument 2 in accumulator */
100 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
101 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, MSG_NOSIGNAL, /* RET_ALLOW */ 53, /* RET_KILL_PROCESS */ 52 ),
102 : // check_sendto:
103 : /* load syscall argument 3 in accumulator */
104 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[3])),
105 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, MSG_NOSIGNAL, /* RET_ALLOW */ 51, /* RET_KILL_PROCESS */ 50 ),
106 : // check_fsync:
107 : /* load syscall argument 0 in accumulator */
108 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
109 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_ALLOW */ 49, /* RET_KILL_PROCESS */ 48 ),
110 : // check_socket:
111 : /* load syscall argument 0 in accumulator */
112 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
113 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, AF_INET, /* lbl_5 */ 2, /* lbl_6 */ 0 ),
114 : // lbl_6:
115 : /* load syscall argument 0 in accumulator */
116 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
117 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, AF_INET6, /* lbl_5 */ 0, /* RET_KILL_PROCESS */ 44 ),
118 : // lbl_5:
119 : /* load syscall argument 1 in accumulator */
120 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
121 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SOCK_STREAM|SOCK_CLOEXEC, /* lbl_8 */ 2, /* lbl_9 */ 0 ),
122 : // lbl_9:
123 : /* load syscall argument 1 in accumulator */
124 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
125 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, /* lbl_8 */ 0, /* lbl_7 */ 2 ),
126 : // lbl_8:
127 : /* load syscall argument 2 in accumulator */
128 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
129 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* RET_ALLOW */ 39, /* lbl_7 */ 0 ),
130 : // lbl_7:
131 : /* load syscall argument 1 in accumulator */
132 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
133 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, /* lbl_11 */ 0, /* lbl_10 */ 2 ),
134 : // lbl_11:
135 : /* load syscall argument 2 in accumulator */
136 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
137 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* RET_ALLOW */ 35, /* lbl_10 */ 0 ),
138 : // lbl_10:
139 : /* load syscall argument 1 in accumulator */
140 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
141 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SOCK_DGRAM|SOCK_CLOEXEC, /* lbl_12 */ 0, /* RET_KILL_PROCESS */ 32 ),
142 : // lbl_12:
143 : /* load syscall argument 2 in accumulator */
144 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
145 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_UDP, /* RET_ALLOW */ 31, /* RET_KILL_PROCESS */ 30 ),
146 : // check_shutdown:
147 : /* load syscall argument 1 in accumulator */
148 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
149 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SHUT_WR, /* RET_ALLOW */ 29, /* RET_KILL_PROCESS */ 28 ),
150 : // check_fcntl:
151 : /* load syscall argument 1 in accumulator */
152 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
153 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, F_SETFL, /* lbl_13 */ 0, /* RET_KILL_PROCESS */ 26 ),
154 : // lbl_13:
155 : /* load syscall argument 2 in accumulator */
156 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
157 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, O_NONBLOCK, /* RET_ALLOW */ 25, /* RET_KILL_PROCESS */ 24 ),
158 : // check_bind:
159 : /* load syscall argument 2 in accumulator */
160 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
161 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, sizeof(struct sockaddr_in), /* RET_ALLOW */ 23, /* lbl_14 */ 0 ),
162 : // lbl_14:
163 : /* load syscall argument 2 in accumulator */
164 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
165 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, sizeof(struct sockaddr_in6), /* RET_ALLOW */ 21, /* RET_KILL_PROCESS */ 20 ),
166 : // check_setsockopt:
167 : /* load syscall argument 1 in accumulator */
168 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
169 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SOL_SOCKET, /* lbl_16 */ 0, /* lbl_15 */ 2 ),
170 : // lbl_16:
171 : /* load syscall argument 2 in accumulator */
172 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
173 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SO_RCVBUF, /* RET_ALLOW */ 17, /* lbl_15 */ 0 ),
174 : // lbl_15:
175 : /* load syscall argument 1 in accumulator */
176 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
177 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_TCP, /* lbl_18 */ 0, /* lbl_17 */ 2 ),
178 : // lbl_18:
179 : /* load syscall argument 2 in accumulator */
180 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
181 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, TCP_FASTOPEN_CONNECT, /* RET_ALLOW */ 13, /* lbl_17 */ 0 ),
182 : // lbl_17:
183 : /* load syscall argument 1 in accumulator */
184 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
185 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_IPV6, /* lbl_19 */ 0, /* RET_KILL_PROCESS */ 10 ),
186 : // lbl_19:
187 : /* load syscall argument 2 in accumulator */
188 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
189 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, IPV6_V6ONLY, /* RET_ALLOW */ 9, /* RET_KILL_PROCESS */ 8 ),
190 : // check_lseek:
191 : /* load syscall argument 0 in accumulator */
192 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
193 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, etc_resolv_conf, /* lbl_20 */ 2, /* lbl_21 */ 0 ),
194 : // lbl_21:
195 : /* load syscall argument 0 in accumulator */
196 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
197 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, etc_hosts_fd, /* lbl_20 */ 0, /* RET_KILL_PROCESS */ 4 ),
198 : // lbl_20:
199 : /* load syscall argument 1 in accumulator */
200 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
201 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_22 */ 0, /* RET_KILL_PROCESS */ 2 ),
202 : // lbl_22:
203 : /* load syscall argument 2 in accumulator */
204 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
205 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SEEK_SET, /* RET_ALLOW */ 1, /* RET_KILL_PROCESS */ 0 ),
206 : // RET_KILL_PROCESS:
207 : /* KILL_PROCESS is placed before ALLOW since it's the fallthrough case. */
208 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
209 : // RET_ALLOW:
210 : /* ALLOW has to be reached by jumping */
211 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
212 0 : };
213 0 : fd_memcpy( out, filter, sizeof( filter ) );
214 0 : }
215 :
216 : #endif
|