diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-11-04 20:25:26 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-11-04 21:08:17 +0100 |
| commit | 8d22366c3bf67aea31ff746fef56e08944713a13 (patch) | |
| tree | 69627a6b25e167b57451fde097ad39e6136099a1 /lib/chaseccomp | |
| parent | 64308987e0ae245977a875ec0015dd1d051587bd (diff) | |
| download | chawan-8d22366c3bf67aea31ff746fef56e08944713a13.tar.gz | |
chaseccomp: lock down clone; fix mprotect on bionic
* add restrictions on clone for buffer filter
- hardcoded it for musl, glibc and bionic. hopefully they don't
change it too soon...
* remove define directive from gen_syscalls
- now the arch nr check is hardcoded in gen_defs. makes things a
bit less complex.
* fix borked mprotect filter on bionic
- this completely broke the browser.
Diffstat (limited to 'lib/chaseccomp')
| -rw-r--r-- | lib/chaseccomp/buffer.chasc | 21 | ||||
| -rw-r--r-- | lib/chaseccomp/chaseccomp.c | 2 | ||||
| -rw-r--r-- | lib/chaseccomp/common.chasc | 6 | ||||
| -rwxr-xr-x | lib/chaseccomp/gen_defs | 2 | ||||
| -rwxr-xr-x | lib/chaseccomp/gen_syscalls | 2 |
5 files changed, 23 insertions, 10 deletions
diff --git a/lib/chaseccomp/buffer.chasc b/lib/chaseccomp/buffer.chasc index 0d14883f..14abddd4 100644 --- a/lib/chaseccomp/buffer.chasc +++ b/lib/chaseccomp/buffer.chasc @@ -20,9 +20,7 @@ ifeqdef SYS_accept4 allow # for when accept is implemented as accept4 ifeqdef SYS_bind allow # for outgoing requests to loader ifeqdef SYS_clock_gettime allow # used by QuickJS in atomics and cpuTime() ifeqdef SYS_clock_gettime64 allow # 64-bit clock_gettime on 32-bit platforms -ifeqdef SYS_clone allow # for when fork is implemented as clone ifeqdef SYS_connect allow # for outgoing requests to loader -ifeqdef SYS_fork allow # for when fork is really fork ifeqdef SYS_getpid allow # for determining current PID after we fork ifeqdef SYS_gettimeofday allow # used by QuickJS in Date.now() ifeqdef SYS_pipe allow # for pipes to child process @@ -31,6 +29,25 @@ ifeqdef SYS_rt_sigreturn allow # newer kernels have this instead of sigreturn ifeqdef SYS_set_robust_list allow # glibc seems to need it for whatever reason ifeqdef SYS_sigreturn allow # called by signal trampoline +ifeqdef SYS_fork allow +# It would be great if this were enough to allow fork and only fork, +# but some Linuxen do not have fork, so most libcs prefer clone. +ifne SYS_clone not_clone +load args[0] # flags +# musl only passes SIGCHLD. +# glibc and bionic also pass settid, cleartid. +ifeq SIGCHLD clone_musl +ifne CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD deny +: clone_musl +load args[1] # child_stack +ifne 0 deny +load args[2] # parent_tid +ifne 0 deny +# 3 is child_tid. Let through whatever we got. +load args[4] # tls +ifeq 0 allow +: not_clone + : deny ret trap : kill diff --git a/lib/chaseccomp/chaseccomp.c b/lib/chaseccomp/chaseccomp.c index b150474d..949d9ee8 100644 --- a/lib/chaseccomp/chaseccomp.c +++ b/lib/chaseccomp/chaseccomp.c @@ -3,6 +3,8 @@ * also bpf(4), except I can't find it on Linux... check a BSD. */ +#define _GNU_SOURCE +#include <sched.h> #include <stdlib.h> #include <stddef.h> #include <sys/prctl.h> diff --git a/lib/chaseccomp/common.chasc b/lib/chaseccomp/common.chasc index 15c40053..6c2bc24a 100644 --- a/lib/chaseccomp/common.chasc +++ b/lib/chaseccomp/common.chasc @@ -1,6 +1,3 @@ -load arch -ifne CHASECCOMP_AUDIT_ARCH_NR deny - # load syscall nr load nr @@ -73,9 +70,8 @@ load nr # bionic also calls mprotect(2) with PROT_READ and PROT_WRITE flags. # Crucially, we don't want to allow PROT_EXEC. ifne SYS_mprotect not_mprotect -define CHA_PROT_READ_OR_PROT_WRITE (PROT_READ | PROT_WRITE) load args[2] -ifne CHA_PROT_READ_OR_PROT_WRITE allow +ifle PROT_READ|PROT_WRITE allow load nr : not_mprotect diff --git a/lib/chaseccomp/gen_defs b/lib/chaseccomp/gen_defs index 80cdbb2f..41c3549b 100755 --- a/lib/chaseccomp/gen_defs +++ b/lib/chaseccomp/gen_defs @@ -13,7 +13,7 @@ cat <<EOF static void determine_audit_arch(int sig, siginfo_t *info, void *ucontext) { - printf("define CHASECCOMP_AUDIT_ARCH_NR %u\n", info->si_arch); + printf("load arch\nifne %u deny\n", info->si_arch); } #define DIE(s) do { perror(s); exit(1); } while (0) diff --git a/lib/chaseccomp/gen_syscalls b/lib/chaseccomp/gen_syscalls index 18c46ac8..658fde80 100755 --- a/lib/chaseccomp/gen_syscalls +++ b/lib/chaseccomp/gen_syscalls @@ -55,7 +55,6 @@ ip=0 while read -r line do line=${line%%#*} case $line in - ''|'define '*) ;; ': '*) line_cut_next if test -n "$labels" then labels="$labels @@ -72,7 +71,6 @@ while read -r line do line_cut_next case $next in :) continue ;; - define) printf '#%s %s\n' "$next" "$line" ; continue ;; ret) put_ret ;; ifeq) put_cmp CHA_BPF_JE;; ifne) put_cmp CHA_BPF_JNE;; |