diff --git a/.crumb b/.crumb index f3e51fe46..784b3d105 100644 --- a/.crumb +++ b/.crumb @@ -72,7 +72,7 @@ }, { "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "last_commit": "d94a503f7", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, @@ -84,26 +84,26 @@ }, { "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "last_commit": "dcccc0211", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "last_commit": "a50c3bd41", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc", - "compiled_at": "2026-10-30T12:31:50Z", + "compiled_at": "2026-10-30T16:28:57Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", + "digest": "sha256:608e77b8e62875142f041ad553bb98998a7646f97a229b96e964a941e61a7c1f", "evidence_files": 12622, "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "files": 17857, + "generated_at_commit": "11e4d7fcc3f8ee40eaf17847cdc868f1b768ffba", + "source_tree": "sha256:bb21970d83b8bffe7561ccc9a5d3e9a907ae16778a63f8868013c6f3f4cc13ce" }, "owner_lane": "", "provenance": { diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index dda6d20b5..8661d309d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -35,6 +35,7 @@ Every model below did real work. A model is listed only for work it did. The orc | Claude Opus 5.5 | Omega 1.0 roadmap: source-pinned readiness audit of the seeded compiler, IR, WebAssembly and bridge paths, milestone acceptance gates, tracking issues #790-#800, OM-2 contract files brought to main byte-identical, and stale status text corrected | | Claude Opus 5.5 | Function-mode constants in the seeded compiler (`fnstore`): consts accepted without `fn main`, globals/texts/host words still error 9, gate16 byte-identity fixtures and old-compiler/mutant negative controls | | Codex (GPT-6.1 Sol) | Repaired qty float-domain classification and checked ingress, diagnostic categories and query/output streaming; permanent adversarial regression fixtures for the #909/#911 audit | +| Claude Opus 5.5 | Effect-derived capability manifest (`seed/effects`, M1): host-word manifest, ELF syscall resolution that fails closed, seccomp cBPF output, probe-parity/strace/bwrap gate with negative controls and tool mutants | This table starts with the numeric work on this branch. Earlier work in this repository is not yet attributed here; add rows only for work that can be traced to a model. diff --git a/seed/effects/.crumb b/seed/effects/.crumb new file mode 100644 index 000000000..6647165f6 --- /dev/null +++ b/seed/effects/.crumb @@ -0,0 +1,20 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-10-30T02:48:27Z", + "compiler": "crumb-compile/1", + "digest": "sha256:4467ea7f6119a2c4b304abefe1409486f6fbf2db8abc4bbc7d28b1f868b16935", + "evidence_files": 0, + "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "files": 8, + "generated_at_commit": "7c820ac33706cd50741c62476a3fc57739e781ce", + "source_tree": "sha256:e430ad3ff4994aed63258852b188b8b7de66e195ce03260689d68de4bf0eb3dc" + } + }, + "layer": "seed", + "name": "effects", + "purpose": "Effect-derived capability manifest in seeded Omega: host-word manifest, ELF syscall check, seccomp cBPF, with probe-parity, strace and bwrap oracle gate", + "schema_version": "1.0.0" +} diff --git a/seed/effects/README.md b/seed/effects/README.md new file mode 100644 index 000000000..7c7b10ee1 --- /dev/null +++ b/seed/effects/README.md @@ -0,0 +1,59 @@ +# effects: capability manifest derived from Omega source + +A seeded-Omega program reaches the kernel only through the closed keyword set in +[OMEGESE section 10](../../docs/one_layer/OMEGESE.md) and +[MAPPING.md](../host/MAPPING.md): there is no raw syscall and no address-to-pointer +conversion. The host words that appear in a unit are therefore a complete, finite list +of the OS effects it can have. This tool turns that list into a manifest, checks it +against the compiled binary, and emits a seccomp filter that enforces it. + +``` +seed/out/omc < seed/effects/effects.om > effects && chmod +x effects +effects src [allow=C,..] < unit.om host words, classes, Linux syscalls; policy check +effects elf < binary syscalls the omc ELF can issue (fail closed) +effects verify SRC BIN [allow=C,..] ELF syscalls must lie within the source manifest +effects bpf [launch] < unit.om seccomp cBPF allow-list for bwrap --seccomp +effects table word, class and syscalls, one per line +``` + +Classes: `io` (read, write), `fd`, `path`, `net`, `proc`, `ident`, `time`, `env`, +`random`, `device`. `exit`/traps (syscall 93) are always allowed. + +Exit status: 0 pass, 1 refused or undeclared syscall, 2 usage, 3 invalid or +unresolvable input, 4 read error. + +`elf` treats every SVC in an executable load segment as reachable. Each SVC must be +immediately preceded by `MOVZ X8,#n`, no direct branch may land on it, and the text +may contain no `BR`/`BLR`. Anything else is `ELF UNRESOLVED` (exit 3). W+X segments +are refused. These rules hold for every program the pinned compiler emits today. A +binary from another producer will usually fail closed. + +## Qualification + +`sh seed/effects/check.sh` (pinned omc; strace, bwrap, od and dd as oracles): + +- closure: every keyword with a host code in `seed/omc/genkw.awk` is in the table; + `omc.om` has exactly 5 SVC emit sites (a new site means the table needs review) +- probe parity: one compiled probe per word; the ELF syscalls equal the table row +- self manifest, fixtures, policy refusals with word, class and line +- every program-mode unit in `seed/host/tests` and `seed/rung4/tests`, and omc itself: + binary syscalls lie within the source manifest +- strace: syscalls observed at run time lie within the ELF set +- seccomp: each fixture runs under its own filter; a binary run under a narrower + filter is killed (exit 159, SIGSYS) +- fail-closed controls: SVC without `MOVZ X8`, `MOVZ X9`, branch into an SVC, `BR`, + W+X segment, non-ELF input +- tool mutants (dropped row, wrong syscall number, weakened MOVZ check) are killed + +## Limits + +- Classes and the filter work at syscall granularity. `fopen` is `path` whether it + reads or writes; argument-level policy (literal open flags, socket families) is + future work. +- `bpf launch` adds `execve` (221) so that bwrap can start the program. The program + can therefore call execve itself under that filter. An in-program install would close + this gap but needs a `prctl`/`seccomp` host word, which is a compiler change. +- The filter restricts syscalls only. The check runs bwrap with `--dev-bind / /`, so + filesystem and namespace isolation are separate. +- The table is pinned to the compiler in `om/units.sh`. A compiler that changes how + host words lower is caught by closure and probe parity, not silently accepted. diff --git a/seed/effects/cases/clock.om b/seed/effects/cases/clock.om new file mode 100644 index 000000000..2edfc1d20 --- /dev/null +++ b/seed/effects/cases/clock.om @@ -0,0 +1,13 @@ +note clock: time, identity and randomness; no file, network or process words. +text ok "clock\n" +fn main to int +t = monons +p = getpid +b = new uchar 8 0 +r = random b 0 8 0 +if or le t 0 le p 0 +ret 1 +end +w = write 1 ok 0 len ok +ret 0 +end diff --git a/seed/effects/cases/files.om b/seed/effects/cases/files.om new file mode 100644 index 000000000..fa63d7078 --- /dev/null +++ b/seed/effects/cases/files.om @@ -0,0 +1,17 @@ +note files: create, stat and remove one file in the current directory. +text nm "effects.tmp" +fn main to int +fd = int fopen nm 0 len nm 578 384 +if lt fd 0 +ret 1 +end +w = write fd nm 0 len nm +st = new uchar 128 0 +r = fstat fd st 0 128 +c = fclose fd +u = unlink nm 0 len nm +if or ne r 0 ne u 0 +ret 2 +end +ret 0 +end diff --git a/seed/effects/cases/net.om b/seed/effects/cases/net.om new file mode 100644 index 000000000..a9d97468d --- /dev/null +++ b/seed/effects/cases/net.om @@ -0,0 +1,9 @@ +note net: opens and closes one TCP socket; a policy without net must refuse it. +fn main to int +s = socknew 2 1 0 +if lt s 0 +ret 1 +end +c = fclose int s +ret 0 +end diff --git a/seed/effects/cases/plain.om b/seed/effects/cases/plain.om new file mode 100644 index 000000000..9119b5b30 --- /dev/null +++ b/seed/effects/cases/plain.om @@ -0,0 +1,6 @@ +note plain: stdout only; manifest must be class io, syscalls 64 and exit 93. +text hi "plain\n" +fn main to int +r = write 1 hi 0 len hi +ret 0 +end diff --git a/seed/effects/cases/probes.txt b/seed/effects/cases/probes.txt new file mode 100644 index 000000000..c0ea88143 --- /dev/null +++ b/seed/effects/cases/probes.txt @@ -0,0 +1,85 @@ +note probes.txt: word|expression. check.sh wraps each expression in a minimal program +note (arrays a 8, b 64, c 128 bytes) and compares the compiled syscalls with effects table. +read|read 0 b 0 8 +write|write 1 a 0 1 +fopen|fopen a 0 1 0 0 +fclose|fclose 3 +fsync|fsync 3 +fdsync|fdsync 3 +memfd|memfd a 0 1 0 +fchmod|fchmod 3 0 +chmod|chmod a 0 1 0 +chown|chown a 0 1 0 0 +faccess|faccess a 0 1 0 +getuid|getuid +geteuid|geteuid +getgid|getgid +getegid|getegid +fchdir|fchdir 3 +getppid|getppid +setsid|setsid +getpgid|getpgid 0 +getsid|getsid 0 +syncfs|syncfs 3 +shutdown|shutdown 3 0 +flock|flock 3 1 +setpgid|setpgid 0 0 +umask|umask 0 +fseek|fseek 3 long 0 0 +ftrunc|ftrunc 3 long 0 +truncate|truncate a 0 1 long 0 +unlink|unlink a 0 1 +makedir|makedir a 0 1 0 +rmdir|rmdir a 0 1 +cwd|cwd a 0 64 +chdir|chdir a 0 1 +readlnk|readlnk a 0 1 b 0 64 +getdnts|getdnts 3 b 0 64 +fstat|fstat 3 c 0 128 +stat|stat a 0 1 c 0 128 +lstat|lstat a 0 1 c 0 128 +renames|renames a 0 1 0 +link|link a 0 1 +symlnk|symlnk a 0 1 +monons|monons +realns|realns +sleepns|sleepns long 0 +socknew|socknew 1 1 0 +bind|bind 3 a 0 1 +connect|connect 3 a 0 1 +listen|listen 3 1 +accept|accept 3 0 +sockname|sockname 3 b 0 64 +sockopt|sockopt 3 1 2 a 0 4 +recv|recv 3 b 0 64 0 +send|send 3 a 0 1 0 +waitio|waitio 3 1 long 0 +peercred|peercred 3 b 0 64 +pollfds|pollfds b 0 8 long 0 +sendmsg|sendmsg 3 a 0 1 0 +fork|fork +getpid|getpid +killpid|killpid 0 0 +waitpid|waitpid 0 b 0 8 0 +pipefds|pipefds b 0 8 0 +dupfd|dupfd 3 4 0 +execprog|execprog a 0 1 +argcnt|argcnt +argread|argread 0 b 0 64 +envcnt|envcnt +envread|envread 0 b 0 64 +random|random b 0 8 0 +pread|pread 3 b 0 8 long 0 +pwrite|pwrite 3 a 0 1 long 0 +devctl|devctl 3 21531 b 0 4 +mapnew|mapnew 3 0 4096 1 1 +mapdrop|mapdrop long 1 +mapread|mapread long 1 0 b 0 8 +mapwrite|mapwrite long 1 0 a 0 1 +mapaddr|long mapaddr long 1 +mapget|long mapget long 1 0 8 +mapset|mapset long 1 0 8 0 +maphold|maphold 65536 4096 +mapbind|mapbind long 1 3 0 1 +devcall|devcall neg int 1 uint 3223340587 c 0 32 b 0 0 +uvmctl|uvmctl neg int 1 uint 75 c 0 8 diff --git a/seed/effects/check.sh b/seed/effects/check.sh new file mode 100755 index 000000000..c4754006e --- /dev/null +++ b/seed/effects/check.sh @@ -0,0 +1,183 @@ +#!/bin/sh +# Qualification for seed/effects (effect-derived capability manifest). +# The tool is seeded Omega; this coordinator only compiles, runs and compares. +# strace, bwrap, od and dd are read-only oracles / launchers, not implementation. +# Exit 0 PASS, 1 FAIL, 3 NOT_RUN (wrong compiler or missing oracle). +set -u +cd "$(dirname "$0")/../.." +ROOT=$(pwd) +OMC=${OMC:-$ROOT/seed/out/omc} +PIN=$(sed -n 's/^OMC_PIN=//p' om/units.sh) +[ -x "$OMC" ] || { echo "NOT_RUN effects: no omc at $OMC"; exit 3; } +[ "$(sha256sum < "$OMC" | cut -c1-64)" = "$PIN" ] || { echo "NOT_RUN effects: omc is not the pinned compiler $PIN"; exit 3; } +for t in strace bwrap od dd awk; do + command -v $t > /dev/null || { echo "NOT_RUN effects: oracle $t missing"; exit 3; } +done +B=$ROOT/build/seed/effects +rm -rf "$B"; mkdir -p "$B/probe" "$B/corpus" "$B/run" +C=seed/effects/cases +E=$B/effects +fails=0; checks=0 +ok() { checks=$((checks + 1)); printf 'ok %s\n' "$*"; } +bad() { checks=$((checks + 1)); fails=$((fails + 1)); printf 'FAIL %s\n' "$*"; } +want() { # want NAME EXPECTED_EXIT ACTUAL_EXIT + if [ "$2" = "$3" ]; then ok "$1 exit=$3"; else bad "$1 exit=$3 expected=$2"; fi +} +build() { # build SRC OUT + "$OMC" < "$1" > "$2" 2> "$2.err" && chmod +x "$2" +} +sys_of() { # syscalls line of an elf report + sed -n 's/^ELF 1 .* syscalls=//p' +} + +build seed/effects/effects.om "$E" || { cat "$E.err"; echo "SEMANTIC EFFECTS FAIL build"; exit 1; } +echo "omc $PIN" +echo "effects sha256 $(sha256sum < "$E" | cut -c1-64)" + +# 1. Closure: every keyword with a host code (>= 100, except the non-host type/declaration +# keywords const and qty) is in the table, +# and the table holds nothing else besides read/write. +sed -n 16,18p seed/omc/genkw.awk | grep -oE '[a-z0-9]+:[0-9]+' \ + | awk -F: '$2 >= 100 && $1 != "const" && $1 != "qty" { print $1 }' | sort > "$B/kw.txt" +"$E" table | cut -d' ' -f1 | grep -v -x -e read -e write | sort > "$B/tab.txt" +if cmp -s "$B/kw.txt" "$B/tab.txt"; then ok "closure: $(wc -l < "$B/kw.txt") host keywords == table" +else bad "closure: host keywords differ from table"; diff "$B/kw.txt" "$B/tab.txt"; fi +# omc emits SVC at exactly these sites; a new site means the table must be re-reviewed. +n=$(grep -c '^emit 3556769793$' seed/omc/omc.om) +if [ "$n" = 5 ]; then ok "omc.om SVC emit sites = 5"; else bad "omc.om SVC emit sites = $n (expected 5): review table"; fi + +# 2. Probe parity: compile one program per table word with the pinned omc and read the +# syscalls back out of the ELF; they must equal the table row (93 = exit is always present). +probe() { # probe EXPR OUT + printf 'fn main to int\na = new uchar 8 65\nb = new uchar 64 0\nc = new uchar 128 0\nr = long %s\nret 0\nend\n' "$1" > "$2.om" + build "$2.om" "$2" +} +probe_parity() { # probe_parity TOOL -> prints mismatches, returns count + m=0 + "$1" table > "$B/probe/table.txt" + while read -r w cl s1 s2; do + expr=$(grep "^$w|" $C/probes.txt | head -1 | cut -d'|' -f2-) + [ -n "$expr" ] || { echo " no probe for $w"; m=$((m + 1)); continue; } + probe "$expr" "$B/probe/$w" || { echo " probe $w does not compile: $(cat "$B/probe/$w.err")"; m=$((m + 1)); continue; } + got=$("$E" elf < "$B/probe/$w" | sys_of | tr ',' '\n' | grep -v -x 93 | sort -n | tr '\n' ' ') + exp=$(printf '%s\n%s\n' "$s1" "$s2" | grep -v -x -- - | sort -n -u | tr '\n' ' ') + [ "$got" = "$exp" ] || { echo " $w table=[$exp] elf=[$got]"; m=$((m + 1)); } + done < "$B/probe/table.txt" + return $m +} +if probe_parity "$E"; then ok "probe parity: $(wc -l < "$B/probe/table.txt") words, table == pinned omc" +else bad "probe parity"; fi +printf 'fn main to int\nret 0\nend\n' > "$B/probe/base.om"; build "$B/probe/base.om" "$B/probe/base" +b=$("$E" elf < "$B/probe/base" | sys_of) +[ "$b" = 93 ] && ok "base program syscalls = 93" || bad "base program syscalls = $b" + +# 3. Self manifest: the tool reads stdin/files and writes stdout, nothing else. +"$E" src allow=io,fd,path,env < seed/effects/effects.om > "$B/self.txt"; want "self manifest allow=io,fd,path,env" 0 $? +grep -qx 'EFFECTS 1 words=6 classes=io,fd,path,env syscalls=56,57,63,64,93' "$B/self.txt" && ok "self manifest exact" || bad "self manifest: $(tail -1 "$B/self.txt")" +"$E" verify seed/effects/effects.om "$E" > "$B/selfv.txt"; want "self verify source vs binary" 0 $? + +# 4. Fixtures: manifest, policy, verify. +for f in plain clock files net; do build $C/$f.om "$B/$f" || bad "fixture $f does not compile"; done +"$E" src < $C/plain.om | grep -qx 'EFFECTS 1 words=1 classes=io syscalls=64,93' && ok "plain manifest" || bad "plain manifest" +"$E" src < $C/clock.om | grep -qx 'EFFECTS 1 words=4 classes=io,ident,time,random syscalls=64,93,113,172,278' && ok "clock manifest" || bad "clock manifest" +"$E" src allow=io,ident,time,random < $C/clock.om > /dev/null; want "clock allow=io,ident,time,random" 0 $? +"$E" src allow=io,fd,path < $C/net.om > "$B/net.txt"; want "NEGATIVE net under allow=io,fd,path" 1 $? +grep -qx 'EFFECTS REFUSED word=socknew class=net line=3' "$B/net.txt" && ok "net refusal names word, class and line" || bad "net refusal text" +"$E" src allow=io,nosuch < $C/plain.om > /dev/null; want "NEGATIVE unknown class" 2 $? +for f in plain clock files net; do "$E" verify $C/$f.om "$B/$f" > /dev/null; want "verify $f" 0 $?; done +"$E" verify $C/plain.om "$B/net" > "$B/undecl.txt"; want "NEGATIVE verify plain source vs net binary" 1 $? +grep -q '^VERIFY FAIL undeclared=57,198' "$B/undecl.txt" && ok "undeclared syscalls named (57,198)" || bad "undeclared text: $(tail -1 "$B/undecl.txt")" + +# 5. Corpus: every program-mode unit in seed/host/tests and the fixtures; binary within source. +cn=0; cf=0 +for s in seed/host/tests/*.om seed/rung4/tests/*.om; do + grep -q '^fn main' "$s" || continue + o=$B/corpus/$(echo "$s" | tr '/' '_') + build "$s" "$o" || continue + cn=$((cn + 1)) + "$E" verify "$s" "$o" > "$o.v" || { cf=$((cf + 1)); echo " corpus FAIL $s: $(tail -1 "$o.v")"; } +done +[ $cn -gt 0 ] && [ $cf = 0 ] && ok "corpus verify: $cn compiled programs, binary syscalls within source manifest" || bad "corpus verify: $cf of $cn" +"$E" verify seed/omc/omc.om "$OMC" > "$B/omc.v"; want "verify omc.om vs pinned omc" 0 $? + +# 6. Dynamic oracle: syscalls observed by strace (after the initial execve) within the ELF set. +dyn() { # dyn NAME BINARY [ARGS] < stdin + n=$1; shift + (cd "$B/run" && strace -f -n -qq -o "$B/run/$n.st" "$@" > /dev/null 2>&1) + obs=$(sed 1d "$B/run/$n.st" | sed -n 's/^[0-9]* \[ *\([0-9]*\)\].*/\1/p' | sort -n -u | tr '\n' ' ') + allow=$("$E" elf < "$1" | sys_of | tr ',' ' ') + extra="" + for x in $obs; do case " $allow " in *" $x "*) ;; *) extra="$extra $x";; esac; done + [ -z "$extra" ] && ok "strace $n observed [$obs] within ELF" || bad "strace $n undeclared:$extra" +} +dyn plain "$B/plain" +dyn clock "$B/clock" +dyn files "$B/files" +dyn net "$B/net" +dyn self "$E" src < seed/effects/effects.om +dyn selfv "$E" verify "$ROOT/seed/effects/effects.om" "$E" + +# 7. Enforcement: the manifest compiled to seccomp cBPF, loaded by bwrap before execve. +# 'launch' adds execve (221), which bwrap needs to start the program. +sec() { # sec NAME FILTER_SOURCE BINARY EXPECTED_EXIT + "$E" bpf launch < "$2" > "$B/run/$1.bpf" + (cd "$B/run" && bwrap --dev-bind / / --seccomp 9 "$3" > /dev/null 2>&1 9< "$B/run/$1.bpf") + want "seccomp $1" "$4" $? +} +sec plain $C/plain.om "$B/plain" 0 +sec clock $C/clock.om "$B/clock" 0 +sec files $C/files.om "$B/files" 0 +sec net $C/net.om "$B/net" 0 +sec plain-runs-net $C/plain.om "$B/net" 159 +sec plain-runs-clock $C/plain.om "$B/clock" 159 +sec clock-runs-files $C/clock.om "$B/files" 159 +"$E" bpf launch < seed/effects/effects.om > "$B/run/self.bpf" +bwrap --dev-bind / / --seccomp 9 "$E" src < seed/effects/effects.om 9< "$B/run/self.bpf" | tail -1 | grep -q '^EFFECTS 1 words=6 ' \ + && ok "effects runs under its own filter" || bad "effects under its own filter" +"$E" bpf < $C/plain.om > "$B/run/exact.bpf" +[ "$(wc -c < "$B/run/exact.bpf")" = 64 ] && ok "exact filter for plain = 8 instructions (64 bytes)" || bad "exact filter size $(wc -c < "$B/run/exact.bpf")" + +# 8. Fail-closed ELF controls (patched copies of plain). +word_at_svc() { # index of the first SVC word in the text segment + od -An -v -tx4 -w4 "$1" | awk '$1 == "d4000001" { print NR - 1; exit }' +} +patch() { # patch IN OUT WORDINDEX LE_BYTES(octal escapes) + cp "$1" "$2" + printf "$4" | dd of="$2" bs=1 seek=$(($3 * 4)) conv=notrunc 2> /dev/null +} +i=$(word_at_svc "$B/plain") +patch "$B/plain" "$B/run/nomovz" $((i - 1)) '\037\040\003\325' # NOP replaces MOVZ X8 +"$E" elf < "$B/run/nomovz" > "$B/run/nomovz.txt"; want "NEGATIVE svc without MOVZ X8" 3 $? +grep -q 'reason=prev-not-movz-x8' "$B/run/nomovz.txt" && ok " reason prev-not-movz-x8" || bad " reason text" +patch "$B/plain" "$B/run/movzx9" $((i - 1)) '\011\010\200\322' # MOVZ X9,#64: right number, wrong register +"$E" elf < "$B/run/movzx9" > "$B/run/movzx9.txt"; want "NEGATIVE svc after MOVZ X9" 3 $? +grep -q 'reason=prev-not-movz-x8' "$B/run/movzx9.txt" && ok " reason prev-not-movz-x8" || bad " reason text" +patch "$B/plain" "$B/run/btgt" $((i - 2)) '\002\000\000\024' # B +2 lands on the SVC +"$E" elf < "$B/run/btgt" > "$B/run/btgt.txt"; want "NEGATIVE branch into SVC" 3 $? +grep -q 'reason=branch-target' "$B/run/btgt.txt" && ok " reason branch-target" || bad " reason text" +patch "$B/plain" "$B/run/br" $((i - 2)) '\000\000\037\326' # BR X0 +"$E" elf < "$B/run/br" > "$B/run/br.txt"; want "NEGATIVE indirect branch" 3 $? +patch "$B/plain" "$B/run/wx" 17 '\007' # p_flags of phdr 0 = RWX +"$E" elf < "$B/run/wx" > "$B/run/wx.txt"; want "NEGATIVE W+X segment" 3 $? +grep -qx 'ELF REFUSED wx-segment' "$B/run/wx.txt" && ok " reason wx-segment" || bad " reason text" +printf 'not an elf' > "$B/run/junk" +"$E" elf < "$B/run/junk" > /dev/null; want "NEGATIVE not an ELF" 3 $? + +# 9. Tool mutants must be killed by the checks above. +mut() { # mut NAME SED_EXPR + sed "$2" seed/effects/effects.om > "$B/mut-$1.om" + if cmp -s seed/effects/effects.om "$B/mut-$1.om"; then bad "mutant $1 did not apply"; return; fi + build "$B/mut-$1.om" "$B/mut-$1" || { bad "mutant $1 does not compile"; return; } + k="" + probe_parity "$B/mut-$1" > /dev/null || k="$k probe-parity" + "$B/mut-$1" table | cut -d' ' -f1 | grep -v -x -e read -e write | sort | cmp -s - "$B/kw.txt" || k="$k closure" + "$B/mut-$1" verify $C/clock.om "$B/clock" > /dev/null || k="$k verify" + "$B/mut-$1" elf < "$B/run/movzx9" > /dev/null; [ $? = 3 ] || k="$k movzx9" + [ -n "$k" ] && ok "mutant $1 killed by:$k" || bad "mutant $1 survived" +} +mut drop-getpid 's/getpid ident 172 -\\n//' +mut wrong-random 's/random random 278 -/random random 277 -/' +mut svc-any-prev 's/^if ne and p 4292870175 3531603976$/if eq p 1/' + +if [ $fails = 0 ]; then echo "SEMANTIC EFFECTS PASS checks=$checks"; exit 0; fi +echo "SEMANTIC EFFECTS FAIL failed=$fails checks=$checks"; exit 1 diff --git a/seed/effects/effects.om b/seed/effects/effects.om new file mode 100644 index 000000000..095305feb --- /dev/null +++ b/seed/effects/effects.om @@ -0,0 +1,867 @@ +note effects: effect-derived capability manifest for seeded-Omega programs. +note A unit can reach the kernel only through the closed set of keyword operations in +note OMEGESE section 10 (no raw syscall, no address-to-pointer), so the set of host +note words in its source is a complete, finite statement of its OS effects. +note Modes: +note effects src [allow=C,..] < unit.om host words, classes, Linux syscalls +note effects elf < binary syscalls the omc ELF can issue (fail closed) +note effects verify SRC BIN [allow=C,..] ELF syscalls must be within the source set +note effects bpf [launch] < unit.om seccomp cBPF allow-list (bwrap --seccomp) +note effects table the word table, for the probe parity test +note Exit: 0 pass, 1 refused/undeclared, 2 usage, 3 invalid or unresolvable input, 4 read. + +global inb uchar 8388612 +global mk uchar 2097156 +global ob uchar 1048576 +global obn ulong 1 +global dig uchar 24 +global ab uchar 4096 +global wn ulong 128 +global wc ulong 128 +global ws1 ulong 128 +global ws2 ulong 128 +global wl ulong 128 +global wk ulong 128 +global nw ulong 1 +global cn ulong 16 +global ncl ulong 1 +global sy uchar 512 +global se uchar 512 +global cu uchar 16 +global al uchar 16 +global st ulong 16 +global ef ulong 8 + +note word class syscall1 syscall2 ('-' none). Kept equal to the pinned omc by check.sh, +note which compiles one probe per word and reads the syscalls back out of the ELF. +text tab "read io 63 -\nwrite io 64 -\nfclose fd 57 -\nfsync fd 82 -\nfdsync fd 83 -\nfseek fd 62 -\nftrunc fd 46 -\nfchmod fd 52 -\nfchdir fd 50 -\nsyncfs fd 267 -\nflock fd 32 -\ngetdnts fd 61 -\nfstat fd 80 -\npread fd 67 -\npwrite fd 68 -\ndupfd fd 24 -\npipefds fd 59 -\nwaitio fd 73 -\npollfds fd 73 -\nmemfd fd 279 -\nfopen path 56 -\nchmod path 53 -\nchown path 54 -\nfaccess path 48 -\ntruncate path 45 -\nunlink path 35 -\nmakedir path 34 -\nrmdir path 35 -\ncwd path 17 -\nchdir path 49 -\nreadlnk path 78 -\nstat path 79 -\nlstat path 79 -\nrenames path 276 -\nlink path 37 -\nsymlnk path 36 -\nsocknew net 198 -\nbind net 200 -\nconnect net 203 -\nlisten net 201 -\naccept net 242 -\nsockname net 204 -\nsockopt net 208 -\nrecv net 207 -\nsend net 206 -\npeercred net 209 -\nsendmsg net 211 -\nshutdown net 210 -\nfork proc 220 -\nexecprog proc 221 -\nkillpid proc 129 -\nwaitpid proc 260 -\nsetsid proc 157 -\nsetpgid proc 154 -\numask proc 166 -\ngetpid ident 172 -\ngetppid ident 173 -\ngetuid ident 174 -\ngeteuid ident 175 -\ngetgid ident 176 -\ngetegid ident 177 -\ngetpgid ident 155 -\ngetsid ident 156 -\nmonons time 113 -\nrealns time 113 -\nsleepns time 101 -\nargcnt env - -\nargread env - -\nenvcnt env - -\nenvread env - -\nrandom random 278 -\ndevctl device 29 -\ndevcall device 29 -\nuvmctl device 29 -\nmapnew device 222 -\nmapdrop device 215 -\nmaphold device 215 222\nmapbind device 215 222\nmapread device - -\nmapwrite device - -\nmapaddr device - -\nmapget device - -\nmapset device - -\n" +text cls "io\nfd\npath\nnet\nproc\nident\ntime\nenv\nrandom\ndevice\n" +text kwn "note allow= launch src elf verify bpf table " +text msg "EFFECT \n class=\n syscalls=\n uses=\n line=\nEFFECTS 1 words=\n classes=\nEFFECTS REFUSED word=\nEFFECTS PASS\nEFFECTS REFUSED n=\nELF 1 words=\n svc=\nELF UNRESOLVED at=\n reason=prev-not-movz-x8\n reason=branch-target\n reason=indirect-branch\nELF INVALID\nVERIFY PASS syscalls=\nVERIFY FAIL undeclared=\n unused=\nusage: effects src [allow=C,..] < unit.om | elf < binary | verify SRC BIN [allow=C,..] | bpf [launch] < unit.om | table\neffects: cannot read input\n-\n,\n \nELF REFUSED wx-segment\nEFFECTS REFUSED unknown-class\n reason=nr-range\nELF REFUSED no-exec-segment\n" + +note ---- output ---- +fn obf to void +n = get obn 0 +o = ulong 0 +while lt o n +r = write 1 ob o sub n o +if le r 0 +exit 4 +end +o = add o ulong r +end +put obn 0 0 +end +fn ob1 b uchar to void +n = get obn 0 +if ge n 1048000 +obf +n = ulong 0 +end +put ob n b +put obn 0 add n 1 +end +fn onl to void +ob1 10 +end +fn say id ulong to void +k = ulong 0 +s = ulong 0 +for i ulong len msg +if eq get msg i 10 +if eq k id +for j ulong sub i s +ob1 get msg add s j +end +ret +end +k = add k 1 +s = add i 1 +end +end +end +fn od v ulong to void +x = v +n = ulong 0 +while ge x 10 +put dig n uchar add 48 rem x 10 +x = div x 10 +n = add n 1 +end +put dig n uchar add 48 x +n = add n 1 +for i ulong n +ob1 get dig sub sub n i 1 +end +end +fn pw w ulong to void +x = w +for i ulong 8 +if eq x 0 +ret +end +ob1 uchar and x 255 +x = shr x 8 +end +end + +note ---- tables ---- +fn kwp id ulong to ulong +k = ulong 0 +w = ulong 0 +s = ulong 0 +for i ulong len kwn +c = get kwn i +if eq c 32 +if eq k id +ret w +end +k = add k 1 +w = ulong 0 +s = ulong 0 +else +w = or w shl ulong c s +s = add s 8 +end +end +ret 0 +end +fn clsid w ulong to ulong +for i ulong get ncl 0 +if eq get cn i w +ret i +end +end +ret 99 +end +fn tinit to void +w = ulong 0 +s = ulong 0 +r = ulong 0 +for i ulong len cls +c = get cls i +if eq c 10 +put cn r w +r = add r 1 +w = ulong 0 +s = ulong 0 +else +w = or w shl ulong c s +s = add s 8 +end +end +put ncl 0 r +dash = ulong 45 +r = ulong 0 +f = ulong 0 +w = ulong 0 +s = ulong 0 +d = ulong 0 +for i ulong len tab +c = get tab i +if or eq c 32 eq c 10 +if eq f 0 +put wn r w +end +if eq f 1 +put wc r clsid w +end +if eq f 2 +if eq w dash +put ws1 r 65535 +else +put ws1 r d +end +end +if eq f 3 +if eq w dash +put ws2 r 65535 +else +put ws2 r d +end +end +f = add f 1 +if eq c 10 +r = add r 1 +f = ulong 0 +end +w = ulong 0 +s = ulong 0 +d = ulong 0 +else +w = or w shl ulong c s +s = add s 8 +d = add mul d 10 sub ulong c 48 +end +end +put nw 0 r +end + +note ---- input ---- +fn rdfd fd int to ulong +n = ulong 0 +for i ulong 8388608 +r = read fd inb n sub 8388612 n +if lt r 0 +ret 8388613 +end +if eq r 0 +ret n +end +n = add n ulong r +if ge n 8388612 +ret 8388613 +end +end +ret 8388613 +end +fn rdarg ix ulong to ulong +m = argread ix ab 0 4095 +if le m 0 +ret 8388613 +end +fd = int fopen ab 0 ulong m 0 0 +if lt fd 0 +ret 8388613 +end +n = rdfd fd +c = fclose fd +ret n +end +fn argw ix ulong to ulong +m = argread ix ab 0 4095 +if or le m 0 gt m 8 +ret 0 +end +w = ulong 0 +for i ulong ulong m +w = or w shl ulong get ab i mul i 8 +end +ret w +end +note allow=C1,C2 in argument ix; returns false on an unknown class name +fn parsal ix ulong to bool +m = argread ix ab 0 4095 +if le m 0 +ret false +end +if lt m 6 +ret false +end +pfx = ulong 0 +for i ulong 6 +pfx = or pfx shl ulong get ab i mul i 8 +end +if ne pfx kwp 1 +ret false +end +put ef 0 1 +w = ulong 0 +s = ulong 0 +for i ulong sub ulong m 5 +j = add i 6 +c = uchar 44 +if lt j ulong m +c = get ab j +end +if eq c 44 +if gt s 0 +k = clsid w +if eq k 99 +ret false +end +put al k 1 +end +w = ulong 0 +s = ulong 0 +else +if ge s 64 +ret false +end +w = or w shl ulong c s +s = add s 8 +end +end +ret true +end + +note ---- source scan: every host word occurrence outside notes and text literals ---- +fn hit w ulong ln ulong to void +for r ulong get nw 0 +if eq get wn r w +put wk r add get wk r 1 +if eq get wl r 0 +put wl r ln +end +put cu get wc r 1 +a = get ws1 r +if lt a 512 +put sy a 1 +end +b = get ws2 r +if lt b 512 +put sy b 1 +end +ret +end +end +end +note st: 0 packed word, 1 word length, 2 line, 3 skip-to-eol, 4 in quote, 5 escape, 6 first word on line +fn fin to void +l = get st 1 +if eq l 0 +ret +end +w = get st 0 +if and eq get st 6 1 and eq l 4 eq w kwp 0 +put st 3 1 +else +if le l 8 +hit w get st 2 +end +end +put st 6 0 +put st 0 0 +put st 1 0 +end +fn scansrc n ulong to void +put st 0 0 +put st 1 0 +put st 2 1 +put st 3 0 +put st 4 0 +put st 5 0 +put st 6 1 +put sy 93 1 +for i ulong 8388608 +if ge i n +break +end +c = get inb i +if eq c 10 +fin +put st 2 add get st 2 1 +put st 3 0 +put st 4 0 +put st 5 0 +put st 6 1 +continue +end +if eq get st 3 1 +continue +end +if eq get st 4 1 +if eq get st 5 1 +put st 5 0 +else +if eq c 92 +put st 5 1 +end +if eq c 34 +put st 4 0 +end +end +continue +end +if or or eq c 32 eq c 9 or eq c 13 or eq c 40 eq c 41 +fin +continue +end +if eq c 34 +fin +put st 4 1 +put st 6 0 +continue +end +l = get st 1 +if lt l 8 +put st 0 or get st 0 shl ulong c mul l 8 +end +put st 1 add l 1 +end +fin +end +fn plist a ulong to void +note a 0: source set, 1: elf set, 2: elf minus source, 3: source minus elf +k = ulong 0 +for i ulong 512 +x = get sy i +y = get se i +p = false +if eq a 0 +p = eq x 1 +end +if eq a 1 +p = eq y 1 +end +if eq a 2 +p = and eq y 1 eq x 0 +end +if eq a 3 +p = and eq x 1 eq y 0 +end +if p +if gt k 0 +say 23 +end +od i +k = add k 1 +end +end +if eq k 0 +say 22 +end +end +fn psys r ulong to void +a = get ws1 r +b = get ws2 r +if ge a 512 +say 22 +ret +end +od a +if lt b 512 +say 23 +od b +end +end +fn report to int +u = ulong 0 +for r ulong get nw 0 +if gt get wk r 0 +u = add u 1 +say 0 +pw get wn r +say 1 +pw get cn get wc r +say 2 +psys r +say 3 +od get wk r +say 4 +od get wl r +onl +end +end +say 5 +od u +say 6 +k = ulong 0 +for i ulong get ncl 0 +if eq get cu i 1 +if gt k 0 +say 23 +end +pw get cn i +k = add k 1 +end +end +if eq k 0 +say 22 +end +say 2 +plist 0 +onl +ret refuse +end +fn refuse to int +if eq get ef 0 0 +ret 0 +end +bad = ulong 0 +for r ulong get nw 0 +if and gt get wk r 0 eq get al get wc r 0 +bad = add bad 1 +say 7 +pw get wn r +say 1 +pw get cn get wc r +say 4 +od get wl r +onl +end +end +if eq bad 0 +say 8 +onl +ret 0 +end +say 9 +od bad +onl +ret 1 +end + +note ---- ELF scan of an omc static AArch64 binary ---- +fn r8 o ulong to ulong +ret ulong get inb o +end +fn r16 o ulong to ulong +ret or r8 o shl r8 add o 1 8 +end +fn r32 o ulong to ulong +ret or r16 o shl r16 add o 2 16 +end +fn r64 o ulong to ulong +ret or r32 o shl r32 add o 4 32 +end +fn bad3 id ulong to int +say id +onl +ret 3 +end +fn unres at ulong why ulong to int +say 12 +od at +say why +onl +ret 3 +end +note branch target of word w at index j, or 4294967295 if w is not a direct branch +fn btgt w ulong j ulong to ulong +o = ulong 0 +m = ulong 0 +if eq and w 2080374784 335544320 +o = and w 67108863 +m = 67108864 +end +if or eq and w 4278190096 1409286144 eq and w 2113929216 872415232 +o = and shr w 5 524287 +m = 524288 +end +if eq and w 2113929216 905969664 +o = and shr w 5 16383 +m = 16384 +end +if eq m 0 +ret 4294967295 +end +if ge o div m 2 +b = sub m o +if gt b j +ret 4294967294 +end +ret sub j b +end +ret add j o +end +fn scantext off ulong fsz ulong to int +nwd = div fsz 4 +if gt nwd 2097152 +ret bad3 16 +end +for j ulong 2097152 +if ge j nwd +break +end +put mk j 0 +end +for j ulong 2097152 +if ge j nwd +break +end +w = r32 add off mul j 4 +if or eq and w 4294966303 3592355840 eq and w 4294966303 3594452992 +ret unres j 15 +end +if eq and w 4292870175 3556769793 +put ef 1 add get ef 1 1 +put mk j 1 +if eq j 0 +ret unres j 13 +end +p = r32 add off mul sub j 1 4 +if ne and p 4292870175 3531603976 +ret unres j 13 +end +nr = and shr p 5 65535 +if ge nr 512 +ret unres j 29 +end +put se nr 1 +end +end +for j ulong 2097152 +if ge j nwd +break +end +t = btgt r32 add off mul j 4 j +if lt t nwd +if eq get mk t 1 +ret unres t 14 +end +end +end +put ef 2 add get ef 2 nwd +ret 0 +end +note one program header: -1 not an executable load, 0 scanned, >0 exit code +fn seg p ulong n ulong to int +t = r32 p +f = r32 add p 4 +if ne t 1 +ret -1 +end +if and ne and f 1 0 ne and f 2 0 +say 25 +onl +ret 3 +end +if eq and f 1 0 +ret -1 +end +off = r64 add p 8 +fsz = r64 add p 32 +if or ne rem off 4 0 gt add off fsz n +ret bad3 16 +end +ret scantext off fsz +end +fn scanelf n ulong to int +if lt n 64 +ret bad3 16 +end +if or ne r32 0 1179403647 ne r16 18 183 +ret bad3 16 +end +ph = r64 32 +pe = r16 54 +pn = r16 56 +if or ne pe 56 gt add ph mul pn 56 n +ret bad3 16 +end +nx = ulong 0 +for i ulong pn +v = seg add ph mul i 56 n +if gt v 0 +ret v +end +if eq v 0 +nx = add nx 1 +end +end +if eq nx 0 +say 30 +onl +ret 3 +end +ret 0 +end +fn elfrep to void +say 10 +od get ef 2 +say 11 +od get ef 1 +say 2 +plist 1 +onl +end + +note ---- seccomp cBPF: arch check, one JEQ per allowed nr, kill otherwise ---- +fn binst code ulong jt ulong jf ulong k ulong to void +ob1 uchar and code 255 +ob1 uchar shr code 8 +ob1 uchar jt +ob1 uchar jf +ob1 uchar and k 255 +ob1 uchar and shr k 8 255 +ob1 uchar and shr k 16 255 +ob1 uchar shr k 24 +end +fn bpfout to void +m = ulong 0 +for i ulong 512 +if eq get sy i 1 +m = add m 1 +end +end +binst 32 0 0 4 +binst 21 1 0 3221225655 +binst 6 0 0 2147483648 +binst 32 0 0 0 +t = ulong 0 +for i ulong 512 +if eq get sy i 1 +binst 21 sub m t 0 i +t = add t 1 +end +end +binst 6 0 0 2147483648 +binst 6 0 0 2147418112 +end + +fn ptable to void +for r ulong get nw 0 +pw get wn r +ob1 32 +pw get cn get wc r +ob1 32 +a = get ws1 r +if lt a 512 +od a +else +say 22 +end +ob1 32 +b = get ws2 r +if lt b 512 +od b +else +say 22 +end +onl +end +end + +fn main to int +tinit +ac = argcnt +if lt ac 2 +say 20 +onl +obf +ret 2 +end +md = argw 1 +if eq md kwp 7 +ptable +obf +ret 0 +end +if eq md kwp 3 +if gt ac 3 +say 20 +onl +obf +ret 2 +end +if eq ac 3 +if not parsal 2 +say 26 +onl +obf +ret 2 +end +end +n = rdfd 0 +if gt n 8388612 +say 21 +onl +obf +ret 4 +end +scansrc n +v = report +obf +ret v +end +if eq md kwp 4 +if ne ac 2 +say 20 +onl +obf +ret 2 +end +n = rdfd 0 +if gt n 8388612 +say 21 +onl +obf +ret 4 +end +v = scanelf n +if eq v 0 +elfrep +end +obf +ret v +end +if eq md kwp 6 +lw = ulong 0 +if eq ac 3 +lw = argw 2 +end +if or gt ac 3 and eq ac 3 ne lw kwp 2 +say 20 +onl +obf +ret 2 +end +n = rdfd 0 +if gt n 8388612 +say 21 +onl +obf +ret 4 +end +scansrc n +if eq ac 3 +put sy 221 1 +end +bpfout +obf +ret 0 +end +if eq md kwp 5 +if or lt ac 4 gt ac 5 +say 20 +onl +obf +ret 2 +end +if eq ac 5 +if not parsal 4 +say 26 +onl +obf +ret 2 +end +end +n = rdarg 2 +if gt n 8388612 +say 21 +onl +obf +ret 4 +end +scansrc n +v = report +n = rdarg 3 +if gt n 8388612 +say 21 +onl +obf +ret 4 +end +e = scanelf n +if ne e 0 +obf +ret e +end +elfrep +k = ulong 0 +for i ulong 512 +if and eq get se i 1 eq get sy i 0 +k = add k 1 +end +end +if gt k 0 +say 18 +plist 2 +onl +obf +ret 1 +end +say 17 +plist 1 +say 19 +plist 3 +onl +obf +ret v +end +say 20 +onl +obf +ret 2 +end