Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_app_shared_commands_watch_generated_watch_seccomp_h
3 : #define HEADER_fd_src_app_shared_commands_watch_generated_watch_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_watch_instr_cnt = 46;
37 :
38 0 : static void populate_sock_filter_policy_watch( ulong out_cnt, struct sock_filter out[ static 46 ], uint logfile_fd, uint drain_output_fd ) {
39 0 : FD_TEST( out_cnt >= 46 );
40 0 : struct sock_filter filter[46] = {
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 */ 8 ),
44 : /* load syscall number */
45 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) )),
46 : /* check write */
47 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 8, 0 ),
48 : /* check fsync */
49 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 15, 0 ),
50 : /* allow nanosleep */
51 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_nanosleep, /* RET_ALLOW */ 5, 0 ),
52 : /* allow sched_yield */
53 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sched_yield, /* RET_ALLOW */ 4, 0 ),
54 : /* allow exit_group */
55 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_exit_group, /* RET_ALLOW */ 3, 0 ),
56 : /* check read */
57 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_read, /* check_read */ 15, 0 ),
58 : /* check pselect6 */
59 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_pselect6, /* check_pselect6 */ 20, 0 ),
60 : // RET_KILL_PROCESS:
61 : /* default deny */
62 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
63 : // RET_ALLOW:
64 : /* allow */
65 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
66 : // check_write:
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_JEQ | BPF_K, 0x00000001U, /* write_ALLOW */ 5, /* or_1 */ 0 ),
70 : // or_1:
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, 0x00000002U, /* write_ALLOW */ 3, /* or_2 */ 0 ),
74 : // or_2:
75 : /* arg 0 low 32 bits */
76 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
77 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* write_ALLOW */ 1, /* write_KILL */ 0 ),
78 : // write_KILL:
79 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
80 : // write_ALLOW:
81 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
82 : // check_fsync:
83 : /* arg 0 low 32 bits */
84 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
85 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ((uint)(logfile_fd)), /* fsync_ALLOW */ 1, /* fsync_KILL */ 0 ),
86 : // fsync_KILL:
87 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
88 : // fsync_ALLOW:
89 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
90 : // check_read:
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)(drain_output_fd)), /* read_ALLOW */ 3, /* or_3 */ 0 ),
94 : // or_3:
95 : /* arg 0 low 32 bits */
96 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
97 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* read_ALLOW */ 1, /* read_KILL */ 0 ),
98 : // read_KILL:
99 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
100 : // read_ALLOW:
101 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
102 : // check_pselect6:
103 : /* arg 0 low 32 bits */
104 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(0)),
105 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, FD_SECCOMP_ARG_LO(drain_output_fd+1), /* and_4 */ 0, /* pselect6_KILL */ 12 ),
106 : // and_4:
107 : /* arg 2 high 32 bits */
108 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(2)),
109 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_6 */ 0, /* pselect6_KILL */ 10 ),
110 : // arg_hi_eq_6:
111 : /* arg 2 low 32 bits */
112 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(2)),
113 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* and_5 */ 0, /* pselect6_KILL */ 8 ),
114 : // and_5:
115 : /* arg 3 high 32 bits */
116 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(3)),
117 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_8 */ 0, /* pselect6_KILL */ 6 ),
118 : // arg_hi_eq_8:
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, 0x00000000U, /* and_7 */ 0, /* pselect6_KILL */ 4 ),
122 : // and_7:
123 : /* arg 5 high 32 bits */
124 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_HI_OFFSET(5)),
125 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* arg_hi_eq_9 */ 0, /* pselect6_KILL */ 2 ),
126 : // arg_hi_eq_9:
127 : /* arg 5 low 32 bits */
128 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, FD_SECCOMP_ARG_LO_OFFSET(5)),
129 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0x00000000U, /* pselect6_ALLOW */ 1, /* pselect6_KILL */ 0 ),
130 : // pselect6_KILL:
131 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
132 : // pselect6_ALLOW:
133 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
134 0 : };
135 0 : fd_memcpy( out, filter, sizeof( filter ) );
136 0 : }
137 :
138 : #endif /* defined(__linux__) */
139 :
140 : #endif /* HEADER_fd_src_app_shared_commands_watch_generated_watch_seccomp_h */
|