Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_discof_replay_generated_fd_replay_tile_seccomp_h
3 : #define HEADER_fd_src_discof_replay_generated_fd_replay_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_replay_tile_instr_cnt = 46;
35 :
36 0 : static void populate_sock_filter_policy_fd_replay_tile( ulong out_cnt, struct sock_filter out[ static 46 ], uint logfile_fd, uint accounts_fd, uint store_fd ) {
37 0 : FD_TEST( out_cnt >= 46 );
38 0 : struct sock_filter filter[46] = {
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 */ 8 ),
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 */ 8, 0 ),
46 : /* check fsync */
47 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 13, 0 ),
48 : /* check pwritev2 */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pwritev2, /* check_pwritev2 */ 16, 0 ),
50 : /* check preadv2 */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_preadv2, /* check_preadv2 */ 19, 0 ),
52 : /* check fallocate */
53 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fallocate, /* check_fallocate */ 22, 0 ),
54 : /* check futex */
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_futex, /* check_futex */ 27, 0 ),
56 : /* check pread64 */
57 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pread64, /* check_pread64 */ 32, 0 ),
58 : // RET_KILL_PROCESS:
59 : /* default deny */
60 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
61 : // RET_ALLOW:
62 : /* allow */
63 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
64 : // check_write:
65 : /* arg 0 low 32 bits */
66 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
67 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000002U, /* write_ALLOW */ 3, /* or_1 */ 0 ),
68 : // or_1:
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, ((uint)(logfile_fd)), /* write_ALLOW */ 1, /* write_KILL */ 0 ),
72 : // write_KILL:
73 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
74 : // write_ALLOW:
75 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
76 : // check_fsync:
77 : /* arg 0 low 32 bits */
78 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
79 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* fsync_ALLOW */ 1, /* fsync_KILL */ 0 ),
80 : // fsync_KILL:
81 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
82 : // fsync_ALLOW:
83 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
84 : // check_pwritev2:
85 : /* arg 0 low 32 bits */
86 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
87 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(accounts_fd)), /* pwritev2_ALLOW */ 1, /* pwritev2_KILL */ 0 ),
88 : // pwritev2_KILL:
89 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
90 : // pwritev2_ALLOW:
91 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
92 : // check_preadv2:
93 : /* arg 0 low 32 bits */
94 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
95 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(accounts_fd)), /* preadv2_ALLOW */ 1, /* preadv2_KILL */ 0 ),
96 : // preadv2_KILL:
97 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
98 : // preadv2_ALLOW:
99 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
100 : // check_fallocate:
101 : /* arg 0 low 32 bits */
102 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
103 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(accounts_fd)), /* and_2 */ 0, /* fallocate_KILL */ 2 ),
104 : // and_2:
105 : /* arg 1 low 32 bits */
106 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
107 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* fallocate_ALLOW */ 1, /* fallocate_KILL */ 0 ),
108 : // fallocate_KILL:
109 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
110 : // fallocate_ALLOW:
111 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
112 : // check_futex:
113 : /* arg 1 low 32 bits */
114 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(1)),
115 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(FUTEX_WAKE), /* and_3 */ 0, /* futex_KILL */ 2 ),
116 : // and_3:
117 : /* arg 2 low 32 bits */
118 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
119 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000001U, /* futex_ALLOW */ 1, /* futex_KILL */ 0 ),
120 : // futex_KILL:
121 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
122 : // futex_ALLOW:
123 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
124 : // check_pread64:
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)(store_fd)), /* pread64_ALLOW */ 1, /* pread64_KILL */ 0 ),
128 : // pread64_KILL:
129 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
130 : // pread64_ALLOW:
131 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
132 0 : };
133 0 : fd_memcpy( out, filter, sizeof( filter ) );
134 0 : }
135 :
136 : #endif /* defined(__linux__) */
137 :
138 : #endif /* HEADER_fd_src_discof_replay_generated_fd_replay_tile_seccomp_h */
|