Line data Source code
1 : /* THIS FILE WAS GENERATED BY generate_filters.py. DO NOT EDIT BY HAND! */
2 : #ifndef HEADER_fd_src_disco_metrics_generated_fd_metric_tile_seccomp_h
3 : #define HEADER_fd_src_disco_metrics_generated_fd_metric_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 : static const unsigned int sock_filter_policy_fd_metric_tile_instr_cnt = 45;
28 :
29 0 : static void populate_sock_filter_policy_fd_metric_tile( ulong out_cnt, struct sock_filter * out, unsigned int logfile_fd, unsigned int metrics_socket_fd ) {
30 0 : FD_TEST( out_cnt >= 45 );
31 0 : struct sock_filter filter[45] = {
32 : /* Check: Jump to RET_KILL_PROCESS if the script's arch != the runtime arch */
33 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, arch ) ) ),
34 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, ARCH_NR, 0, /* RET_KILL_PROCESS */ 41 ),
35 : /* loading syscall number in accumulator */
36 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, ( offsetof( struct seccomp_data, nr ) ) ),
37 : /* allow write based on expression */
38 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_write, /* check_write */ 7, 0 ),
39 : /* allow fsync based on expression */
40 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_fsync, /* check_fsync */ 10, 0 ),
41 : /* allow accept4 based on expression */
42 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_accept4, /* check_accept4 */ 11, 0 ),
43 : /* allow read based on expression */
44 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_read, /* check_read */ 18, 0 ),
45 : /* allow sendto based on expression */
46 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_sendto, /* check_sendto */ 23, 0 ),
47 : /* allow close based on expression */
48 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_close, /* check_close */ 28, 0 ),
49 : /* simply allow ppoll */
50 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SYS_ppoll, /* RET_ALLOW */ 34, 0 ),
51 : /* none of the syscalls matched */
52 0 : { BPF_JMP | BPF_JA, 0, 0, /* RET_KILL_PROCESS */ 32 },
53 : // check_write:
54 : /* load syscall argument 0 in accumulator */
55 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
56 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 2, /* RET_ALLOW */ 31, /* lbl_1 */ 0 ),
57 : // lbl_1:
58 : /* load syscall argument 0 in accumulator */
59 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
60 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_ALLOW */ 29, /* RET_KILL_PROCESS */ 28 ),
61 : // check_fsync:
62 : /* load syscall argument 0 in accumulator */
63 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
64 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_ALLOW */ 27, /* RET_KILL_PROCESS */ 26 ),
65 : // check_accept4:
66 : /* load syscall argument 0 in accumulator */
67 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
68 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, metrics_socket_fd, /* lbl_2 */ 0, /* RET_KILL_PROCESS */ 24 ),
69 : // lbl_2:
70 : /* load syscall argument 1 in accumulator */
71 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
72 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_3 */ 0, /* RET_KILL_PROCESS */ 22 ),
73 : // lbl_3:
74 : /* load syscall argument 2 in accumulator */
75 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
76 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 0, /* lbl_4 */ 0, /* RET_KILL_PROCESS */ 20 ),
77 : // lbl_4:
78 : /* load syscall argument 3 in accumulator */
79 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[3])),
80 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, SOCK_CLOEXEC|SOCK_NONBLOCK, /* RET_ALLOW */ 19, /* RET_KILL_PROCESS */ 18 ),
81 : // check_read:
82 : /* load syscall argument 0 in accumulator */
83 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
84 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 2, /* RET_KILL_PROCESS */ 16, /* lbl_5 */ 0 ),
85 : // lbl_5:
86 : /* load syscall argument 0 in accumulator */
87 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
88 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_KILL_PROCESS */ 14, /* lbl_6 */ 0 ),
89 : // lbl_6:
90 : /* load syscall argument 0 in accumulator */
91 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
92 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, metrics_socket_fd, /* RET_KILL_PROCESS */ 12, /* RET_ALLOW */ 13 ),
93 : // check_sendto:
94 : /* load syscall argument 0 in accumulator */
95 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
96 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 2, /* RET_KILL_PROCESS */ 10, /* lbl_7 */ 0 ),
97 : // lbl_7:
98 : /* load syscall argument 0 in accumulator */
99 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
100 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_KILL_PROCESS */ 8, /* lbl_8 */ 0 ),
101 : // lbl_8:
102 : /* load syscall argument 0 in accumulator */
103 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
104 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, metrics_socket_fd, /* RET_KILL_PROCESS */ 6, /* RET_ALLOW */ 7 ),
105 : // check_close:
106 : /* load syscall argument 0 in accumulator */
107 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
108 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, 2, /* RET_KILL_PROCESS */ 4, /* lbl_9 */ 0 ),
109 : // lbl_9:
110 : /* load syscall argument 0 in accumulator */
111 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
112 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, logfile_fd, /* RET_KILL_PROCESS */ 2, /* lbl_10 */ 0 ),
113 : // lbl_10:
114 : /* load syscall argument 0 in accumulator */
115 0 : BPF_STMT( BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
116 0 : BPF_JUMP( BPF_JMP | BPF_JEQ | BPF_K, metrics_socket_fd, /* RET_KILL_PROCESS */ 0, /* RET_ALLOW */ 1 ),
117 : // RET_KILL_PROCESS:
118 : /* KILL_PROCESS is placed before ALLOW since it's the fallthrough case. */
119 0 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS ),
120 : // RET_ALLOW:
121 : /* ALLOW has to be reached by jumping */
122 : BPF_STMT( BPF_RET | BPF_K, SECCOMP_RET_ALLOW ),
123 0 : };
124 0 : fd_memcpy( out, filter, sizeof( filter ) );
125 0 : }
126 :
127 : #endif /* defined(__linux__) */
128 :
129 : #endif /* HEADER_fd_src_disco_metrics_generated_fd_metric_tile_seccomp_h */
|