Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_disco_metrics_generated_fd_metric_tile_seccomp_h
3 : #define HEADER_fd_src_disco_metrics_generated_fd_metric_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_metric_tile_instr_cnt = 92;
37 :
38 0 : static void populate_sock_filter_policy_fd_metric_tile( ulong out_cnt, struct sock_filter out[ static 92 ], uint logfile_fd, uint metrics_socket_fd, uint epoll_inner_fd, uint epoll_outer_fd ) {
39 0 : FD_TEST( out_cnt >= 92 );
40 0 : struct sock_filter filter[92] = {
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 */ 12 ),
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 */ 12, 0 ),
48 : /* check fsync */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 17, 0 ),
50 : /* check accept4 */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_accept4, /* check_accept4 */ 20, 0 ),
52 : /* check read */
53 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_read, /* check_read */ 33, 0 ),
54 : /* check sendto */
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendto, /* check_sendto */ 40, 0 ),
56 : /* check close */
57 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_close, /* check_close */ 47, 0 ),
58 : /* check epoll_pwait */
59 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_epoll_pwait, /* check_epoll_pwait */ 54, 0 ),
60 : /* check epoll_ctl */
61 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_epoll_ctl, /* check_epoll_ctl */ 61, 0 ),
62 : /* check clock_nanosleep */
63 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_clock_nanosleep, /* check_clock_nanosleep */ 68, 0 ),
64 : /* check futex */
65 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_futex, /* check_futex */ 73, 0 ),
66 : /* allow restart_syscall */
67 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_restart_syscall, /* RET_ALLOW */ 1, 0 ),
68 : // RET_KILL_PROCESS:
69 : /* default deny */
70 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
71 : // RET_ALLOW:
72 : /* allow */
73 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
74 : // check_write:
75 : /* arg 0 low 32 bits */
76 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
77 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* write_ALLOW */ 3, /* or_1 */ 0 ),
78 : // or_1:
79 : /* arg 0 low 32 bits */
80 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
81 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* write_ALLOW */ 1, /* write_KILL */ 0 ),
82 : // write_KILL:
83 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
84 : // write_ALLOW:
85 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
86 : // check_fsync:
87 : /* arg 0 low 32 bits */
88 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
89 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* fsync_ALLOW */ 1, /* fsync_KILL */ 0 ),
90 : // fsync_KILL:
91 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
92 : // fsync_ALLOW:
93 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
94 : // check_accept4:
95 : /* arg 0 low 32 bits */
96 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
97 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(metrics_socket_fd)), /* and_2 */ 0, /* accept4_KILL */ 10 ),
98 : // and_2:
99 : /* arg 1 high 32 bits */
100 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(1)),
101 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_4 */ 0, /* accept4_KILL */ 8 ),
102 : // arg_hi_eq_4:
103 : /* arg 1 low 32 bits */
104 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
105 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_3 */ 0, /* accept4_KILL */ 6 ),
106 : // and_3:
107 : /* arg 2 high 32 bits */
108 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(2)),
109 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_6 */ 0, /* accept4_KILL */ 4 ),
110 : // arg_hi_eq_6:
111 : /* arg 2 low 32 bits */
112 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
113 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_5 */ 0, /* accept4_KILL */ 2 ),
114 : // and_5:
115 : /* arg 3 low 32 bits */
116 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
117 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(SOCK_CLOEXEC|SOCK_NONBLOCK), /* accept4_ALLOW */ 1, /* accept4_KILL */ 0 ),
118 : // accept4_KILL:
119 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
120 : // accept4_ALLOW:
121 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
122 : // check_read:
123 : /* arg 0 low 32 bits */
124 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
125 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* read_KILL */ 4, /* or_7 */ 0 ),
126 : // or_7:
127 : /* arg 0 low 32 bits */
128 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
129 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* read_KILL */ 2, /* or_8 */ 0 ),
130 : // or_8:
131 : /* arg 0 low 32 bits */
132 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
133 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(metrics_socket_fd)), /* read_KILL */ 0, /* read_ALLOW */ 1 ),
134 : // read_KILL:
135 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
136 : // read_ALLOW:
137 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
138 : // check_sendto:
139 : /* arg 0 low 32 bits */
140 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
141 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* sendto_KILL */ 4, /* or_9 */ 0 ),
142 : // or_9:
143 : /* arg 0 low 32 bits */
144 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
145 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* sendto_KILL */ 2, /* or_10 */ 0 ),
146 : // or_10:
147 : /* arg 0 low 32 bits */
148 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
149 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(metrics_socket_fd)), /* sendto_KILL */ 0, /* sendto_ALLOW */ 1 ),
150 : // sendto_KILL:
151 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
152 : // sendto_ALLOW:
153 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
154 : // check_close:
155 : /* arg 0 low 32 bits */
156 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
157 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* close_KILL */ 4, /* or_11 */ 0 ),
158 : // or_11:
159 : /* arg 0 low 32 bits */
160 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
161 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* close_KILL */ 2, /* or_12 */ 0 ),
162 : // or_12:
163 : /* arg 0 low 32 bits */
164 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
165 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(metrics_socket_fd)), /* close_KILL */ 0, /* close_ALLOW */ 1 ),
166 : // close_KILL:
167 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
168 : // close_ALLOW:
169 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
170 : // check_epoll_pwait:
171 : /* arg 0 low 32 bits */
172 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
173 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_inner_fd)), /* and_13 */ 0, /* epoll_pwait_KILL */ 4 ),
174 : // and_13:
175 : /* arg 4 high 32 bits */
176 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(4)),
177 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_14 */ 0, /* epoll_pwait_KILL */ 2 ),
178 : // arg_hi_eq_14:
179 : /* arg 4 low 32 bits */
180 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(4)),
181 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* epoll_pwait_ALLOW */ 1, /* epoll_pwait_KILL */ 0 ),
182 : // epoll_pwait_KILL:
183 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
184 : // epoll_pwait_ALLOW:
185 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
186 : // check_epoll_ctl:
187 : /* arg 0 low 32 bits */
188 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
189 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_inner_fd)), /* epoll_ctl_ALLOW */ 5, /* or_15 */ 0 ),
190 : // or_15:
191 : /* arg 0 low 32 bits */
192 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
193 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_outer_fd)), /* and_16 */ 0, /* epoll_ctl_KILL */ 2 ),
194 : // and_16:
195 : /* arg 2 low 32 bits */
196 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
197 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_inner_fd)), /* epoll_ctl_ALLOW */ 1, /* epoll_ctl_KILL */ 0 ),
198 : // epoll_ctl_KILL:
199 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
200 : // epoll_ctl_ALLOW:
201 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
202 : // check_clock_nanosleep:
203 : /* arg 0 low 32 bits */
204 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
205 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(CLOCK_REALTIME), /* and_17 */ 0, /* clock_nanosleep_KILL */ 2 ),
206 : // and_17:
207 : /* arg 1 low 32 bits */
208 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
209 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* clock_nanosleep_ALLOW */ 1, /* clock_nanosleep_KILL */ 0 ),
210 : // clock_nanosleep_KILL:
211 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
212 : // clock_nanosleep_ALLOW:
213 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
214 : // check_futex:
215 : /* arg 1 low 32 bits */
216 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
217 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(FUTEX_WAIT_BITSET), /* and_18 */ 0, /* futex_KILL */ 2 ),
218 : // and_18:
219 : /* arg 2 low 32 bits */
220 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
221 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* futex_ALLOW */ 1, /* futex_KILL */ 0 ),
222 : // futex_KILL:
223 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
224 : // futex_ALLOW:
225 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
226 0 : };
227 0 : fd_memcpy( out, filter, sizeof( filter ) );
228 0 : }
229 :
230 : #endif /* defined(__linux__) */
231 :
232 : #endif /* HEADER_fd_src_disco_metrics_generated_fd_metric_tile_seccomp_h */
|