Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_discof_rpc_generated_fd_rpc_tile_seccomp_h
3 : #define HEADER_fd_src_discof_rpc_generated_fd_rpc_tile_seccomp_h
4 :
5 : #if defined(__linux__)
6 :
7 : #include "../../../../src/util/fd_util_base.h"
8 : #include <linux/audit.h>
9 : #include <linux/capability.h>
10 : #include <linux/filter.h>
11 : #include <linux/seccomp.h>
12 : #include <linux/bpf.h>
13 : #include <linux/unistd.h>
14 : #include <sys/syscall.h>
15 : #include <signal.h>
16 : #include <stddef.h>
17 :
18 : #if defined(__i386__)
19 : # define ARCH_NR AUDIT_ARCH_I386
20 : #elif defined(__x86_64__)
21 : # define ARCH_NR AUDIT_ARCH_X86_64
22 : #elif defined(__aarch64__)
23 : # define ARCH_NR AUDIT_ARCH_AARCH64
24 : #elif defined(__riscv) && __riscv_xlen == 64
25 : # define ARCH_NR AUDIT_ARCH_RISCV64
26 : #else
27 : # error "Target architecture is unsupported by seccomp."
28 : #endif
29 :
30 : #define FD_SECCOMP_ARG_LO_OFFSET(argno) ( offsetof( struct seccomp_data, args[(argno)] ) )
31 : #define FD_SECCOMP_ARG_HI_OFFSET(argno) ( offsetof( struct seccomp_data, args[(argno)] ) + 4U )
32 :
33 : #define FD_SECCOMP_ARG_LO(x) ((uint)(((ulong)(uint)(int)(x) ) & 0xffffffffUL))
34 : #define FD_SECCOMP_ARG_HI(x) ((uint)(((ulong)(x) >> 32) & 0xffffffffUL))
35 :
36 : static const uint sock_filter_policy_fd_rpc_tile_instr_cnt = 101;
37 :
38 0 : static void populate_sock_filter_policy_fd_rpc_tile( ulong out_cnt, struct sock_filter out[ static 101 ], uint logfile_fd, uint rpc_socket_fd, uint accdb_ro_fd, uint epoll_inner_fd, uint epoll_outer_fd ) {
39 0 : FD_TEST( out_cnt >= 101 );
40 0 : struct sock_filter filter[101] = {
41 : /* validate architecture */
42 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, arch ) )),
43 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 13 ),
44 : /* load syscall number */
45 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) )),
46 : /* check write */
47 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 13, 0 ),
48 : /* check fsync */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 18, 0 ),
50 : /* check accept4 */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_accept4, /* check_accept4 */ 21, 0 ),
52 : /* check read */
53 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_read, /* check_read */ 34, 0 ),
54 : /* check sendto */
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendto, /* check_sendto */ 41, 0 ),
56 : /* check sendmsg */
57 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendmsg, /* check_sendmsg */ 48, 0 ),
58 : /* check close */
59 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_close, /* check_close */ 57, 0 ),
60 : /* check epoll_pwait */
61 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_epoll_pwait, /* check_epoll_pwait */ 64, 0 ),
62 : /* check epoll_ctl */
63 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_epoll_ctl, /* check_epoll_ctl */ 71, 0 ),
64 : /* check preadv2 */
65 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_preadv2, /* check_preadv2 */ 78, 0 ),
66 : /* check futex */
67 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_futex, /* check_futex */ 81, 0 ),
68 : /* allow restart_syscall */
69 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_restart_syscall, /* RET_ALLOW */ 1, 0 ),
70 : // RET_KILL_PROCESS:
71 : /* default deny */
72 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
73 : // RET_ALLOW:
74 : /* allow */
75 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
76 : // check_write:
77 : /* arg 0 low 32 bits */
78 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
79 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* write_ALLOW */ 3, /* or_1 */ 0 ),
80 : // or_1:
81 : /* arg 0 low 32 bits */
82 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
83 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* write_ALLOW */ 1, /* write_KILL */ 0 ),
84 : // write_KILL:
85 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
86 : // write_ALLOW:
87 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
88 : // check_fsync:
89 : /* arg 0 low 32 bits */
90 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
91 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* fsync_ALLOW */ 1, /* fsync_KILL */ 0 ),
92 : // fsync_KILL:
93 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
94 : // fsync_ALLOW:
95 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
96 : // check_accept4:
97 : /* arg 0 low 32 bits */
98 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
99 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(rpc_socket_fd)), /* and_2 */ 0, /* accept4_KILL */ 10 ),
100 : // and_2:
101 : /* arg 1 high 32 bits */
102 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(1)),
103 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_4 */ 0, /* accept4_KILL */ 8 ),
104 : // arg_hi_eq_4:
105 : /* arg 1 low 32 bits */
106 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
107 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_3 */ 0, /* accept4_KILL */ 6 ),
108 : // and_3:
109 : /* arg 2 high 32 bits */
110 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(2)),
111 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_6 */ 0, /* accept4_KILL */ 4 ),
112 : // arg_hi_eq_6:
113 : /* arg 2 low 32 bits */
114 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
115 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_5 */ 0, /* accept4_KILL */ 2 ),
116 : // and_5:
117 : /* arg 3 low 32 bits */
118 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
119 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(SOCK_CLOEXEC|SOCK_NONBLOCK), /* accept4_ALLOW */ 1, /* accept4_KILL */ 0 ),
120 : // accept4_KILL:
121 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
122 : // accept4_ALLOW:
123 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
124 : // check_read:
125 : /* arg 0 low 32 bits */
126 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
127 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* read_KILL */ 4, /* or_7 */ 0 ),
128 : // or_7:
129 : /* arg 0 low 32 bits */
130 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
131 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* read_KILL */ 2, /* or_8 */ 0 ),
132 : // or_8:
133 : /* arg 0 low 32 bits */
134 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
135 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(rpc_socket_fd)), /* read_KILL */ 0, /* read_ALLOW */ 1 ),
136 : // read_KILL:
137 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
138 : // read_ALLOW:
139 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
140 : // check_sendto:
141 : /* arg 0 low 32 bits */
142 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
143 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* sendto_KILL */ 4, /* or_9 */ 0 ),
144 : // or_9:
145 : /* arg 0 low 32 bits */
146 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
147 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* sendto_KILL */ 2, /* or_10 */ 0 ),
148 : // or_10:
149 : /* arg 0 low 32 bits */
150 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
151 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(rpc_socket_fd)), /* sendto_KILL */ 0, /* sendto_ALLOW */ 1 ),
152 : // sendto_KILL:
153 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
154 : // sendto_ALLOW:
155 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
156 : // check_sendmsg:
157 : /* arg 0 low 32 bits */
158 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
159 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* sendmsg_KILL */ 6, /* or_12 */ 0 ),
160 : // or_12:
161 : /* arg 0 low 32 bits */
162 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
163 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* sendmsg_KILL */ 4, /* or_13 */ 0 ),
164 : // or_13:
165 : /* arg 0 low 32 bits */
166 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
167 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(rpc_socket_fd)), /* sendmsg_KILL */ 2, /* and_11 */ 0 ),
168 : // and_11:
169 : /* arg 2 low 32 bits */
170 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
171 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(MSG_NOSIGNAL), /* sendmsg_ALLOW */ 1, /* sendmsg_KILL */ 0 ),
172 : // sendmsg_KILL:
173 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
174 : // sendmsg_ALLOW:
175 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
176 : // check_close:
177 : /* arg 0 low 32 bits */
178 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
179 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* close_KILL */ 4, /* or_14 */ 0 ),
180 : // or_14:
181 : /* arg 0 low 32 bits */
182 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
183 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* close_KILL */ 2, /* or_15 */ 0 ),
184 : // or_15:
185 : /* arg 0 low 32 bits */
186 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
187 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(rpc_socket_fd)), /* close_KILL */ 0, /* close_ALLOW */ 1 ),
188 : // close_KILL:
189 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
190 : // close_ALLOW:
191 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
192 : // check_epoll_pwait:
193 : /* arg 0 low 32 bits */
194 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
195 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_inner_fd)), /* and_16 */ 0, /* epoll_pwait_KILL */ 4 ),
196 : // and_16:
197 : /* arg 4 high 32 bits */
198 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(4)),
199 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_17 */ 0, /* epoll_pwait_KILL */ 2 ),
200 : // arg_hi_eq_17:
201 : /* arg 4 low 32 bits */
202 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(4)),
203 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* epoll_pwait_ALLOW */ 1, /* epoll_pwait_KILL */ 0 ),
204 : // epoll_pwait_KILL:
205 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
206 : // epoll_pwait_ALLOW:
207 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
208 : // check_epoll_ctl:
209 : /* arg 0 low 32 bits */
210 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
211 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_inner_fd)), /* epoll_ctl_ALLOW */ 5, /* or_18 */ 0 ),
212 : // or_18:
213 : /* arg 0 low 32 bits */
214 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
215 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_outer_fd)), /* and_19 */ 0, /* epoll_ctl_KILL */ 2 ),
216 : // and_19:
217 : /* arg 2 low 32 bits */
218 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
219 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_inner_fd)), /* epoll_ctl_ALLOW */ 1, /* epoll_ctl_KILL */ 0 ),
220 : // epoll_ctl_KILL:
221 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
222 : // epoll_ctl_ALLOW:
223 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
224 : // check_preadv2:
225 : /* arg 0 low 32 bits */
226 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
227 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(accdb_ro_fd)), /* preadv2_ALLOW */ 1, /* preadv2_KILL */ 0 ),
228 : // preadv2_KILL:
229 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
230 : // preadv2_ALLOW:
231 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
232 : // check_futex:
233 : /* arg 1 low 32 bits */
234 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
235 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(FUTEX_WAIT_BITSET), /* and_20 */ 0, /* futex_KILL */ 2 ),
236 : // and_20:
237 : /* arg 2 low 32 bits */
238 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
239 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* futex_ALLOW */ 1, /* futex_KILL */ 0 ),
240 : // futex_KILL:
241 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
242 : // futex_ALLOW:
243 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
244 0 : };
245 0 : fd_memcpy( out, filter, sizeof( filter ) );
246 0 : }
247 :
248 : #endif /* defined(__linux__) */
249 :
250 : #endif /* HEADER_fd_src_discof_rpc_generated_fd_rpc_tile_seccomp_h */
|