diff options
23 files changed, 877 insertions, 147 deletions
diff --git a/libc/SECCOMP_BLACKLIST.TXT b/libc/SECCOMP_BLACKLIST_COMMON.TXT index 28345155fb..f279002fee 100644 --- a/libc/SECCOMP_BLACKLIST.TXT +++ b/libc/SECCOMP_BLACKLIST_COMMON.TXT @@ -26,7 +26,7 @@ # # - Each parameter type is assumed to be stored in 32 bits. # -# This file is processed by a python script named gensyscalls.py. +# This file is processed by a python script named genseccomp.py. int swapon(const char*, int) all int swapoff(const char*) all diff --git a/libc/SECCOMP_WHITELIST_APP.TXT b/libc/SECCOMP_WHITELIST_APP.TXT new file mode 100644 index 0000000000..2f3618c440 --- /dev/null +++ b/libc/SECCOMP_WHITELIST_APP.TXT @@ -0,0 +1,26 @@ +# This file is used to populate seccomp's whitelist policy in combination with SYSCALLS.TXT. +# Note that the resultant policy is applied only to zygote spawned processes. +# +# Each non-blank, non-comment line has the following format: +# +# return_type func_name[|alias_list][:syscall_name[:socketcall_id]]([parameter_list]) arch_list +# +# where: +# arch_list ::= "all" | arch+ +# arch ::= "arm" | "arm64" | "mips" | "mips64" | "x86" | "x86_64" +# +# Note: +# - syscall_name corresponds to the name of the syscall, which may differ from +# the exported function name (example: the exit syscall is implemented by the _exit() +# function, which is not the same as the standard C exit() function which calls it) + +# - alias_list is optional comma separated list of function aliases +# +# - The call_id parameter, given that func_name and syscall_name have +# been provided, allows the user to specify dispatch style syscalls. +# For example, socket() syscall on i386 actually becomes: +# socketcall(__NR_socket, 1, *(rest of args on stack)). +# +# - Each parameter type is assumed to be stored in 32 bits. +# +# This file is processed by a python script named genseccomp.py. diff --git a/libc/SECCOMP_WHITELIST.TXT b/libc/SECCOMP_WHITELIST_COMMON.TXT index 36a579ba11..a620b4444e 100644 --- a/libc/SECCOMP_WHITELIST.TXT +++ b/libc/SECCOMP_WHITELIST_COMMON.TXT @@ -23,7 +23,7 @@ # # - Each parameter type is assumed to be stored in 32 bits. # -# This file is processed by a python script named gensyscalls.py. +# This file is processed by a python script named genseccomp.py. # syscalls needed to boot android int pivot_root:pivot_root(const char *new_root, const char *put_old) arm64,x86_64,mips64 diff --git a/libc/SECCOMP_WHITELIST_SYSTEM.TXT b/libc/SECCOMP_WHITELIST_SYSTEM.TXT new file mode 100644 index 0000000000..2f3618c440 --- /dev/null +++ b/libc/SECCOMP_WHITELIST_SYSTEM.TXT @@ -0,0 +1,26 @@ +# This file is used to populate seccomp's whitelist policy in combination with SYSCALLS.TXT. +# Note that the resultant policy is applied only to zygote spawned processes. +# +# Each non-blank, non-comment line has the following format: +# +# return_type func_name[|alias_list][:syscall_name[:socketcall_id]]([parameter_list]) arch_list +# +# where: +# arch_list ::= "all" | arch+ +# arch ::= "arm" | "arm64" | "mips" | "mips64" | "x86" | "x86_64" +# +# Note: +# - syscall_name corresponds to the name of the syscall, which may differ from +# the exported function name (example: the exit syscall is implemented by the _exit() +# function, which is not the same as the standard C exit() function which calls it) + +# - alias_list is optional comma separated list of function aliases +# +# - The call_id parameter, given that func_name and syscall_name have +# been provided, allows the user to specify dispatch style syscalls. +# For example, socket() syscall on i386 actually becomes: +# socketcall(__NR_socket, 1, *(rest of args on stack)). +# +# - Each parameter type is assumed to be stored in 32 bits. +# +# This file is processed by a python script named genseccomp.py. diff --git a/libc/malloc_debug/README.md b/libc/malloc_debug/README.md index bb56cb8bb0..b7a12a5c69 100644 --- a/libc/malloc_debug/README.md +++ b/libc/malloc_debug/README.md @@ -484,15 +484,15 @@ Enable backtrace tracking for the zygote and zygote based processes: adb shell setprop libc.debug.malloc.options backtrace adb shell start -Enable multiple options (backtrace and guards): +Enable multiple options (backtrace and guard): adb shell stop - adb shell setprop libc.debug.malloc.options "\"backtrace guards\"" + adb shell setprop libc.debug.malloc.options "\"backtrace guard\"" adb shell start Note: The two levels of quoting in the adb shell command is necessary. The outer layer of quoting is for the shell on the host, to ensure that the -inner layer of quoting is sent to the device, to make 'backtrace guards' +inner layer of quoting is sent to the device, to make 'backtrace guard' a single argument. Enable malloc debug using an environment variable (pre-O Android release): diff --git a/libc/seccomp/Android.bp b/libc/seccomp/Android.bp index b3707bc2ff..bb91849272 100644 --- a/libc/seccomp/Android.bp +++ b/libc/seccomp/Android.bp @@ -2,18 +2,24 @@ cc_library { name: "libseccomp_policy", srcs: [ "seccomp_policy.cpp", - "arm_policy.cpp", + "arm_app_policy.cpp", "arm_global_policy.cpp", - "arm64_policy.cpp", + "arm_system_policy.cpp", + "arm64_app_policy.cpp", "arm64_global_policy.cpp", - "x86_policy.cpp", + "arm64_system_policy.cpp", + "x86_app_policy.cpp", "x86_global_policy.cpp", - "x86_64_policy.cpp", + "x86_system_policy.cpp", + "x86_64_app_policy.cpp", "x86_64_global_policy.cpp", - "mips_policy.cpp", + "x86_64_system_policy.cpp", + "mips_app_policy.cpp", "mips_global_policy.cpp", - "mips64_policy.cpp", + "mips_system_policy.cpp", + "mips64_app_policy.cpp", "mips64_global_policy.cpp", + "mips64_system_policy.cpp", ], export_include_dirs: ["include"], cflags: ["-Wall", "-Werror"], diff --git a/libc/seccomp/arm64_policy.cpp b/libc/seccomp/arm64_app_policy.cpp index c52c737355..12722e1942 100644 --- a/libc/seccomp/arm64_policy.cpp +++ b/libc/seccomp/arm64_app_policy.cpp @@ -4,7 +4,7 @@ #include <errno.h> #include "seccomp_bpfs.h" -const sock_filter arm64_filter[] = { +const sock_filter arm64_app_filter[] = { BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 32), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 15, 0), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 101, 7, 0), @@ -40,4 +40,4 @@ BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 288, 1, 0), //mlock2|copy_file_range|preadv2|pwr BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; -const size_t arm64_filter_size = sizeof(arm64_filter) / sizeof(struct sock_filter); +const size_t arm64_app_filter_size = sizeof(arm64_app_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/arm64_system_policy.cpp b/libc/seccomp/arm64_system_policy.cpp new file mode 100644 index 0000000000..a8d71932d3 --- /dev/null +++ b/libc/seccomp/arm64_system_policy.cpp @@ -0,0 +1,43 @@ +// Autogenerated file - edit at your peril!! + +#include <linux/filter.h> +#include <errno.h> + +#include "seccomp_bpfs.h" +const sock_filter arm64_system_filter[] = { +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 32), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 15, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 101, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 18, 27, 26), //io_setup|io_destroy|io_submit|io_cancel|io_getevents|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|getcwd +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 42, 26, 25), //eventfd2|epoll_create1|epoll_ctl|epoll_pwait|dup|dup3|fcntl|inotify_init1|inotify_add_watch|inotify_rm_watch|ioctl|ioprio_set|ioprio_get|flock|mknodat|mkdirat|unlinkat|symlinkat|linkat|renameat|umount2|mount|pivot_root +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 59, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 24, 23), //statfs|fstatfs|truncate|ftruncate|fallocate|faccessat|chdir|fchdir|chroot|fchmod|fchmodat|fchownat|fchown|openat|close +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 99, 23, 22), //pipe2|quotactl|getdents64|lseek|read|write|readv|writev|pread64|pwrite64|preadv|pwritev|sendfile|pselect6|ppoll|signalfd4|vmsplice|splice|tee|readlinkat|newfstatat|fstat|sync|fsync|fdatasync|sync_file_range|timerfd_create|timerfd_settime|timerfd_gettime|utimensat|acct|capget|capset|personality|exit|exit_group|waitid|set_tid_address|unshare|futex +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 105, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 104, 20, 19), //nanosleep|getitimer|setitimer +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 19, 18), //init_module|delete_module|timer_create|timer_gettime|timer_getoverrun|timer_settime|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|syslog|ptrace|sched_setparam|sched_setscheduler|sched_getscheduler|sched_getparam|sched_setaffinity|sched_getaffinity|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|restart_syscall|kill|tkill|tgkill|sigaltstack|rt_sigsuspend|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigreturn|setpriority|getpriority|reboot|setregid|setgid|setreuid|setuid|setresuid|getresuid|setresgid|getresgid|setfsuid|setfsgid|times|setpgid|getpgid|getsid|setsid|getgroups|setgroups|uname|sethostname|setdomainname|getrlimit|setrlimit|getrusage|umask|prctl|getcpu|gettimeofday|settimeofday|adjtimex|getpid|getppid|getuid|geteuid|getgid|getegid|gettid|sysinfo +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 203, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 17, 16), //socket|socketpair|bind|listen +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 16, 15), //connect|getsockname|getpeername|sendto|recvfrom|setsockopt|getsockopt|shutdown|sendmsg|recvmsg|readahead|brk|munmap|mremap +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 266, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 240, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 226, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 12, 11), //clone|execve|mmap|fadvise64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 234, 11, 10), //mprotect|msync|mlock|munlock|mlockall|munlockall|mincore|madvise +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 260, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 9, 8), //rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 8, 7), //wait4|prlimit64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 281, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 274, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 5, 4), //clock_adjtime|syncfs|setns|sendmmsg|process_vm_readv|process_vm_writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 4, 3), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 2, 1), //execveat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 288, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2 +BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), +}; + +const size_t arm64_system_filter_size = sizeof(arm64_system_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/arm_policy.cpp b/libc/seccomp/arm_app_policy.cpp index 2bc168a3e9..d0fd6cacba 100644 --- a/libc/seccomp/arm_policy.cpp +++ b/libc/seccomp/arm_app_policy.cpp @@ -4,7 +4,7 @@ #include <errno.h> #include "seccomp_bpfs.h" -const sock_filter arm_filter[] = { +const sock_filter arm_app_filter[] = { BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 126), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 63, 0), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 31, 0), @@ -134,4 +134,4 @@ BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 1, 0), //__ARM_NR_set_tls BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; -const size_t arm_filter_size = sizeof(arm_filter) / sizeof(struct sock_filter); +const size_t arm_app_filter_size = sizeof(arm_app_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/arm_system_policy.cpp b/libc/seccomp/arm_system_policy.cpp new file mode 100644 index 0000000000..de6703899b --- /dev/null +++ b/libc/seccomp/arm_system_policy.cpp @@ -0,0 +1,137 @@ +// Autogenerated file - edit at your peril!! + +#include <linux/filter.h> +#include <errno.h> + +#include "seccomp_bpfs.h" +const sock_filter arm_system_filter[] = { +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 126), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 63, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 31, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 15, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 119, 118), //restart_syscall|exit|fork|read|write|open|close +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 118, 117), //creat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 116, 115), //unlink|execve|chdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 115, 114), //lseek|getpid|mount +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 112, 111), //getuid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 111, 110), //ptrace +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 109, 108), //access +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 40, 108, 107), //sync|kill|rename|mkdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 104, 103), //dup|pipe|times +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 103, 102), //brk +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 101, 100), //acct|umount2 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 100, 99), //ioctl|fcntl +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 63, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 97, 96), //setpgid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 96, 95), //umask|chroot +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 94, 93), //dup2|getppid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 93, 92), //setsid|sigaction +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 15, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 88, 87), //sethostname|setrlimit +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 87, 86), //getrusage|gettimeofday|settimeofday +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 88, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 85, 84), //readlink +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 84, 83), //reboot +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 81, 80), //munmap|truncate +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 80, 79), //fchmod +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 103, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 78, 77), //getpriority|setpriority +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 77, 76), //syslog|setitimer|getitimer +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 73, 72), //wait4 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 72, 71), //sysinfo +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 70, 69), //fsync|sigreturn|clone|setdomainname|uname +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 69, 68), //adjtimex|mprotect +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 66, 65), //init_module|delete_module +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 65, 64), //quotactl|getpgid|fchdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 63, 62), //personality +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 62, 61), //setfsuid|setfsgid|_llseek|getdents|_newselect|flock|msync|readv|writev|getsid|fdatasync +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 292, 31, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 219, 15, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 56, 55), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 55, 54), //poll +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 53, 52), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 52, 51), //getcwd|capget|capset|sigaltstack|sendfile +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 49, 48), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 48, 47), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 46, 45), //setuid32|setgid32 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 45, 44), //getdents64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 270, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 41, 40), //mincore|madvise|fcntl64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 249, 40, 39), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 38, 37), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 269, 37, 36), //set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 286, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 34, 33), //arm_fadvise64_64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 33, 32), //waitid|socket|bind|connect|listen +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 290, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 289, 31, 30), //getsockname|getpeername|socketpair +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 30, 29), //sendto +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 369, 15, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 316, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 298, 25, 24), //recvfrom|shutdown|setsockopt|getsockopt|sendmsg|recvmsg +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 319, 24, 23), //inotify_init|inotify_add_watch|inotify_rm_watch +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 327, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 326, 22, 21), //openat|mkdirat|mknodat|fchownat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 338, 21, 20), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 348, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 344, 18, 17), //splice|sync_file_range2|tee|vmsplice +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 347, 17, 16), //getcpu|epoll_pwait +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 350, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 15, 14), //utimensat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 367, 14, 13), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg|accept4 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 390, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 372, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 370, 10, 9), //prlimit64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 378, 9, 8), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 387, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 386, 7, 6), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 388, 6, 5), //execveat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983045, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983042, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 394, 3, 2), //mlock2|copy_file_range|preadv2|pwritev2 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983043, 2, 1), //__ARM_NR_cacheflush +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 983046, 1, 0), //__ARM_NR_set_tls +BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), +}; + +const size_t arm_system_filter_size = sizeof(arm_system_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/include/seccomp_policy.h b/libc/seccomp/include/seccomp_policy.h index e337decce5..ed1901b10a 100644 --- a/libc/seccomp/include/seccomp_policy.h +++ b/libc/seccomp/include/seccomp_policy.h @@ -20,8 +20,11 @@ #include <stddef.h> #include <linux/filter.h> +// TODO(victorhsieh): remove once the callers are switched to the new API. bool set_seccomp_filter(); + +bool set_app_seccomp_filter(); +bool set_system_seccomp_filter(); bool set_global_seccomp_filter(); -void get_seccomp_filter(const sock_filter*& filter, size_t& filter_size); #endif diff --git a/libc/seccomp/mips64_policy.cpp b/libc/seccomp/mips64_app_policy.cpp index 26967ce6c8..27bb0fa172 100644 --- a/libc/seccomp/mips64_policy.cpp +++ b/libc/seccomp/mips64_app_policy.cpp @@ -4,7 +4,7 @@ #include <errno.h> #include "seccomp_bpfs.h" -const sock_filter mips64_filter[] = { +const sock_filter mips64_app_filter[] = { BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5000, 0, 84), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5164, 41, 0), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5077, 21, 0), @@ -92,4 +92,4 @@ BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5323, 1, 0), //mlock2|copy_file_range|preadv2|pw BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; -const size_t mips64_filter_size = sizeof(mips64_filter) / sizeof(struct sock_filter); +const size_t mips64_app_filter_size = sizeof(mips64_app_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/mips64_system_policy.cpp b/libc/seccomp/mips64_system_policy.cpp new file mode 100644 index 0000000000..8f34d417cb --- /dev/null +++ b/libc/seccomp/mips64_system_policy.cpp @@ -0,0 +1,95 @@ +// Autogenerated file - edit at your peril!! + +#include <linux/filter.h> +#include <errno.h> + +#include "seccomp_bpfs.h" +const sock_filter mips64_system_filter[] = { +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5000, 0, 84), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5164, 41, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5077, 21, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5034, 11, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5008, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5005, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5003, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5002, 77, 76), //read|write +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5004, 76, 75), //close +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5006, 75, 74), //fstat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5031, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5023, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5020, 72, 71), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|ioctl|pread64|pwrite64|readv|writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5028, 71, 70), //sched_yield|mremap|msync|mincore|madvise +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5032, 70, 69), //dup +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5057, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5043, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5038, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5037, 66, 65), //nanosleep|getitimer|setitimer +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5042, 65, 64), //getpid|sendfile|socket|connect +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5056, 64, 63), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5070, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5062, 62, 61), //execve|exit|wait4|kill|uname +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5076, 61, 60), //fcntl|flock|fsync|fdatasync|truncate|ftruncate +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5132, 9, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5093, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5091, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5089, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5080, 56, 55), //getcwd|chdir|fchdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5090, 55, 54), //fchmod +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5092, 54, 53), //fchown +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5110, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5109, 52, 51), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5130, 51, 50), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5151, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5137, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5134, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5133, 47, 46), //personality +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5136, 46, 45), //statfs|fstatfs +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5150, 45, 44), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5153, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5152, 43, 42), //pivot_root +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5162, 42, 41), //prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5244, 21, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5208, 11, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5178, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5172, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5168, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5167, 36, 35), //reboot|sethostname|setdomainname +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5170, 35, 34), //init_module|delete_module +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5173, 34, 33), //quotactl +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5200, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5194, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5193, 31, 30), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5198, 30, 29), //futex|sched_setaffinity|sched_getaffinity|cacheflush +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5206, 29, 28), //io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5237, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5215, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5211, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5209, 25, 24), //epoll_ctl +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5214, 24, 23), //rt_sigreturn|set_tid_address|restart_syscall +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5226, 23, 22), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5242, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5238, 21, 20), //waitid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5243, 20, 19), //set_thread_area +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5297, 9, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5271, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5252, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5247, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5246, 15, 14), //inotify_add_watch|inotify_rm_watch +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5251, 14, 13), //openat|mkdirat|mknodat|fchownat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5267, 13, 12), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5279, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5276, 11, 10), //getcpu|epoll_pwait|ioprio_set|ioprio_get|utimensat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5295, 10, 9), //fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5316, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5308, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5300, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5298, 6, 5), //prlimit64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5306, 5, 4), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5315, 4, 3), //getdents64|sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5319, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5317, 2, 1), //execveat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5323, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2 +BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), +}; + +const size_t mips64_system_filter_size = sizeof(mips64_system_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/mips_policy.cpp b/libc/seccomp/mips_app_policy.cpp index 7485b906f1..abda7eb1c5 100644 --- a/libc/seccomp/mips_policy.cpp +++ b/libc/seccomp/mips_app_policy.cpp @@ -4,7 +4,7 @@ #include <errno.h> #include "seccomp_bpfs.h" -const sock_filter mips_filter[] = { +const sock_filter mips_app_filter[] = { BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4001, 0, 110), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4131, 55, 0), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4063, 27, 0), @@ -118,4 +118,4 @@ BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4363, 1, 0), //mlock2|copy_file_range|preadv2|pw BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; -const size_t mips_filter_size = sizeof(mips_filter) / sizeof(struct sock_filter); +const size_t mips_app_filter_size = sizeof(mips_app_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/mips_system_policy.cpp b/libc/seccomp/mips_system_policy.cpp new file mode 100644 index 0000000000..7b9da60e71 --- /dev/null +++ b/libc/seccomp/mips_system_policy.cpp @@ -0,0 +1,121 @@ +// Autogenerated file - edit at your peril!! + +#include <linux/filter.h> +#include <errno.h> + +#include "seccomp_bpfs.h" +const sock_filter mips_system_filter[] = { +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4001, 0, 110), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4131, 55, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4063, 27, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4036, 13, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4023, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4010, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4008, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4007, 103, 102), //exit|fork|read|write|open|close +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4009, 102, 101), //creat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4019, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4013, 100, 99), //unlink|execve|chdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4022, 99, 98), //lseek|getpid|mount +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4033, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4026, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4025, 96, 95), //setuid|getuid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4027, 95, 94), //ptrace +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4034, 94, 93), //access +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4054, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4045, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4041, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4040, 90, 89), //sync|kill|rename|mkdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4044, 89, 88), //dup|pipe|times +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4049, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4048, 87, 86), //brk|setgid|getgid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4053, 86, 85), //geteuid|getegid|acct|umount2 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4060, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4057, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4056, 83, 82), //ioctl|fcntl +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4058, 82, 81), //setpgid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4062, 81, 80), //umask|chroot +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4094, 13, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4085, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4070, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4066, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4065, 76, 75), //dup2|getppid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4068, 75, 74), //setsid|sigaction +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4074, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4072, 73, 72), //setreuid|setregid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4082, 72, 71), //sethostname|setrlimit|getrlimit|getrusage|gettimeofday|settimeofday|getgroups|setgroups +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4090, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4088, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4086, 69, 68), //readlink +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4089, 68, 67), //reboot +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4093, 67, 66), //mmap|munmap|truncate +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4118, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4114, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4103, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4098, 63, 62), //fchmod|fchown|getpriority|setpriority +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4106, 62, 61), //syslog|setitimer|getitimer +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4116, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4115, 60, 59), //wait4 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4117, 59, 58), //sysinfo +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4128, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4124, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4123, 56, 55), //fsync|sigreturn|clone|setdomainname|uname +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4126, 55, 54), //adjtimex|mprotect +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4130, 54, 53), //init_module|delete_module +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4248, 27, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4179, 13, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4154, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4138, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4136, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4134, 48, 47), //quotactl|getpgid|fchdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4137, 47, 46), //personality +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4151, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4148, 45, 44), //setfsuid|setfsgid|_llseek|getdents|_newselect|flock|msync|readv|writev|cacheflush +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4153, 44, 43), //getsid|fdatasync +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4176, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4169, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4168, 41, 40), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4175, 40, 39), //bind|connect|getpeername|getsockname|getsockopt|listen +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4178, 39, 38), //recvfrom|recvmsg +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4210, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4190, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4188, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4187, 35, 34), //sendmsg|sendto|setsockopt|shutdown|socket|socketpair|setresuid|getresuid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4189, 34, 33), //poll +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4203, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4202, 32, 31), //setresgid|getresgid|prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4208, 31, 30), //getcwd|capget|capset|sigaltstack|sendfile +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4222, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4217, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4216, 28, 27), //mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4221, 27, 26), //mincore|madvise|getdents64|fcntl64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4247, 26, 25), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|io_setup|io_destroy|io_getevents|io_submit|io_cancel|exit_group +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4319, 13, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4293, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4283, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4278, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4267, 21, 20), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages|set_tid_address|restart_syscall|fadvise64|statfs64|fstatfs64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|tgkill +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4279, 20, 19), //waitid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4288, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4287, 18, 17), //set_thread_area|inotify_init|inotify_add_watch|inotify_rm_watch +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4292, 17, 16), //openat|mkdirat|mknodat|fchownat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4316, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4312, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4308, 14, 13), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare|splice|sync_file_range|tee|vmsplice +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4314, 13, 12), //getcpu|epoll_pwait +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4317, 12, 11), //utimensat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4349, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4341, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4338, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4336, 8, 7), //eventfd|fallocate|timerfd_create|timerfd_gettime|timerfd_settime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|accept4|recvmmsg +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4339, 7, 6), //prlimit64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4347, 6, 5), //clock_adjtime|syncfs|sendmmsg|setns|process_vm_readv|process_vm_writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4359, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4356, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4355, 3, 2), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4357, 2, 1), //execveat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4363, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2 +BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), +}; + +const size_t mips_system_filter_size = sizeof(mips_system_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/seccomp_bpfs.h b/libc/seccomp/seccomp_bpfs.h index a8f47ca814..8728c36235 100644 --- a/libc/seccomp/seccomp_bpfs.h +++ b/libc/seccomp/seccomp_bpfs.h @@ -20,28 +20,45 @@ #include <stddef.h> #include <linux/seccomp.h> -extern const struct sock_filter arm_filter[]; -extern const size_t arm_filter_size; +extern const struct sock_filter arm_app_filter[]; +extern const size_t arm_app_filter_size; +extern const struct sock_filter arm_system_filter[]; +extern const size_t arm_system_filter_size; extern const struct sock_filter arm_global_filter[]; extern const size_t arm_global_filter_size; -extern const struct sock_filter arm64_filter[]; -extern const size_t arm64_filter_size; + +extern const struct sock_filter arm64_app_filter[]; +extern const size_t arm64_app_filter_size; +extern const struct sock_filter arm64_system_filter[]; +extern const size_t arm64_system_filter_size; extern const struct sock_filter arm64_global_filter[]; extern const size_t arm64_global_filter_size; -extern const struct sock_filter x86_filter[]; -extern const size_t x86_filter_size; + +extern const struct sock_filter x86_app_filter[]; +extern const size_t x86_app_filter_size; +extern const struct sock_filter x86_system_filter[]; +extern const size_t x86_system_filter_size; extern const struct sock_filter x86_global_filter[]; extern const size_t x86_global_filter_size; -extern const struct sock_filter x86_64_filter[]; -extern const size_t x86_64_filter_size; + +extern const struct sock_filter x86_64_app_filter[]; +extern const size_t x86_64_app_filter_size; +extern const struct sock_filter x86_64_system_filter[]; +extern const size_t x86_64_system_filter_size; extern const struct sock_filter x86_64_global_filter[]; extern const size_t x86_64_global_filter_size; -extern const struct sock_filter mips_filter[]; -extern const size_t mips_filter_size; + +extern const struct sock_filter mips_app_filter[]; +extern const size_t mips_app_filter_size; +extern const struct sock_filter mips_system_filter[]; +extern const size_t mips_system_filter_size; extern const struct sock_filter mips_global_filter[]; extern const size_t mips_global_filter_size; -extern const struct sock_filter mips64_filter[]; -extern const size_t mips64_filter_size; + +extern const struct sock_filter mips64_app_filter[]; +extern const size_t mips64_app_filter_size; +extern const struct sock_filter mips64_system_filter[]; +extern const size_t mips64_system_filter_size; extern const struct sock_filter mips64_global_filter[]; extern const size_t mips64_global_filter_size; diff --git a/libc/seccomp/seccomp_policy.cpp b/libc/seccomp/seccomp_policy.cpp index 19ef299dfa..99a821fc6a 100644 --- a/libc/seccomp/seccomp_policy.cpp +++ b/libc/seccomp/seccomp_policy.cpp @@ -32,13 +32,17 @@ #define DUAL_ARCH #define PRIMARY_ARCH AUDIT_ARCH_AARCH64 -static const struct sock_filter* primary_filter = arm64_filter; -static const size_t primary_filter_size = arm64_filter_size; +static const struct sock_filter* primary_app_filter = arm64_app_filter; +static const size_t primary_app_filter_size = arm64_app_filter_size; +static const struct sock_filter* primary_system_filter = arm64_system_filter; +static const size_t primary_system_filter_size = arm64_system_filter_size; static const struct sock_filter* primary_global_filter = arm64_global_filter; static const size_t primary_global_filter_size = arm64_global_filter_size; #define SECONDARY_ARCH AUDIT_ARCH_ARM -static const struct sock_filter* secondary_filter = arm_filter; -static const size_t secondary_filter_size = arm_filter_size; +static const struct sock_filter* secondary_app_filter = arm_app_filter; +static const size_t secondary_app_filter_size = arm_app_filter_size; +static const struct sock_filter* secondary_system_filter = arm_system_filter; +static const size_t secondary_system_filter_size = arm_system_filter_size; static const struct sock_filter* secondary_global_filter = arm_global_filter; static const size_t secondary_global_filter_size = arm_global_filter_size; @@ -46,13 +50,17 @@ static const size_t secondary_global_filter_size = arm_global_filter_size; #define DUAL_ARCH #define PRIMARY_ARCH AUDIT_ARCH_X86_64 -static const struct sock_filter* primary_filter = x86_64_filter; -static const size_t primary_filter_size = x86_64_filter_size; +static const struct sock_filter* primary_app_filter = x86_64_app_filter; +static const size_t primary_app_filter_size = x86_64_app_filter_size; +static const struct sock_filter* primary_system_filter = x86_64_system_filter; +static const size_t primary_system_filter_size = x86_64_system_filter_size; static const struct sock_filter* primary_global_filter = x86_64_global_filter; static const size_t primary_global_filter_size = x86_64_global_filter_size; #define SECONDARY_ARCH AUDIT_ARCH_I386 -static const struct sock_filter* secondary_filter = x86_filter; -static const size_t secondary_filter_size = x86_filter_size; +static const struct sock_filter* secondary_app_filter = x86_app_filter; +static const size_t secondary_app_filter_size = x86_app_filter_size; +static const struct sock_filter* secondary_system_filter = x86_system_filter; +static const size_t secondary_system_filter_size = x86_system_filter_size; static const struct sock_filter* secondary_global_filter = x86_global_filter; static const size_t secondary_global_filter_size = x86_global_filter_size; @@ -60,13 +68,17 @@ static const size_t secondary_global_filter_size = x86_global_filter_size; #define DUAL_ARCH #define PRIMARY_ARCH AUDIT_ARCH_MIPSEL64 -static const struct sock_filter* primary_filter = mips64_filter; -static const size_t primary_filter_size = mips64_filter_size; +static const struct sock_filter* primary_app_filter = mips64_app_filter; +static const size_t primary_app_filter_size = mips64_app_filter_size; +static const struct sock_filter* primary_system_filter = mips64_system_filter; +static const size_t primary_system_filter_size = mips64_system_filter_size; static const struct sock_filter* primary_global_filter = mips64_global_filter; static const size_t primary_global_filter_size = mips64_global_filter_size; #define SECONDARY_ARCH AUDIT_ARCH_MIPSEL -static const struct sock_filter* secondary_filter = mips_filter; -static const size_t secondary_filter_size = mips_filter_size; +static const struct sock_filter* secondary_app_filter = mips_app_filter; +static const size_t secondary_app_filter_size = mips_app_filter_size; +static const struct sock_filter* secondary_system_filter = mips_system_filter; +static const size_t secondary_system_filter_size = mips_system_filter_size; static const struct sock_filter* secondary_global_filter = mips_global_filter; static const size_t secondary_global_filter_size = mips_global_filter_size; @@ -122,30 +134,48 @@ static bool install_filter(filter const& f) { const_cast<struct sock_filter*>(&f[0]), }; + if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) { + PLOG(FATAL) << "Could not set to no new privs"; + return false; + } if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) < 0) { PLOG(FATAL) << "Could not set seccomp filter of size " << f.size(); return false; } - - LOG(INFO) << "Global filter of size " << f.size() << " installed"; return true; } -bool _set_seccomp_filter(bool global) { +enum FilterType { + APP, + SYSTEM, + GLOBAL +}; + +bool _set_seccomp_filter(FilterType type) { const sock_filter *p, *s; size_t p_size, s_size; filter f; - if (global) { + switch (type) { + case APP: + p = primary_app_filter; + p_size = primary_app_filter_size; + s = secondary_app_filter; + s_size = secondary_app_filter_size; + break; + case SYSTEM: + p = primary_system_filter; + p_size = primary_system_filter_size; + s = secondary_system_filter; + s_size = secondary_system_filter_size; + break; + case GLOBAL: p = primary_global_filter; p_size = primary_global_filter_size; s = secondary_global_filter; s_size = secondary_global_filter_size; - } else { - p = primary_filter; - p_size = primary_filter_size; - s = secondary_filter; - s_size = secondary_filter_size; + break; + } #ifdef DUAL_ARCH @@ -181,19 +211,17 @@ bool _set_seccomp_filter(bool global) { } bool set_seccomp_filter() { - return _set_seccomp_filter(false); + return _set_seccomp_filter(FilterType::APP); } -bool set_global_seccomp_filter() { - return _set_seccomp_filter(true); +bool set_app_seccomp_filter() { + return _set_seccomp_filter(FilterType::APP); } -void get_seccomp_filter(const sock_filter*& filter, size_t& filter_size) { -#if defined __aarch64__ || defined __x86_64__ || defined __mips64__ - filter = primary_filter; - filter_size = primary_filter_size; -#else - filter = secondary_filter; - filter_size = secondary_filter_size; -#endif +bool set_system_seccomp_filter() { + return _set_seccomp_filter(FilterType::SYSTEM); +} + +bool set_global_seccomp_filter() { + return _set_seccomp_filter(FilterType::GLOBAL); } diff --git a/libc/seccomp/x86_64_policy.cpp b/libc/seccomp/x86_64_app_policy.cpp index 025e24f944..171b95902a 100644 --- a/libc/seccomp/x86_64_policy.cpp +++ b/libc/seccomp/x86_64_app_policy.cpp @@ -4,7 +4,7 @@ #include <errno.h> #include "seccomp_bpfs.h" -const sock_filter x86_64_filter[] = { +const sock_filter x86_64_app_filter[] = { BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 88), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 175, 43, 0), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 21, 0), @@ -96,4 +96,4 @@ BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 329, 1, 0), //mlock2|copy_file_range|preadv2|pwr BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; -const size_t x86_64_filter_size = sizeof(x86_64_filter) / sizeof(struct sock_filter); +const size_t x86_64_app_filter_size = sizeof(x86_64_app_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/x86_64_system_policy.cpp b/libc/seccomp/x86_64_system_policy.cpp new file mode 100644 index 0000000000..f2b2601cfd --- /dev/null +++ b/libc/seccomp/x86_64_system_policy.cpp @@ -0,0 +1,99 @@ +// Autogenerated file - edit at your peril!! + +#include <linux/filter.h> +#include <errno.h> + +#include "seccomp_bpfs.h" +const sock_filter x86_64_system_filter[] = { +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 88), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 175, 43, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 79, 21, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 35, 11, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 5, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 3, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 2, 81, 80), //read|write +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 4, 80, 79), //close +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 6, 79, 78), //fstat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 32, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 21, 76, 75), //lseek|mmap|mprotect|munmap|brk|rt_sigaction|rt_sigprocmask|rt_sigreturn|ioctl|pread64|pwrite64|readv|writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 29, 75, 74), //sched_yield|mremap|msync|mincore|madvise +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 74, 73), //dup +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 38, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 37, 70, 69), //nanosleep|getitimer +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 43, 69, 68), //setitimer|getpid|sendfile|socket|connect +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 68, 67), //sendto|recvfrom|sendmsg|recvmsg|shutdown|bind|listen|getsockname|getpeername|socketpair|setsockopt|getsockopt|clone +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 72, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 64, 66, 65), //vfork|execve|exit|wait4|kill|uname +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 78, 65, 64), //fcntl|flock|fsync|fdatasync|truncate|ftruncate +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 11, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 91, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 82, 60, 59), //getcwd|chdir|fchdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 92, 59, 58), //fchmod +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 58, 57), //fchown +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 135, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 112, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 111, 55, 54), //umask|gettimeofday|getrlimit|getrusage|sysinfo|times|ptrace|getuid|syslog|getgid|setuid|setgid|geteuid|getegid|setpgid|getppid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 132, 54, 53), //setsid|setreuid|setregid|getgroups|setgroups|setresuid|getresuid|setresgid|getresgid|getpgid|setfsuid|setfsgid|getsid|capget|capset|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|sigaltstack +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 53, 52), //personality +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 157, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 155, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 140, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 139, 49, 48), //statfs|fstatfs +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 153, 48, 47), //getpriority|setpriority|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|mlock|munlock|mlockall|munlockall +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 156, 47, 46), //pivot_root +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 167, 45, 44), //prctl|arch_prctl|adjtimex|setrlimit|chroot|sync|acct|settimeofday|mount|umount2 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 44, 43), //reboot|sethostname|setdomainname +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 257, 21, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 221, 11, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 202, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 186, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 179, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 177, 38, 37), //init_module|delete_module +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 180, 37, 36), //quotactl +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 201, 36, 35), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 217, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 206, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 205, 33, 32), //futex|sched_setaffinity|sched_getaffinity +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 211, 32, 31), //io_setup|io_destroy|io_getevents|io_submit|io_cancel +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 220, 31, 30), //getdents64|set_tid_address|restart_syscall +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 251, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 247, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 233, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 232, 27, 26), //fadvise64|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|exit_group +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 235, 26, 25), //epoll_ctl|tgkill +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 248, 25, 24), //waitid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 23, 22), //ioprio_set|ioprio_get +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 256, 22, 21), //inotify_add_watch|inotify_rm_watch +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 302, 11, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 280, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 275, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 262, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 261, 17, 16), //openat|mkdirat|mknodat|fchownat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 16, 15), //newfstatat|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 279, 15, 14), //splice|tee|sync_file_range|vmsplice +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 283, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 282, 12, 11), //utimensat|epoll_pwait +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 11, 10), //timerfd_create +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 10, 9), //fallocate|timerfd_settime|timerfd_gettime|accept4|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open|recvmmsg +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 5, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 314, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 305, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 303, 6, 5), //prlimit64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 312, 5, 4), //clock_adjtime|syncfs|sendmmsg|setns|getcpu|process_vm_readv|process_vm_writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 320, 4, 3), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 325, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 323, 2, 1), //execveat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 329, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2 +BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), +}; + +const size_t x86_64_system_filter_size = sizeof(x86_64_system_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/x86_policy.cpp b/libc/seccomp/x86_app_policy.cpp index 494a42a2b0..2db23680d9 100644 --- a/libc/seccomp/x86_policy.cpp +++ b/libc/seccomp/x86_app_policy.cpp @@ -4,7 +4,7 @@ #include <errno.h> #include "seccomp_bpfs.h" -const sock_filter x86_filter[] = { +const sock_filter x86_app_filter[] = { BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 116), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 57, 0), BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 29, 0), @@ -124,4 +124,4 @@ BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 1, 0), //mlock2|copy_file_range|preadv2|pwr BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), }; -const size_t x86_filter_size = sizeof(x86_filter) / sizeof(struct sock_filter); +const size_t x86_app_filter_size = sizeof(x86_app_filter) / sizeof(struct sock_filter); diff --git a/libc/seccomp/x86_system_policy.cpp b/libc/seccomp/x86_system_policy.cpp new file mode 100644 index 0000000000..b45e609b68 --- /dev/null +++ b/libc/seccomp/x86_system_policy.cpp @@ -0,0 +1,127 @@ +// Autogenerated file - edit at your peril!! + +#include <linux/filter.h> +#include <errno.h> + +#include "seccomp_bpfs.h" +const sock_filter x86_system_filter[] = { +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 0, 0, 116), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 131, 57, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 66, 29, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 41, 15, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 24, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 10, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 8, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 7, 109, 108), //restart_syscall|exit|fork|read|write|open|close +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 9, 108, 107), //creat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 19, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 13, 106, 105), //unlink|execve|chdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 22, 105, 104), //lseek|getpid|mount +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 33, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 26, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 25, 102, 101), //getuid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 27, 101, 100), //ptrace +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 36, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 34, 99, 98), //access +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 40, 98, 97), //sync|kill|rename|mkdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 57, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 51, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 45, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 44, 94, 93), //dup|pipe|times +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 46, 93, 92), //brk +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 54, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 53, 91, 90), //acct|umount2 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 56, 90, 89), //ioctl|fcntl +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 63, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 60, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 58, 87, 86), //setpgid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 62, 86, 85), //umask|chroot +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 65, 85, 84), //dup2|getppid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 96, 13, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 88, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 77, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 74, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 68, 80, 79), //setsid|sigaction +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 76, 79, 78), //sethostname|setrlimit +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 85, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 80, 77, 76), //getrusage|gettimeofday|settimeofday +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 86, 76, 75), //readlink +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 94, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 90, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 89, 73, 72), //reboot +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 93, 72, 71), //mmap|munmap|truncate +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 95, 71, 70), //fchmod +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 118, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 114, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 102, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 98, 67, 66), //getpriority|setpriority +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 106, 66, 65), //socketcall|syslog|setitimer|getitimer +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 116, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 115, 64, 63), //wait4 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 117, 63, 62), //sysinfo +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 128, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 124, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 123, 60, 59), //fsync|sigreturn|clone|setdomainname|uname +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 126, 59, 58), //adjtimex|mprotect +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 130, 58, 57), //init_module|delete_module +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 272, 29, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 199, 15, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 168, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 138, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 136, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 134, 52, 51), //quotactl|getpgid|fchdir +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 137, 51, 50), //personality +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 150, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 149, 49, 48), //setfsuid|setfsgid|_llseek|getdents|_newselect|flock|msync|readv|writev|getsid|fdatasync +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 164, 48, 47), //mlock|munlock|mlockall|munlockall|sched_setparam|sched_getparam|sched_setscheduler|sched_getscheduler|sched_yield|sched_get_priority_max|sched_get_priority_min|sched_rr_get_interval|nanosleep|mremap +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 183, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 172, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 169, 45, 44), //poll +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 182, 44, 43), //prctl|rt_sigreturn|rt_sigaction|rt_sigprocmask|rt_sigpending|rt_sigtimedwait|rt_sigqueueinfo|rt_sigsuspend|pread64|pwrite64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 190, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 188, 42, 41), //getcwd|capget|capset|sigaltstack|sendfile +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 198, 41, 40), //vfork|ugetrlimit|mmap2|truncate64|ftruncate64|stat64|lstat64|fstat64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 245, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 218, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 213, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 212, 37, 36), //getuid32|getgid32|geteuid32|getegid32|setreuid32|setregid32|getgroups32|setgroups32|fchown32|setresuid32|getresuid32|setresgid32|getresgid32 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 215, 36, 35), //setuid32|setgid32 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 224, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 222, 34, 33), //mincore|madvise|getdents64|fcntl64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 244, 33, 32), //gettid|readahead|setxattr|lsetxattr|fsetxattr|getxattr|lgetxattr|fgetxattr|listxattr|llistxattr|flistxattr|removexattr|lremovexattr|fremovexattr|tkill|sendfile64|futex|sched_setaffinity|sched_getaffinity|set_thread_area +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 254, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 252, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 250, 30, 29), //io_setup|io_destroy|io_getevents|io_submit|io_cancel +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 253, 29, 28), //exit_group +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 271, 28, 27), //epoll_create|epoll_ctl|epoll_wait|remap_file_pages|set_tid_address|timer_create|timer_settime|timer_gettime|timer_getoverrun|timer_delete|clock_settime|clock_gettime|clock_getres|clock_nanosleep|statfs64|fstatfs64|tgkill +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 322, 13, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 300, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 291, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 284, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 273, 23, 22), //fadvise64_64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 285, 22, 21), //waitid +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 295, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 294, 20, 19), //inotify_init|inotify_add_watch|inotify_rm_watch +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 299, 19, 18), //openat|mkdirat|mknodat|fchownat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 318, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 313, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 311, 16, 15), //fstatat64|unlinkat|renameat|linkat|symlinkat|readlinkat|fchmodat|faccessat|pselect6|ppoll|unshare +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 317, 15, 14), //splice|sync_file_range|tee|vmsplice +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 321, 14, 13), //getcpu|epoll_pwait|utimensat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 351, 7, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 343, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 340, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 337, 10, 9), //timerfd_create|eventfd|fallocate|timerfd_settime|timerfd_gettime|signalfd4|eventfd2|epoll_create1|dup3|pipe2|inotify_init1|preadv|pwritev|rt_tgsigqueueinfo|perf_event_open +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 341, 9, 8), //prlimit64 +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 346, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 345, 7, 6), //clock_adjtime|syncfs +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 349, 6, 5), //setns|process_vm_readv|process_vm_writev +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 376, 3, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 358, 1, 0), +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 357, 3, 2), //sched_setattr|sched_getattr|renameat2|seccomp|getrandom|memfd_create +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 359, 2, 1), //execveat +BPF_JUMP(BPF_JMP|BPF_JGE|BPF_K, 380, 1, 0), //mlock2|copy_file_range|preadv2|pwritev2 +BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), +}; + +const size_t x86_system_filter_size = sizeof(x86_system_filter) / sizeof(struct sock_filter); diff --git a/libc/tools/genseccomp.py b/libc/tools/genseccomp.py index f3a232e6e9..dad911331f 100755 --- a/libc/tools/genseccomp.py +++ b/libc/tools/genseccomp.py @@ -26,47 +26,18 @@ class SyscallRange(object): self.names.append(name) -def get_names(syscall_files, architecture, global_policy): - syscall_lists = [] - for syscall_file in syscall_files: - parser = SysCallsTxtParser() - parser.parse_open_file(syscall_file) - syscall_lists.append(parser.syscalls) - - bionic, whitelist, blacklist = syscall_lists[0], syscall_lists[1], syscall_lists[2] - if global_policy: - global_whitelist = syscall_lists[-1] - else: - global_whitelist = [] - - for x in blacklist: - if not x in bionic: - raise RuntimeError("Blacklist item not in bionic - aborting " + str(x)) - - if x in whitelist: - raise RuntimeError("Blacklist item in whitelist - aborting " + str(x)) - - bionic_minus_blacklist = [x for x in bionic if x not in blacklist] - syscalls = bionic_minus_blacklist + whitelist + global_whitelist - - # Select only elements matching required architecture - syscalls = [x for x in syscalls if architecture in x and x[architecture]] - - # We only want the name - names = [x["name"] for x in syscalls] - - # Check for duplicates - dups = [name for name, count in collections.Counter(names).items() if count > 1] +def load_syscall_names_from_file(file_path, architecture): + parser = SysCallsTxtParser() + parser.parse_open_file(open(file_path)) + return set([x["name"] for x in parser.syscalls if x.get(architecture)]) - # x86 has duplicate socketcall entries, so hard code for this - if architecture == "x86": - dups.remove("socketcall") - if len(dups) > 0: - raise RuntimeError("Duplicate entries found - aborting " + str(dups)) +def merge_names(base_names, whitelist_names, blacklist_names): + if bool(blacklist_names - base_names): + raise RuntimeError("Blacklist item not in bionic - aborting " + str( + blacklist_name - base_names)) - # Remove remaining duplicates - return list(set(names)) + return (base_names - blacklist_names) | whitelist_names def convert_names_to_NRs(names, header_dir, extra_switches): @@ -175,8 +146,11 @@ def convert_ranges_to_bpf(ranges): return bpf -def convert_bpf_to_output(bpf, architecture, global_policy): - suffix = "global_" if global_policy else "" +def convert_bpf_to_output(bpf, architecture, name_modifier): + if name_modifier: + name_modifier = name_modifier + "_" + else: + name_modifier = "" header = textwrap.dedent("""\ // Autogenerated file - edit at your peril!! @@ -185,29 +159,51 @@ def convert_bpf_to_output(bpf, architecture, global_policy): #include "seccomp_bpfs.h" const sock_filter {architecture}_{suffix}filter[] = {{ - """).format(architecture=architecture,suffix=suffix) + """).format(architecture=architecture,suffix=name_modifier) footer = textwrap.dedent("""\ }}; const size_t {architecture}_{suffix}filter_size = sizeof({architecture}_{suffix}filter) / sizeof(struct sock_filter); - """).format(architecture=architecture,suffix=suffix) + """).format(architecture=architecture,suffix=name_modifier) return header + "\n".join(bpf) + footer -def construct_bpf(syscall_files, architecture, header_dir, extra_switches, - global_policy): - names = get_names(syscall_files, architecture, global_policy) +def construct_bpf(names, architecture, header_dir, extra_switches, + name_modifier): syscalls = convert_names_to_NRs(names, header_dir, extra_switches) ranges = convert_NRs_to_ranges(syscalls) bpf = convert_ranges_to_bpf(ranges) - return convert_bpf_to_output(bpf, architecture, global_policy) - - -ANDROID_SYSCALL_FILES = ["SYSCALLS.TXT", - "SECCOMP_WHITELIST.TXT", - "SECCOMP_BLACKLIST.TXT"] + return convert_bpf_to_output(bpf, architecture, name_modifier) + + +# final syscalls = base - blacklists + whitelists +ANDROID_SYSTEM_SYSCALL_FILES = { + "base": "SYSCALLS.TXT", + "whitelists": [ + "SECCOMP_WHITELIST_COMMON.TXT", + "SECCOMP_WHITELIST_SYSTEM.TXT"], + "blacklists": ["SECCOMP_BLACKLIST_COMMON.TXT"] +} + +ANDROID_APP_SYSCALL_FILES = { + "base": "SYSCALLS.TXT", + "whitelists": [ + "SECCOMP_WHITELIST_COMMON.TXT", + "SECCOMP_WHITELIST_APP.TXT"], + "blacklists": ["SECCOMP_BLACKLIST_COMMON.TXT"] +} + +ANDROID_GLOBAL_SYSCALL_FILES = { + "base": "SYSCALLS.TXT", + "whitelists": [ + "SECCOMP_WHITELIST_COMMON.TXT", + "SECCOMP_WHITELIST_SYSTEM.TXT", + "SECCOMP_WHITELIST_APP.TXT", + "SECCOMP_WHITELIST_GLOBAL.TXT"], + "blacklists": ["SECCOMP_BLACKLIST_COMMON.TXT"] +} POLICY_CONFIGS = [("arm", "kernel/uapi/asm-arm", []), @@ -223,18 +219,23 @@ def set_dir(): os.chdir(os.path.join(os.environ["ANDROID_BUILD_TOP"], "bionic/libc")) -def gen_policy(global_policy): - if global_policy: - ANDROID_SYSCALL_FILES.append("SECCOMP_WHITELIST_GLOBAL.TXT") - +def gen_policy(syscall_files, name_modifier): for arch, header_path, switches in POLICY_CONFIGS: - files = [open(filename) for filename in ANDROID_SYSCALL_FILES] - output = construct_bpf(files, arch, header_path, switches, global_policy) + base_names = load_syscall_names_from_file(syscall_files["base"], arch) + whitelist_names = set() + for f in syscall_files["whitelists"]: + whitelist_names |= load_syscall_names_from_file(f, arch) + blacklist_names = set() + for f in syscall_files["blacklists"]: + blacklist_names |= load_syscall_names_from_file(f, arch) + + names = merge_names(base_names, whitelist_names, blacklist_names) + output = construct_bpf(names, arch, header_path, switches, name_modifier) # And output policy existing = "" - global_string = "_global" if global_policy else "" - output_path = "seccomp/{}{}_policy.cpp".format(arch, global_string) + filename_modifier = "_" + name_modifier if name_modifier else "" + output_path = "seccomp/{}{}_policy.cpp".format(arch, filename_modifier) if os.path.isfile(output_path): existing = open(output_path).read() if output == existing: @@ -247,8 +248,10 @@ def gen_policy(global_policy): def main(): set_dir() - gen_policy(False) - gen_policy(True) + gen_policy(ANDROID_SYSTEM_SYSCALL_FILES, 'system') + gen_policy(ANDROID_APP_SYSCALL_FILES, 'app') + gen_policy(ANDROID_GLOBAL_SYSCALL_FILES, 'global') + if __name__ == "__main__": main() diff --git a/tests/complex_test.cpp b/tests/complex_test.cpp index 85b20de401..2aaa192315 100644 --- a/tests/complex_test.cpp +++ b/tests/complex_test.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ -#include <gtest/gtest.h> - #if defined(__BIONIC_LP32_USE_LONG_DOUBLE) #define COMPLEX_TEST complex_h_force_long_double #else @@ -43,26 +41,27 @@ #include <math.h> // For M_PI_2/M_PI_2l. -#if 0 -// Note that gtest doesn't support complex numbers, so the output from -// assertion failures is misleading/useless (at best you'll only see the real -// part). -// TODO: find out why gtest doesn't use these; until then they're only useful -// for manual printf^Woperator<< debugging. +// Prettify gtest Complex printing. #include <iostream> -std::ostream& operator<<(std::ostream& os, const double _Complex c) { - os << "(" << creal(c) << "," << cimag(c) << "i)"; - return os; +namespace testing { +namespace internal { +inline void PrintTo(const double _Complex& c, std::ostream* os) { + *os << "(" << creal(c) << "," << cimag(c) << "i)"; } -std::ostream& operator<<(std::ostream& os, const float _Complex c) { - os << "(" << crealf(c) << "," << cimagf(c) << "i)"; - return os; +inline void PrintTo(const float _Complex& c, std::ostream* os) { + *os << "(" << crealf(c) << "," << cimagf(c) << "i)"; } -std::ostream& operator<<(std::ostream& os, const long double _Complex c) { - os << "(" << creall(c) << "," << cimagl(c) << "i)"; - return os; +inline void PrintTo(const long double _Complex& c, std::ostream* os) { + *os << "(" << creall(c) << "," << cimagl(c) << "i)"; } -#endif +} +} + +// Macro 'I' defined in complex.h conflicts with gtest.h. +#pragma push_macro("I") +#undef I +#include <gtest/gtest.h> +#pragma pop_macro("I") TEST(COMPLEX_TEST, cabs) { ASSERT_EQ(0.0, cabs(0)); |
