Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_disco_net_sock_generated_fd_sock_tile_seccomp_h
3 : #define HEADER_fd_src_disco_net_sock_generated_fd_sock_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_sock_tile_instr_cnt = 42;
37 :
38 0 : static void populate_sock_filter_policy_fd_sock_tile( ulong out_cnt, struct sock_filter out[ static 42 ], uint logfile_fd, uint tx_fd, uint rx_fd0, uint rx_fd1 ) {
39 0 : FD_TEST( out_cnt >= 42 );
40 0 : struct sock_filter filter[42] = {
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 */ 6 ),
44 : /* load syscall number */
45 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) )),
46 : /* allow ppoll */
47 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_ppoll, /* RET_ALLOW */ 5, 0 ),
48 : /* check recvmmsg */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_recvmmsg, /* check_recvmmsg */ 5, 0 ),
50 : /* check sendmmsg */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendmmsg, /* check_sendmmsg */ 18, 0 ),
52 : /* check write */
53 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 25, 0 ),
54 : /* check fsync */
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 30, 0 ),
56 : // RET_KILL_PROCESS:
57 : /* default deny */
58 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
59 : // RET_ALLOW:
60 : /* allow */
61 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
62 : // check_recvmmsg:
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_JGE | BPF_K, ((uint)(rx_fd0)), /* and_2 */ 0, /* recvmmsg_KILL */ 10 ),
66 : // and_2:
67 : /* arg 0 low 32 bits */
68 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
69 0 : BPF_JUMP( BPF_JMP | BPF_JGE | BPF_K, ((uint)(rx_fd1)), /* recvmmsg_KILL */ 8, /* and_1 */ 0 ),
70 : // and_1:
71 : /* arg 2 low 32 bits */
72 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
73 0 : BPF_JUMP( BPF_JMP | BPF_JGT | BPF_K, 0x00000040U, /* recvmmsg_KILL */ 6, /* and_3 */ 0 ),
74 : // and_3:
75 : /* arg 3 low 32 bits */
76 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
77 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(MSG_DONTWAIT), /* and_4 */ 0, /* recvmmsg_KILL */ 4 ),
78 : // and_4:
79 : /* arg 4 high 32 bits */
80 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(4)),
81 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_5 */ 0, /* recvmmsg_KILL */ 2 ),
82 : // arg_hi_eq_5:
83 : /* arg 4 low 32 bits */
84 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(4)),
85 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* recvmmsg_ALLOW */ 1, /* recvmmsg_KILL */ 0 ),
86 : // recvmmsg_KILL:
87 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
88 : // recvmmsg_ALLOW:
89 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
90 : // check_sendmmsg:
91 : /* arg 0 low 32 bits */
92 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
93 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(tx_fd)), /* and_6 */ 0, /* sendmmsg_KILL */ 4 ),
94 : // and_6:
95 : /* arg 2 low 32 bits */
96 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
97 0 : BPF_JUMP( BPF_JMP | BPF_JGT | BPF_K, 0x00000040U, /* sendmmsg_KILL */ 2, /* and_7 */ 0 ),
98 : // and_7:
99 : /* arg 3 low 32 bits */
100 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(3)),
101 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(MSG_DONTWAIT), /* sendmmsg_ALLOW */ 1, /* sendmmsg_KILL */ 0 ),
102 : // sendmmsg_KILL:
103 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
104 : // sendmmsg_ALLOW:
105 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
106 : // check_write:
107 : /* arg 0 low 32 bits */
108 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
109 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* write_ALLOW */ 3, /* or_8 */ 0 ),
110 : // or_8:
111 : /* arg 0 low 32 bits */
112 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
113 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* write_ALLOW */ 1, /* write_KILL */ 0 ),
114 : // write_KILL:
115 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
116 : // write_ALLOW:
117 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
118 : // check_fsync:
119 : /* arg 0 low 32 bits */
120 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
121 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* fsync_ALLOW */ 1, /* fsync_KILL */ 0 ),
122 : // fsync_KILL:
123 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
124 : // fsync_ALLOW:
125 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
126 0 : };
127 0 : fd_memcpy( out, filter, sizeof( filter ) );
128 0 : }
129 :
130 : #endif /* defined(__linux__) */
131 :
132 : #endif /* HEADER_fd_src_disco_net_sock_generated_fd_sock_tile_seccomp_h */
|