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 : #else
25 : # error "Target architecture is unsupported by seccomp."
26 : #endif
27 :
28 : #define FD_SECCOMP_ARG_LO_OFFSET(argno) ( offsetof( struct seccomp_data, args[(argno)] ) )
29 : #define FD_SECCOMP_ARG_HI_OFFSET(argno) ( offsetof( struct seccomp_data, args[(argno)] ) + 4U )
30 :
31 : #define FD_SECCOMP_ARG_LO(x) ((uint)(((ulong)(uint)(int)(x) ) & 0xffffffffUL))
32 : #define FD_SECCOMP_ARG_HI(x) ((uint)(((ulong)(x) >> 32) & 0xffffffffUL))
33 :
34 : static const uint sock_filter_policy_fd_metric_tile_instr_cnt = 84;
35 :
36 0 : static void populate_sock_filter_policy_fd_metric_tile( ulong out_cnt, struct sock_filter out[ static 84 ], uint logfile_fd, uint metrics_socket_fd, uint epoll_inner_fd, uint epoll_outer_fd ) {
37 0 : FD_TEST( out_cnt >= 84 );
38 0 : struct sock_filter filter[84] = {
39 : /* validate architecture */
40 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, arch ) )),
41 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 10 ),
42 : /* load syscall number */
43 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) )),
44 : /* check write */
45 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 10, 0 ),
46 : /* check fsync */
47 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 15, 0 ),
48 : /* check accept4 */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_accept4, /* check_accept4 */ 18, 0 ),
50 : /* check read */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_read, /* check_read */ 31, 0 ),
52 : /* check sendto */
53 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendto, /* check_sendto */ 38, 0 ),
54 : /* check close */
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_close, /* check_close */ 45, 0 ),
56 : /* check epoll_pwait */
57 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_epoll_pwait, /* check_epoll_pwait */ 52, 0 ),
58 : /* check epoll_ctl */
59 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_epoll_ctl, /* check_epoll_ctl */ 59, 0 ),
60 : /* check clock_nanosleep */
61 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_clock_nanosleep, /* check_clock_nanosleep */ 66, 0 ),
62 : // RET_KILL_PROCESS:
63 : /* default deny */
64 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
65 : // RET_ALLOW:
66 : /* allow */
67 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
68 : // check_write:
69 : /* arg 0 low 32 bits */
70 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
71 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* write_ALLOW */ 3, /* or_1 */ 0 ),
72 : // or_1:
73 : /* arg 0 low 32 bits */
74 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
75 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* write_ALLOW */ 1, /* write_KILL */ 0 ),
76 : // write_KILL:
77 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
78 : // write_ALLOW:
79 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
80 : // check_fsync:
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)), /* fsync_ALLOW */ 1, /* fsync_KILL */ 0 ),
84 : // fsync_KILL:
85 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
86 : // fsync_ALLOW:
87 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
88 : // check_accept4:
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)(metrics_socket_fd)), /* and_2 */ 0, /* accept4_KILL */ 10 ),
92 : // and_2:
93 : /* arg 1 high 32 bits */
94 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(1)),
95 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_4 */ 0, /* accept4_KILL */ 8 ),
96 : // arg_hi_eq_4:
97 : /* arg 1 low 32 bits */
98 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
99 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_3 */ 0, /* accept4_KILL */ 6 ),
100 : // and_3:
101 : /* arg 2 high 32 bits */
102 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(2)),
103 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_6 */ 0, /* accept4_KILL */ 4 ),
104 : // arg_hi_eq_6:
105 : /* arg 2 low 32 bits */
106 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
107 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_5 */ 0, /* accept4_KILL */ 2 ),
108 : // and_5:
109 : /* arg 3 low 32 bits */
110 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
111 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(SOCK_CLOEXEC|SOCK_NONBLOCK), /* accept4_ALLOW */ 1, /* accept4_KILL */ 0 ),
112 : // accept4_KILL:
113 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
114 : // accept4_ALLOW:
115 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
116 : // check_read:
117 : /* arg 0 low 32 bits */
118 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
119 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* read_KILL */ 4, /* or_7 */ 0 ),
120 : // or_7:
121 : /* arg 0 low 32 bits */
122 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
123 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* read_KILL */ 2, /* or_8 */ 0 ),
124 : // or_8:
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, ((uint)(metrics_socket_fd)), /* read_KILL */ 0, /* read_ALLOW */ 1 ),
128 : // read_KILL:
129 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
130 : // read_ALLOW:
131 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
132 : // check_sendto:
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, 0x00000002U, /* sendto_KILL */ 4, /* or_9 */ 0 ),
136 : // or_9:
137 : /* arg 0 low 32 bits */
138 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
139 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* sendto_KILL */ 2, /* or_10 */ 0 ),
140 : // or_10:
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, ((uint)(metrics_socket_fd)), /* sendto_KILL */ 0, /* sendto_ALLOW */ 1 ),
144 : // sendto_KILL:
145 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
146 : // sendto_ALLOW:
147 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
148 : // check_close:
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, 0x00000002U, /* close_KILL */ 4, /* or_11 */ 0 ),
152 : // or_11:
153 : /* arg 0 low 32 bits */
154 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
155 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* close_KILL */ 2, /* or_12 */ 0 ),
156 : // or_12:
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, ((uint)(metrics_socket_fd)), /* close_KILL */ 0, /* close_ALLOW */ 1 ),
160 : // close_KILL:
161 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
162 : // close_ALLOW:
163 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
164 : // check_epoll_pwait:
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)(epoll_inner_fd)), /* and_13 */ 0, /* epoll_pwait_KILL */ 4 ),
168 : // and_13:
169 : /* arg 4 high 32 bits */
170 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(4)),
171 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_14 */ 0, /* epoll_pwait_KILL */ 2 ),
172 : // arg_hi_eq_14:
173 : /* arg 4 low 32 bits */
174 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(4)),
175 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* epoll_pwait_ALLOW */ 1, /* epoll_pwait_KILL */ 0 ),
176 : // epoll_pwait_KILL:
177 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
178 : // epoll_pwait_ALLOW:
179 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
180 : // check_epoll_ctl:
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)(epoll_inner_fd)), /* epoll_ctl_ALLOW */ 5, /* 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)(epoll_outer_fd)), /* and_16 */ 0, /* epoll_ctl_KILL */ 2 ),
188 : // and_16:
189 : /* arg 2 low 32 bits */
190 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
191 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(epoll_inner_fd)), /* epoll_ctl_ALLOW */ 1, /* epoll_ctl_KILL */ 0 ),
192 : // epoll_ctl_KILL:
193 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
194 : // epoll_ctl_ALLOW:
195 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
196 : // check_clock_nanosleep:
197 : /* arg 0 low 32 bits */
198 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
199 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(CLOCK_REALTIME), /* and_17 */ 0, /* clock_nanosleep_KILL */ 2 ),
200 : // and_17:
201 : /* arg 1 low 32 bits */
202 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
203 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* clock_nanosleep_ALLOW */ 1, /* clock_nanosleep_KILL */ 0 ),
204 : // clock_nanosleep_KILL:
205 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
206 : // clock_nanosleep_ALLOW:
207 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
208 0 : };
209 0 : fd_memcpy( out, filter, sizeof( filter ) );
210 0 : }
211 :
212 : #endif /* defined(__linux__) */
213 :
214 : #endif /* HEADER_fd_src_disco_metrics_generated_fd_metric_tile_seccomp_h */
|