aboutsummaryrefslogtreecommitdiffstats
path: root/lib/chaseccomp/gen_syscalls
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-10-31 17:44:03 +0100
committerbptato <nincsnevem662@gmail.com>2024-10-31 18:38:16 +0100
commitd9ca197ed8056c021d4e37ec52aacc6039e24ab7 (patch)
tree782781c4bb85e65f112092f96c7ee91e447c7c97 /lib/chaseccomp/gen_syscalls
parentd9a74dbdeef846a98a464bfc102ce282b45e9606 (diff)
downloadchawan-d9ca197ed8056c021d4e37ec52aacc6039e24ab7.tar.gz
chaseccomp: fix compilation with newest dash, misc changes
* fix matching on unstripped whitespace: caught after upgrading to upstream dash & chaseccomp wouldn't compile * add defines to ensure that we computed the filter length correctly * inline cut_label * EPERM on sigaction, sigprocmask, gettid, and kill on tgkill (so a crash doesn't trigger sandbox violations) * move SIGSYS handler to C and add one for the network The last change removes the stack trace from SIGSYS, but gives us the syscall number which is probably more useful. (Indeed, we don't even have a stack trace in release builds.)
Diffstat (limited to 'lib/chaseccomp/gen_syscalls')
-rwxr-xr-xlib/chaseccomp/gen_syscalls36
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/chaseccomp/gen_syscalls b/lib/chaseccomp/gen_syscalls
index a4d7d5b5..401403d5 100755
--- a/lib/chaseccomp/gen_syscalls
+++ b/lib/chaseccomp/gen_syscalls
@@ -9,7 +9,7 @@ test "$1" || die "usage: gen_syscalls [file]"
find_label() {
printf '%s\n' "$labels" | while read -r line
- do case $line in
+ do case "$line" in
"$1 "*) printf '%d\n' "${line#* }"
break
;;
@@ -24,23 +24,19 @@ line_cut_next() {
if test "$line" = "$oline"; then line= ; fi
}
-cut_label() {
+put_cmp() {
+ line_cut_next
+ val=$next
line_cut_next
label=$(find_label "$next")
test "$label" || die "missing label $next"
label=$(($label - 1 - $ip))
-}
-
-put_cmp() {
- line_cut_next
- val=$next
- cut_label
- printf '\t%s(%s, %d),\n' "$inst" "$val" "$label"
+ printf '\t%s(%s, %d),\n' "$1" "$val" "$label"
}
put_load() {
line_cut_next
- printf '\t%s(%s),\n' "$inst" "$next"
+ printf '\tCHA_BPF_LOAD(%s),\n' "$next"
}
put_ret() {
@@ -52,13 +48,13 @@ put_ret() {
errno) val="SECCOMP_RET_ERRNO | ($line & SECCOMP_RET_DATA)" ;;
*) die "wrong retval $line" ;;
esac
- printf '\t%s(%s),\n' "$inst" "$val"
+ printf '\tCHA_BPF_RET(%s),\n' "$val"
}
ip=0
while read -r line
do line=${line%%#*}
- case $line in
+ case "$line" in
''|define' '*) ;;
': '*) line_cut_next
if test -n "$labels"
@@ -76,13 +72,15 @@ while read -r line
do line_cut_next
case $next in
:) continue ;;
- define) printf '#%s %s\n' "$next $line" ; continue ;;
- ret) inst=CHA_BPF_RET put_ret ;;
- ifeq) inst=CHA_BPF_JE put_cmp ;;
- ifne) inst=CHA_BPF_JNE put_cmp ;;
- ifle) inst=CHA_BPF_JLE put_cmp ;;
- load) inst=CHA_BPF_LOAD put_load ;;
- *) die "unexpected instruction $inst" ;;
+ define) printf '#%s %s\n' "$next" "$line" ; continue ;;
+ ret) put_ret ;;
+ ifeq) put_cmp CHA_BPF_JE;;
+ ifne) put_cmp CHA_BPF_JNE;;
+ ifle) put_cmp CHA_BPF_JLE;;
+ load) put_load;;
+ *) die "unexpected instruction $next" ;;
esac
ip=$(($ip + 1))
done < "$1"
+
+printf '#define EXPECTED_COUNT %d\n' "$ip"