aboutgitcodelistschat:MatrixIRC
path: root/filter.h
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2022-12-21 14:49:09 +0100
committerAlice Frosi <afrosi@redhat.com>2022-12-21 14:55:52 +0100
commitf9613be602d9ff4f999fd216b52c59cd68cf71a3 (patch)
tree51c3c1c17f8e9029610e7de671da79a6cebae779 /filter.h
parentb8989e6bc221c7273ad70e2361a4f0457422cebe (diff)
downloadseitan-f9613be602d9ff4f999fd216b52c59cd68cf71a3.tar
seitan-f9613be602d9ff4f999fd216b52c59cd68cf71a3.tar.gz
seitan-f9613be602d9ff4f999fd216b52c59cd68cf71a3.tar.bz2
seitan-f9613be602d9ff4f999fd216b52c59cd68cf71a3.tar.lz
seitan-f9613be602d9ff4f999fd216b52c59cd68cf71a3.tar.xz
seitan-f9613be602d9ff4f999fd216b52c59cd68cf71a3.tar.zst
seitan-f9613be602d9ff4f999fd216b52c59cd68cf71a3.zip
Generation of bpf program
The build binary creates the bpf filter based on the syscalls defined in struct bpf_call. E.g: ./build test.bpf First, a table with the filtered syscalls is built in ascending order of syscall number and including the amount of syscalls of that type. After, the BPF filter with a binary search tree is constructed with: 1. the nodes for the tree search 2. the leaves with all the syscall numbers 3. every syscall arguments if present Then, the BPF instructions are written in the input file. Signed-off-by: Alice Frosi <afrosi@redhat.com>
Diffstat (limited to 'filter.h')
-rw-r--r--filter.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/filter.h b/filter.h
new file mode 100644
index 0000000..134a16b
--- /dev/null
+++ b/filter.h
@@ -0,0 +1,39 @@
+#ifndef FILTER_H_
+#define FILTER_H_
+
+#include <linux/filter.h>
+#include <linux/audit.h>
+#include <linux/seccomp.h>
+
+#define JGE(nr, right, left) \
+ BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, (nr), (right), (left))
+#define JUMPA(jump) BPF_JUMP(BPF_JMP | BPF_JA, (jump), 0, 0)
+#define EQ(nr, a1, a2) BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, (nr), (a1), (a2))
+
+#define MAX_FILTER 1024
+
+#define MAX_JUMPS 128
+#define EMPTY -1
+
+struct bpf_call {
+ char *name;
+ int args[6];
+ bool check_arg[6];
+};
+
+struct syscall_entry {
+ unsigned int count;
+ long nr;
+ const struct bpf_call *entry;
+};
+
+void create_lookup_nodes(int jumps[], unsigned int n);
+unsigned int left_child(unsigned int parent_index);
+unsigned int right_child(unsigned int parent_index);
+
+unsigned int create_bfp_program(struct syscall_entry table[],
+ struct sock_filter filter[],
+ unsigned int n_syscall);
+int convert_bpf(char *file, struct bpf_call *entries, int n);
+
+#endif