Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_app_fdctl_run_tiles_generated_net_seccomp_h
3 : #define HEADER_fd_src_app_fdctl_run_tiles_generated_net_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_net_instr_cnt = 60;
25 :
26 0 : static void populate_sock_filter_policy_net( ulong out_cnt, struct sock_filter * out, unsigned int logfile_fd, unsigned int xsk_fd, unsigned int lo_xsk_fd, unsigned int netlink_fd) {
27 0 : FD_TEST( out_cnt >= 60 );
28 0 : struct sock_filter filter[60] = {
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 */ 56 ),
32 : /* loading syscall number in accumulator */
33 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) ) ),
34 : /* allow write based on expression */
35 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 6, 0 ),
36 : /* allow fsync based on expression */
37 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 9, 0 ),
38 : /* allow sendto based on expression */
39 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendto, /* check_sendto */ 10, 0 ),
40 : /* allow recvmsg based on expression */
41 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_recvmsg, /* check_recvmsg */ 31, 0 ),
42 : /* allow getsockopt based on expression */
43 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_getsockopt, /* check_getsockopt */ 36, 0 ),
44 : /* allow recvfrom based on expression */
45 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_recvfrom, /* check_recvfrom */ 41, 0 ),
46 : /* none of the syscalls matched */
47 0 : { BPF_JMP | BPF_JA, 0, 0, /* RET_KILL_PROCESS */ 48 },
48 : // check_write:
49 : /* load syscall argument 0 in accumulator */
50 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 2, /* RET_ALLOW */ 47, /* lbl_1 */ 0 ),
52 : // lbl_1:
53 : /* load syscall argument 0 in accumulator */
54 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_ALLOW */ 45, /* RET_KILL_PROCESS */ 44 ),
56 : // check_fsync:
57 : /* load syscall argument 0 in accumulator */
58 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
59 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_ALLOW */ 43, /* RET_KILL_PROCESS */ 42 ),
60 : // check_sendto:
61 : /* load syscall argument 0 in accumulator */
62 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
63 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, xsk_fd, /* lbl_3 */ 2, /* lbl_4 */ 0 ),
64 : // lbl_4:
65 : /* load syscall argument 0 in accumulator */
66 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
67 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, lo_xsk_fd, /* lbl_3 */ 0, /* lbl_2 */ 10 ),
68 : // lbl_3:
69 : /* load syscall argument 1 in accumulator */
70 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
71 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_5 */ 0, /* lbl_2 */ 8 ),
72 : // lbl_5:
73 : /* load syscall argument 2 in accumulator */
74 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
75 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_6 */ 0, /* lbl_2 */ 6 ),
76 : // lbl_6:
77 : /* load syscall argument 3 in accumulator */
78 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[3])),
79 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, MSG_DONTWAIT, /* lbl_7 */ 0, /* lbl_2 */ 4 ),
80 : // lbl_7:
81 : /* load syscall argument 4 in accumulator */
82 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[4])),
83 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_8 */ 0, /* lbl_2 */ 2 ),
84 : // lbl_8:
85 : /* load syscall argument 5 in accumulator */
86 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[5])),
87 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* RET_ALLOW */ 29, /* lbl_2 */ 0 ),
88 : // lbl_2:
89 : /* load syscall argument 0 in accumulator */
90 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
91 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, netlink_fd, /* lbl_9 */ 0, /* RET_KILL_PROCESS */ 26 ),
92 : // lbl_9:
93 : /* load syscall argument 3 in accumulator */
94 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[3])),
95 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_10 */ 0, /* RET_KILL_PROCESS */ 24 ),
96 : // lbl_10:
97 : /* load syscall argument 4 in accumulator */
98 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[4])),
99 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_11 */ 0, /* RET_KILL_PROCESS */ 22 ),
100 : // lbl_11:
101 : /* load syscall argument 5 in accumulator */
102 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[5])),
103 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* RET_ALLOW */ 21, /* RET_KILL_PROCESS */ 20 ),
104 : // check_recvmsg:
105 : /* load syscall argument 0 in accumulator */
106 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
107 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, xsk_fd, /* lbl_12 */ 2, /* lbl_13 */ 0 ),
108 : // lbl_13:
109 : /* load syscall argument 0 in accumulator */
110 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
111 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, lo_xsk_fd, /* lbl_12 */ 0, /* RET_KILL_PROCESS */ 16 ),
112 : // lbl_12:
113 : /* load syscall argument 2 in accumulator */
114 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
115 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, MSG_DONTWAIT, /* RET_ALLOW */ 15, /* RET_KILL_PROCESS */ 14 ),
116 : // check_getsockopt:
117 : /* load syscall argument 0 in accumulator */
118 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
119 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, xsk_fd, /* lbl_14 */ 0, /* RET_KILL_PROCESS */ 12 ),
120 : // lbl_14:
121 : /* load syscall argument 1 in accumulator */
122 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
123 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SOL_XDP, /* lbl_15 */ 0, /* RET_KILL_PROCESS */ 10 ),
124 : // lbl_15:
125 : /* load syscall argument 2 in accumulator */
126 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
127 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, XDP_STATISTICS, /* RET_ALLOW */ 9, /* RET_KILL_PROCESS */ 8 ),
128 : // check_recvfrom:
129 : /* load syscall argument 0 in accumulator */
130 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
131 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, netlink_fd, /* lbl_16 */ 0, /* RET_KILL_PROCESS */ 6 ),
132 : // lbl_16:
133 : /* load syscall argument 3 in accumulator */
134 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[3])),
135 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_17 */ 0, /* RET_KILL_PROCESS */ 4 ),
136 : // lbl_17:
137 : /* load syscall argument 4 in accumulator */
138 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[4])),
139 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_18 */ 0, /* RET_KILL_PROCESS */ 2 ),
140 : // lbl_18:
141 : /* load syscall argument 5 in accumulator */
142 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[5])),
143 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* RET_ALLOW */ 1, /* RET_KILL_PROCESS */ 0 ),
144 : // RET_KILL_PROCESS:
145 : /* KILL_PROCESS is placed before ALLOW since it's the fallthrough case. */
146 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
147 : // RET_ALLOW:
148 : /* ALLOW has to be reached by jumping */
149 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
150 0 : };
151 0 : fd_memcpy( out, filter, sizeof( filter ) );
152 0 : }
153 :
154 : #endif
|