2 * seccomp example for x86 (32-bit and 64-bit) with BPF macros
4 * Copyright (c) 2012 The Chromium OS Authors <chromium-os-dev@chromium.org>
6 * Will Drewry <wad@chromium.org>
7 * Kees Cook <keescook@chromium.org>
9 * Use of this source code is governed by a BSD-style license that can be
10 * found in the LICENSE file.
12 * A stripped down version of the file found in this tutorial: http://outflux.net/teach-seccomp/.
14 #ifndef _SECCOMP_BPF_H_
15 #define _SECCOMP_BPF_H_
17 #ifndef SK_UNSAFE_BUILD_DESKTOP_ONLY
28 #include <sys/prctl.h>
29 #ifndef PR_SET_NO_NEW_PRIVS
30 # define PR_SET_NO_NEW_PRIVS 38
33 #include <linux/unistd.h>
34 #include <linux/audit.h>
35 #include <linux/filter.h>
36 #ifdef HAVE_LINUX_SECCOMP_H
37 # include <linux/seccomp.h>
39 #ifndef SECCOMP_MODE_FILTER
40 # define SECCOMP_MODE_FILTER 2 /* uses user-supplied filter. */
41 # define SECCOMP_RET_KILL 0x00000000U /* kill the task immediately */
42 # define SECCOMP_RET_TRAP 0x00030000U /* disallow and force a SIGSYS */
43 # define SECCOMP_RET_ALLOW 0x7fff0000U /* allow */
47 __u64 instruction_pointer;
52 # define SYS_SECCOMP 1
55 #define syscall_nr (offsetof(struct seccomp_data, nr))
57 #define EXAMINE_SYSCALL \
58 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, syscall_nr)
60 #define ALLOW_SYSCALL(name) \
61 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_##name, 0, 1), \
62 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW)
64 #define KILL_PROCESS \
65 BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_KILL)
67 #endif /* SK_UNSAFE_BUILD_DESKTOP_ONLY */
69 #endif /* _SECCOMP_BPF_H_ */