interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

[Codex Security] Checked native entry omits fixed-reference provenance validation

open 5ec9a4bb211dc589 #3 · opened 2026-11-15 16:47 UTC

Imported from GitHub drakestapleton/omega-mv#3, by drakestapleton

Base 91f88c287d7831784a808c5b054818fd9055afb5 · Head 6d13724d90d60adb2c52c467825a1923d8f2010e

drakestapleton wrote on 2026-11-15 16:47 UTC

The patch centralizes complete argument validation before checked native execution.

  • osc_rt_args_ok now rejects missing runtimes, arbitrary or stale references, wrong-length slots, noncanonical scalars and booleans, and malformed slice pairs.
  • osc_native_call invokes the shared guard before osc_rt_call_native, so attacker-selected bases cannot reach generated LDR or STR instructions.
  • osc_interp_run_prevalidated shares the same guard, while valid live references, canonical values, existing slices, -1 refusals, and the documented raw entry remain supported.

Static Verification Checks

  • Native boundary closure (Passed) — Static inspection of osc_native_call, with runtime checks not performed, establishes validation precedes the vulnerable native dereference path.
  • Reference provenance enforcement (Passed) — osc_rt_args_ok and osc_rt_is_live_ref require exact live-slot starts and lengths, closing arbitrary, stale, and mismatched-base access.
  • Interpreter compatibility preserved (Passed) — osc_interp_run_prevalidated uses the shared validator, preserving canonical scalar, reference, slice, arity, and refusal behavior.
  • Hostile ingress assertions (Passed) — tests/compiler/test_osc_compiler.c asserts rejected calls preserve ret while valid live references still return expected data.
  • Finding: acf_2de501fc05d409693206cddb10041676

  • Patch: arp_7ec29858ea02d6f8f23b032d795c9344
  • Base commit: 91f88c287d7831784a808c5b054818fd9055afb5
  • Patch SHA-256: 6d67361829baec3650ede72dfbcb389d35dc92dfaf9c1ad628ebc9f671db0237

Apply it

git checkout -b patch-5ec9a4bb211dc589 91f88c287d7831784a808c5b054818fd9055afb5
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/5ec9a4bb211dc589.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
drakestapleton/omega-mv
3
6d13724d90d60adb2c52c467825a1923d8f2010e
{"kind":"github-import","owner":"drakestapleton","repo":"omega-mv","number":3,"url":"https://github.com/drakestapleton/omega-mv/pull/3","export_sha256":"7a4dc05cfaafc4ff4b6c7811f8b55128091a7d4d233c7761f900f26220660f83","imported_utc":"2026-11-18T16:39:51Z"}

Changes

diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index aa4a7bd38..136bdd3a2 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -7,6 +7,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE
 
 | Model | What it did |
 |---|---|
+| Codex | Unified interpreter and checked-native argument validation for live fixed references, canonical scalars, and external slices, with hostile-ingress regression coverage. |
 | Grok 4.7 (via Cursor Agent) | Merged main `fd3751b31` (#1020, carrying #1045 and #1050) into #1052. The only conflict was the generated root `.crumb` (child `last_commit` stamps, the `tests` digest, and the root digest). Recompiled with the crumb.lock tool (`d0f0b95d`); `crumb verify .` current. The #525/#962 pins were left as committed: `src/checker2/c2_check.c`, `src/compiler/osc_ir.c` and `src/compiler/osc_ir.h` still hash to the SHA-256s in `ACCEPTED`. |
 | Claude Opus 5.5 (via omp) | #1020 (actions/cache-4.3.0 ->6.1.0): merged main `d3d1b1bc` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d`). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). |
 | Claude Opus 5.5 (via omp) | #1018 (actions/upload-artifact-4 ->7): merged main `d3d1b1bc` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d`). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). |
diff --git a/src/compiler/osc_interp.c b/src/compiler/osc_interp.c
index 000a2fde4..b02f84002 100644
--- a/src/compiler/osc_interp.c
+++ b/src/compiler/osc_interp.c
@@ -225,25 +225,9 @@ static uint64_t run_func(Ctx *c, int fi, const uint64_t *args) {
     }
 }
 
-static int check_args(const OscUnit *u, int func, const uint64_t *args, unsigned nargs, const OscRt *rt) {
-    if (!rt || func < 0 || func >= u->nfuncs) return -1;
-    const OscFunc *f = &u->funcs[func];
-    if (nargs != f->nparams || (nargs && !args)) return -1;
-    for (unsigned p = 0; p < nargs; p++) {
-        const OscType *t = &f->vtype[p];
-        if (t->s == OSC_T_BYTES || t->s == OSC_T_CELLS) continue; /* external pointer: checked as a pair below */
-        if (t->s == OSC_T_REF) {
-            if (!osc_rt_is_live_ref(rt, args[p], t->len)) return -1;
-        } else if (canon(t->s, args[p]) != args[p]) {
-            return -1;
-        }
-    }
-    return osc_ir_slice_args_ok(f, args, nargs); /* NULL with len > 0, wrapping range, overlapping cells */
-}
-
 int osc_interp_run_prevalidated(const OscUnit *u, int func, const uint64_t *args, unsigned nargs, OscRt *rt,
                                 uint64_t *ret) {
-    if (!u || !ret || check_args(u, func, args, nargs, rt)) return -1;
+    if (!u || !ret || func < 0 || func >= u->nfuncs || osc_rt_args_ok(&u->funcs[func], args, nargs, rt)) return -1;
     Ctx c = {u, rt, 0};
     uint64_t a[OSC_MAX_PARAMS] = {0};
     for (unsigned i = 0; i < nargs; i++) a[i] = args[i];
diff --git a/src/compiler/osc_native.c b/src/compiler/osc_native.c
index 82fe5ff99..bd479bdc5 100644
--- a/src/compiler/osc_native.c
+++ b/src/compiler/osc_native.c
@@ -64,6 +64,6 @@ int osc_native_call(const OscUnit *u, int fi, const OscNative *nm, uint32_t entr
     if (!u || !nm || fi < 0 || (unsigned)fi >= u->nfuncs) return -1;
     void *entry = osc_native_at(nm, entry_off);
     if (!entry) return -1;
-    if (osc_ir_slice_args_ok(&u->funcs[fi], args, nargs)) return -1; /* refused: never calls in */
+    if (osc_rt_args_ok(&u->funcs[fi], args, nargs, rt)) return -1; /* refused: never calls in */
     return osc_rt_call_native(rt, entry, args, nargs, ret);
 }
diff --git a/src/compiler/osc_native.h b/src/compiler/osc_native.h
index 1f2243784..802796bd3 100644
--- a/src/compiler/osc_native.h
+++ b/src/compiler/osc_native.h
@@ -40,8 +40,9 @@ int osc_native_map(OscNative *nm, const uint8_t *code, size_t len);
 /* Address of byte offset `off` in the mapping, or NULL if out of range/misaligned. */
 void *osc_native_at(const OscNative *nm, uint32_t off);
 void osc_native_unmap(OscNative *nm);
-/* Checked native entry: refuses (-1, no call) malformed or overlapping slice args via osc_ir_slice_args_ok, else
- * osc_rt_call_native on the code at entry_off. Returns the trap code (0 = ok) or -1. osc_rt_call_native is raw and unchecked. */
+/* Checked native entry: refuses (-1, no call) invalid arguments via osc_rt_args_ok,
+ * else osc_rt_call_native on the code at entry_off. Returns the trap code
+ * (0 = ok) or -1. osc_rt_call_native is raw and unchecked. */
 int osc_native_call(const OscUnit *u, int fi, const OscNative *nm, uint32_t entry_off, OscRt *rt, const uint64_t *args,
                     unsigned nargs, uint64_t *ret);
 
diff --git a/src/compiler/osc_rt.c b/src/compiler/osc_rt.c
index 04e81b65d..607e5178b 100644
--- a/src/compiler/osc_rt.c
+++ b/src/compiler/osc_rt.c
@@ -146,6 +146,32 @@ int osc_rt_is_live_ref(const OscRt *rt, uint64_t addr, uint64_t len) {
     return slot_of(rt, addr, len) >= 0;
 }
 
+static uint64_t canonical_arg(OscScalar t, uint64_t x) {
+    unsigned w = osc_scalar_width(t);
+    if (t == OSC_T_BOOL) return x & 1;
+    if (w >= 64) return x;
+    if (osc_scalar_signed(t)) {
+        uint64_t m = 1ULL << (w - 1);
+        x &= (1ULL << w) - 1;
+        return (x ^ m) - m;
+    }
+    return x & ((1ULL << w) - 1);
+}
+
+int osc_rt_args_ok(const OscFunc *f, const uint64_t *args, unsigned nargs, const OscRt *rt) {
+    if (!rt || !f || nargs != f->nparams || (nargs && !args)) return -1;
+    for (unsigned p = 0; p < nargs; p++) {
+        const OscType *t = &f->vtype[p];
+        if (t->s == OSC_T_BYTES || t->s == OSC_T_CELLS) continue; /* external pointer: checked as a pair below */
+        if (t->s == OSC_T_REF) {
+            if (!osc_rt_is_live_ref(rt, args[p], t->len)) return -1;
+        } else if (canonical_arg(t->s, args[p]) != args[p]) {
+            return -1;
+        }
+    }
+    return osc_ir_slice_args_ok(f, args, nargs); /* NULL with len > 0, wrapping range, overlapping cells */
+}
+
 void osc_rt_release(OscRt *rt, uint64_t addr, uint64_t len) {
     int s = slot_of(rt, addr, len);
     if (s < 0 || rt->slot_arena[s]) osc_rt_trap(rt, OSC_TRAP_RUNTIME);
diff --git a/src/compiler/osc_rt.h b/src/compiler/osc_rt.h
index 968c8e0de..42198d0fd 100644
--- a/src/compiler/osc_rt.h
+++ b/src/compiler/osc_rt.h
@@ -171,6 +171,11 @@ int osc_rt_same_outcome(const OscRt *a, const OscRt *b);
 /* 1 if addr is the start of a live slot (used to check REF arguments). */
 int osc_rt_is_live_ref(const OscRt *rt, uint64_t addr, uint64_t len);
 
+/* Checked host-call boundary for a validated function: 0 if every argument is
+ * canonical for its scalar type, every REF names a live slot of matching
+ * length in rt, and every external slice pair is valid; -1 otherwise. */
+int osc_rt_args_ok(const OscFunc *f, const uint64_t *args, unsigned nargs, const OscRt *rt);
+
 /* ---- OSC-2 arenas (docs/osc/OSC-2-DESIGN.md section 3) ----------------
  * An arena is one pool slot with capacity cap (1..OSC_MAX_ARRAY_LEN cells),
  * opened by osc_rt_arena_open, which returns its handle (the slot's address)
diff --git a/tests/compiler/test_osc_compiler.c b/tests/compiler/test_osc_compiler.c
index 3353f1374..c531308e9 100644
--- a/tests/compiler/test_osc_compiler.c
+++ b/tests/compiler/test_osc_compiler.c
@@ -2122,6 +2122,63 @@ static void slice_host_checks(void)
     free(buf);
 }
 
+/* checked native entry: fixed references must belong to the supplied runtime,
+ * match their declared length, remain live, and accompany canonical scalars */
+static void native_arg_checks(void)
+{
+    OscUnit *u = U1;
+    OscDiag d;
+    const char *src = "fn f(a: &[u64; 2], i: u8, take: bool) -> u64 { if take { return a[i]; } return 9; }\n";
+    CHECK(osc_compile(src, strlen(src), u, &d, NULL) == 0, "native-arg unit refused: %s", d.message);
+    const OscFunc *f = &u->funcs[0];
+    CHECK(f->nparams == 3, "native-arg function should take three registers, got %u", f->nparams);
+
+    osc_rt_reset(RN);
+    uint64_t live = osc_rt_alloc(RN, 2, 11);
+    uint64_t wrong_len = osc_rt_alloc(RN, 3, 12);
+    uint64_t stale = osc_rt_alloc(RN, 2, 13);
+    osc_rt_release(RN, stale, 2);
+    ((uint64_t *)(uintptr_t)live)[1] = 42;
+    uint64_t fake[2] = {21, 22};
+    uint64_t good[3] = {live, 1, 1};
+    uint64_t bad[5][3] = {
+        {(uint64_t)(uintptr_t)fake, 1, 1}, /* address outside the runtime pool */
+        {wrong_len, 1, 1},                /* live slot of the wrong declared length */
+        {stale, 1, 1},                    /* released slot */
+        {live, 256, 1},                   /* noncanonical u8 */
+        {live, 1, 2}                      /* noncanonical bool */
+    };
+    const char *why[5] = {"arbitrary reference", "wrong-length reference", "stale reference", "noncanonical u8",
+                          "noncanonical bool"};
+    CHECK(osc_rt_args_ok(f, good, 3, RN) == 0, "shared argument check refused a live matching reference");
+    for (unsigned i = 0; i < 5; i++)
+        CHECK(osc_rt_args_ok(f, bad[i], 3, RN) == -1, "shared argument check accepted %s", why[i]);
+    CHECK(osc_rt_args_ok(f, good, 3, NULL) == -1, "shared argument check accepted a NULL runtime");
+
+    OscCode code;
+    OscNative nm;
+    char err[160];
+    memset(&code, 0, sizeof code);
+    CHECK(osc_cg_compile(u, &code, err, sizeof err) == 0, "native-arg codegen refused: %s", err);
+    if (osc_native_map(&nm, code.code, code.len) == 0) {
+        uint64_t ret = 77;
+        CHECK(osc_native_call(u, 0, &nm, code.entry[0], RN, good, 3, &ret) == 0 && ret == 42,
+              "checked native call refused valid arguments (ret %llu)", (unsigned long long)ret);
+        for (unsigned i = 0; i < 5; i++) {
+            ret = 77;
+            CHECK(osc_native_call(u, 0, &nm, code.entry[0], RN, bad[i], 3, &ret) == -1 && ret == 77,
+                  "checked native call entered with %s", why[i]);
+        }
+        ret = 77;
+        CHECK(osc_native_call(u, 0, &nm, code.entry[0], NULL, good, 3, &ret) == -1 && ret == 77,
+              "checked native call entered with a NULL runtime");
+        osc_native_unmap(&nm);
+    }
+    osc_cg_free(&code);
+    osc_rt_release(RN, live, 2);
+    osc_rt_release(RN, wrong_len, 3);
+}
+
 int main(int argc, char **argv)
 {
     unsigned fuzz = argc > 1 ? (unsigned)strtoul(argv[1], NULL, 10) : 1000;
@@ -2172,6 +2229,7 @@ int main(int argc, char **argv)
         for (int i = 0; i < ns; i++) free(sv[i]);
         free(sv);
     }
+    native_arg_checks();
 
     const char *const *tn = trap_names;
     printf("trap coverage (runs, interpreter == native):\n");