Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_disco_netlink_generated_netlink_seccomp_h
3 : #define HEADER_fd_src_disco_netlink_generated_netlink_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_netlink_instr_cnt = 63;
35 :
36 0 : static void populate_sock_filter_policy_netlink( ulong out_cnt, struct sock_filter out[ static 63 ], uint logfile_fd, uint nl_mon_fd, uint nl_req_fd, uint arp_probe_fd ) {
37 0 : FD_TEST( out_cnt >= 63 );
38 0 : struct sock_filter filter[63] = {
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 */ 5 ),
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 */ 5, 0 ),
46 : /* check fsync */
47 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 10, 0 ),
48 : /* check sendto */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendto, /* check_sendto */ 13, 0 ),
50 : /* check recvfrom */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_recvfrom, /* check_recvfrom */ 38, 0 ),
52 : // RET_KILL_PROCESS:
53 : /* default deny */
54 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
55 : // RET_ALLOW:
56 : /* allow */
57 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
58 : // check_write:
59 : /* arg 0 low 32 bits */
60 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
61 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* write_ALLOW */ 3, /* or_1 */ 0 ),
62 : // or_1:
63 : /* arg 0 low 32 bits */
64 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
65 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* write_ALLOW */ 1, /* write_KILL */ 0 ),
66 : // write_KILL:
67 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
68 : // write_ALLOW:
69 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
70 : // check_fsync:
71 : /* arg 0 low 32 bits */
72 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
73 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* fsync_ALLOW */ 1, /* fsync_KILL */ 0 ),
74 : // fsync_KILL:
75 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
76 : // fsync_ALLOW:
77 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
78 : // check_sendto:
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)(nl_req_fd)), /* and_3 */ 0, /* or_2 */ 8 ),
82 : // and_3:
83 : /* arg 3 low 32 bits */
84 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
85 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_4 */ 0, /* or_2 */ 6 ),
86 : // and_4:
87 : /* arg 4 high 32 bits */
88 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(4)),
89 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_6 */ 0, /* or_2 */ 4 ),
90 : // arg_hi_eq_6:
91 : /* arg 4 low 32 bits */
92 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(4)),
93 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_5 */ 0, /* or_2 */ 2 ),
94 : // and_5:
95 : /* arg 5 low 32 bits */
96 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(5)),
97 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* sendto_ALLOW */ 15, /* or_2 */ 0 ),
98 : // or_2:
99 : /* arg 0 low 32 bits */
100 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
101 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(arp_probe_fd)), /* and_7 */ 0, /* sendto_KILL */ 12 ),
102 : // and_7:
103 : /* arg 1 high 32 bits */
104 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(1)),
105 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_9 */ 0, /* sendto_KILL */ 10 ),
106 : // arg_hi_eq_9:
107 : /* arg 1 low 32 bits */
108 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
109 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_8 */ 0, /* sendto_KILL */ 8 ),
110 : // and_8:
111 : /* arg 2 high 32 bits */
112 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(2)),
113 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_11 */ 0, /* sendto_KILL */ 6 ),
114 : // arg_hi_eq_11:
115 : /* arg 2 low 32 bits */
116 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
117 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_10 */ 0, /* sendto_KILL */ 4 ),
118 : // and_10:
119 : /* arg 3 low 32 bits */
120 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
121 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(MSG_DONTWAIT), /* and_12 */ 0, /* sendto_KILL */ 2 ),
122 : // and_12:
123 : /* arg 5 low 32 bits */
124 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(5)),
125 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(FD_SOCKADDR_IN_SZ), /* sendto_ALLOW */ 1, /* sendto_KILL */ 0 ),
126 : // sendto_KILL:
127 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
128 : // sendto_ALLOW:
129 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
130 : // check_recvfrom:
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)(nl_mon_fd)), /* and_13 */ 2, /* or_14 */ 0 ),
134 : // or_14:
135 : /* arg 0 low 32 bits */
136 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
137 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(nl_req_fd)), /* and_13 */ 0, /* recvfrom_KILL */ 12 ),
138 : // and_13:
139 : /* arg 3 low 32 bits */
140 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
141 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_15 */ 2, /* or_16 */ 0 ),
142 : // or_16:
143 : /* arg 3 low 32 bits */
144 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
145 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(MSG_DONTWAIT), /* and_15 */ 0, /* recvfrom_KILL */ 8 ),
146 : // and_15:
147 : /* arg 4 high 32 bits */
148 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(4)),
149 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_18 */ 0, /* recvfrom_KILL */ 6 ),
150 : // arg_hi_eq_18:
151 : /* arg 4 low 32 bits */
152 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(4)),
153 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_17 */ 0, /* recvfrom_KILL */ 4 ),
154 : // and_17:
155 : /* arg 5 high 32 bits */
156 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(5)),
157 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_19 */ 0, /* recvfrom_KILL */ 2 ),
158 : // arg_hi_eq_19:
159 : /* arg 5 low 32 bits */
160 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(5)),
161 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* recvfrom_ALLOW */ 1, /* recvfrom_KILL */ 0 ),
162 : // recvfrom_KILL:
163 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
164 : // recvfrom_ALLOW:
165 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
166 0 : };
167 0 : fd_memcpy( out, filter, sizeof( filter ) );
168 0 : }
169 :
170 : #endif /* defined(__linux__) */
171 :
172 : #endif /* HEADER_fd_src_disco_netlink_generated_netlink_seccomp_h */
|