Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/patches/a9739db9cba226a7 # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers ## gates: chip steps build against physics.lock; pin physics `aecb9d35` (M19, #523) merged `a9739db9cba226a7` #579 · opened 2026-10-19 14:46 UTC · closed 2026-10-31 04:29 UTC · merged 2026-10-31 04:29 UTC Imported from GitHub aien-dev/omega-mv#579, by drakestapleton Base `ef56718725e2ad98547a42ecfef80985a11fa4e2` · Head `1f7b6ae2dc1aec7484bae422a41c588fd675cc4b` Merged on GitHub as `0243e4aff88937b4e616d8e211d47084aca2befe`; reachable from main `c7acd2607139eedfabeac16b6042cefe8ede431f` (observed 2026-11-18T16:35:54Z) drakestapleton wrote on 2026-10-19 14:46 UTC Qualification 2026-10-31 (PrReady/Chip579), head `1f7b6ae2dc1aec7484bae422a41c588fd675cc4b` What this PR still adds over main `ef5671872`: the physics pin is superseded because main's physics.lock `048e5f5` descends from `aecb9d35`. The remaining diff is 7 files: src/omega_clean_clone.{c,h} (new), src/omega_blackwell_gates.c (M18 gate 16 in a private mkdtemp folder, with no shell and OUT_DIR unset), src/omega_world_gates.c (m19_git_head without popen; checkout removed after gate 16), Makefile (adds the object; it stays out of libomega_gpu.a), and crumbs. The PR does not touch tests/gates/, .aien/, .github/workflows/, .forgejo/ or tools/aien-test/. Resync: I merged origin/main `4376c211`, then `6d7b8838` (C6 #984), then `613765d2` (r5 #985), then `ef5671872` (#986, #946, #988). The only conflicts were in .crumb files: I took main's side and ran crumb compile. crumb verify reports OK, 184 crumbs. Chip value gates (MEASURED), tree `785c8bde`, shared window 20261031T023123Z-a8f420, ledger L882, logs /tmp/prfix/Chip579-logs/chip-*.log. Every step returned rc=0: composition-gate-gpu, m17, chip:test-m19, chip:test-m5, prod-hygiene-silicon, r12-silicon, r13-silicon, r13-testbuild-silicon, r14-silicon, r16-authpath-silicon. The test-m19 log shows OMEGA_ACCEL_RESIDENT_CLEAN_CLONE_PASS and OMEGA_BW_MATMUL_CLEAN_CLONE_PASS (M18 gate 16, the new no-shell path). After the run, the private folder /tmp/omega_clean_m18_quyKca held only clean_clone_m18.log, so the checkout removal worked. r15-parity-silicon returned rc=2: in pair 3 of 5, RES-1 never confirmed the incumbent cost. I reran it alone in window 20261031T025451Z-0d66e7 and it returned rc=0 (5 pairs, 0 failures). This PR does not touch r15 code. Host gates (MEASURED), tree `5a8bb29a` (main `613765d2` plus this PR): 53 of the 54 steps the plan selected returned rc=0, including crumb-verify, compiler, sm121dis, runtime, faculty-arm and the 7 spark:*-host steps. rx-host-reference returned rc=2 because of a stopwatch check (rx_action_graph speedup 1.76 < 2). A rerun on the same head returned rc=0. The control run on main `ef5671872` under the same load failed a different stopwatch check (rx_workflow_fusion 2943 -> 3142 us). Both failures come from machine load, not from this change. From `5a8bb29a` to `1f7b6ae2` the only additions are main's own commits #986, #946 and #988. This PR's diff against main is unchanged (7 files). NOT_RUN: OMEGA-NUMERIC-TRANSC-FULL (plan marks it OPERATOR_STEP_PENDING). Timing verdicts: the windows were shared while Flint ran overnight, and timing needs an exclusive window. Scope after merging main at `62d1d0d66` (head `6541322389cd93c4f7d80114720d613a7c130de0`): the physics-pin part of this PR is no longer in its diff. main already builds chip/spark steps at physics.lock (`72e99878b`), and physics.lock on main is `048e5f5`, which descends from `aecb9d35` and `6d7cf0d4`. The rx-host-reference/faculty-arm pins are carried by #566. The r11 own-hold test change also dropped out, in favour of main's `3591ef088`. M19 gate 16 and gate 18 now use main's #781/`603c9ab15` code. What remains in the diff: M18 gate 16 runs in a private mkdtemp folder with no shell and with OUT_DIR unset; src/omega_clean_clone.{c,h}; m19_git_head no longer uses popen; and the built clean-clone checkout is removed after M18/M19 gate 16 while the log is kept. Chip gates (M18/M19 on the GB10) are NOT_RUN for this head. The omega M19 chip gate never got the physics memory fix. This makes the chip steps build against `physics.lock` and moves the lock to physics main with physics#64. Stacked on #565 (its first commits are #565's; after #565 merges this branch is rebased so only its own two commits remain). ## What changes - `tests/gates/run.sh`: the `chip:*|spark:*`, `rx-host-reference` and `faculty-arm` steps take physics from `physics.lock` (`physics_pin`) instead of a hard-coded `6d7cf0d`. A hard-coded copy drifted twice (#508, #523). - `physics.lock`: `6d7cf0d4` -> `aecb9d35` (physics main with physics#64, the bounded RM_ALLOC retry on NV_ERR_NO_MEMORY, the #523 error). - `tests/gates/omega-rx-host-reference.gate`: comment only. - Crumbs recompiled with the pinned tool (`d0f0b95d`), last commit. ## Evidence (gates-fix agent, Spark, handoff `~/handoffs/2026-10-19-gates-fix.md` section 6) - `omega-m19-green-try.log`: OMEGA-M19 PASS on the GB10, 16 suites with 0 failures, clean-clone PASS, on this tree (`5c143c5e` = tree of `5be22e57`). First M19 pass on record. - Control, #565 alone (old physics): also PASS (`omega-m19-control-565-only.log`). - COMPOSITION-GATE-GPU PASS on this branch; faculty-arm PASS. - Limit: during both chip runs the chip had plenty of large free memory blocks, so the #523 "no memory" condition did not happen. These runs show the gate is green with the retry wired in; they do not prove the retry itself. - rx-host-reference has two stopwatch checks that fail on a busy machine with or without this change (identical test binaries in both builds). Not changed here. Pipeline configuration change (tests/gates): judged by an operator run on the Spark. Refs #523. Overlaps #566 (same physics_pin change for run.sh); #566 is rebased onto this after it lands. This PR was opened by the Hermes PR desk on Drake's behalf. drakestapleton wrote on 2026-10-24 06:40 UTC #565 at `68a3a6145fc6ae1771adab88b8292af785a10bb1` is closed as work transferred here. It is an ancestor of this head `5be22e571a9744b1f47a767bbdd92949e4150dc4`, with all six changed nonmetadata files byte-identical. Preserve the carried #530/#529 hold-test and clean-clone behavior. #566 remains open: its 19 gate inputs and discriminating selftest are distinct scope, not a redundant pin bump. The desk has consolidated tracking before aggregate merge. This does not mark the transferred work complete, qualified, deployed, or merged. All original acceptance requirements remain attached to this successor. Current queue: aien-dev/aien-architecture-mv#190. ### Fetch it A git bundle of the pull request's head, 49536 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/a9739db9cba226a7.bundle -o a9739db9cba226a7.bundle git fetch a9739db9cba226a7.bundle refs/pull/579/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-mv 579 1f7b6ae2dc1aec7484bae422a41c588fd675cc4b ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":579,"url":"https://github.com/aien-dev/omega-mv/pull/579","export_sha256":"7319147b350ad908bf0b731068ec3be7b8dee848041dc862f71455e8e4680140","imported_utc":"2026-11-18T16:35:54Z"} ``` ### Changes ``` diff --git a/.crumb b/.crumb index 963d04c04..3204fd9ca 100644 --- a/.crumb +++ b/.crumb @@ -48,7 +48,7 @@ }, { "digest": "97cea09c64062a83e88ed0ef689bad3f86216860886800a9aaa96d1525dc561b", - "last_commit": "7fd7e5f7f", + "last_commit": "613765d2b", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -60,19 +60,19 @@ }, { "digest": "c0668c8969cceab0f03ac6ab352ae579c8b473a9ec743d80c89fc187b769c12c", - "last_commit": "22011cbc9", + "last_commit": "6d7b88384", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, { "digest": "968629f559041774f86d45d87d153c0094ee23b46a67d63959de9c5d2fd7cd0a", - "last_commit": "06bd19321", + "last_commit": "f5c9bd89a", "name": "native", "purpose": "Handwritten .om units of omega-mv that are not part of the seed ladder: the ORIG-4 shadow adviso" }, { "digest": "1973c1d57f6cf961b5c11cd84b0ceebd3bbe5250a7abd40e05988a138e248185", - "last_commit": "06bd19321", + "last_commit": "f56a372ae", "name": "neuralese", "purpose": "Bounded untrusted representation envelopes and explicit checked Omega decoding; learned extensio" }, @@ -89,33 +89,33 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "569046def53c95f65e57dc6ecac3ff2523bf2fe744c802cca7c87ef830d40959", - "last_commit": "7fd7e5f7f", + "digest": "cd8f78e6b6ca22288d7f77a7e6438a1f085c5fbf5ad7cc3bf0254627d2e71015", + "last_commit": "5a8bb29a2", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { "digest": "4e7251847298392c2e24591e45747e2b214c48f66a636063fbd7b3ab32a55a6d", - "last_commit": "a370a673e", + "last_commit": "6d7b88384", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "c9c0eb6fcb03f5be2576714a9b49e2ead49190277059fcbbd253f49db07c047d", - "last_commit": "22011cbc9", + "last_commit": "6d7b88384", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:88f9771eefaeb5a65216b322005fd9e086c35684cbd1406e686aac7e40fa0554", - "compiled_at": "2026-10-31T03:41:21Z", + "children_root": "sha256:1d1aa55dc6d8ef9da740009a2b96f7b386eefe27999cebe9b3a364489b06df4d", + "compiled_at": "2026-10-31T04:21:57Z", "compiler": "crumb-compile/1", - "digest": "sha256:6a59ebafaab0f2358a6320117048cc918847664388ae82e85cbc41ac36674fe8", + "digest": "sha256:fdd2cb63a9d37b205328cfc066ab949415a91adf03c7194c2bfe7be8a4de7dd2", "evidence_files": 14606, "evidence_root": "sha256:28233834368ddb7bbc564ab04c645c15958342765d5d3455dec54131f161a4f8", - "files": 22758, - "generated_at_commit": "b2ed08a39b5b40c747d50b05a0803a5bbd624549", - "source_tree": "sha256:ba7879ebb5253c97f157a06d4e8d25fd88f9ff2b9ea71bbc5edf95c70aaf02b4" + "files": 22760, + "generated_at_commit": "5a8bb29a2c1be2c004377e386dcc4000c24b938d", + "source_tree": "sha256:e198912b14f03eed4290e2ecd19fcab8e6034edf3fea9e808ab6ee33986c74e4" }, "owner_lane": "", "provenance": { diff --git a/Makefile b/Makefile index bf39ac9c7..6011dfa5d 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ SRCS = src/omega_om_units.c src/omega_canonical.c src/omega_validate.c src/omega src/omega_matvec.c src/omega_accelerator.c src/omega_accelerator_world.c \ src/omega_vector.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ src/omega_blackwell_realize.c src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c src/omega_blackwell_gates.c src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_gpu_session.c src/omega_gpu_platform.c src/omega_gpu_platform_linux.c src/omega_gpu_fmt.c src/omega_gpu_matmul_api.c src/omega_gpu_elementwise_api.c src/omega_gpu_attention_api.c src/omega_gpu_serving.c src/omega_world_gates.c src/omega_gpu_wait.c \ - src/omega_evidence.c \ + src/omega_evidence.c src/omega_clean_clone.c \ $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c \ tools/omegatool.c # OWN-30B cut 2 (2026-10-13): column windows over a resident bf16 tensor for the MoE path. New file, @@ -2509,7 +2509,7 @@ test-vc-bridge: tests/test_omega_vc_bridge.c src/omega_vc_bridge.c src/omega_vc_ # they compile the physics checkout path into the object (-DOMEGA_PHYSICS_DIR), which made the # archive digest depend on where physics was checked out. Without them libomega_gpu.a is # byte-identical for any PHYSICS_DIR and any omega checkout directory. -GPU_API_OBJS = $(filter-out $(OUT_DIR)/omegatool.o $(OUT_DIR)/omega_blackwell_gates.o $(OUT_DIR)/omega_world_gates.o,$(OBJS)) +GPU_API_OBJS = $(filter-out $(OUT_DIR)/omegatool.o $(OUT_DIR)/omega_blackwell_gates.o $(OUT_DIR)/omega_world_gates.o $(OUT_DIR)/omega_clean_clone.o,$(OBJS)) GPU_API_TEST = $(OUT_DIR)/gpu_matmul_api_test GPU_R4_RECEIPT = $(OUT_DIR)/gpu_matmul_r4_receipt $(OUT_DIR)/libomega_gpu.a: $(GPU_API_OBJS) | check-physics-lock diff --git a/src/.crumb b/src/.crumb index 125a8d6cb..acf215898 100644 --- a/src/.crumb +++ b/src/.crumb @@ -188,14 +188,14 @@ } ], "children_root": "sha256:6ade3e583c9df260fbfc768469dae662b88153725b14f7086431861419cfffe3", - "compiled_at": "2026-10-31T02:49:10Z", + "compiled_at": "2026-10-31T04:21:57Z", "compiler": "crumb-compile/1", - "digest": "sha256:569046def53c95f65e57dc6ecac3ff2523bf2fe744c802cca7c87ef830d40959", + "digest": "sha256:cd8f78e6b6ca22288d7f77a7e6438a1f085c5fbf5ad7cc3bf0254627d2e71015", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 597, - "generated_at_commit": "7fd7e5f7f3e02a24887d47223185a6fd3ed36243", - "source_tree": "sha256:68e317af63aa90a09d3bfdc9fae3117f47ffd698001af2c20e4d985aff1aefd7" + "files": 599, + "generated_at_commit": "5a8bb29a2c1be2c004377e386dcc4000c24b938d", + "source_tree": "sha256:c9d14042ce2222dc91ad4fbf3e21b9f67a28e04acd826b489827ec1dae2a4334" }, "owner_lane": "", "provenance": { diff --git a/src/omega_blackwell_gates.c b/src/omega_blackwell_gates.c index 54ec7f769..3c248417e 100644 --- a/src/omega_blackwell_gates.c +++ b/src/omega_blackwell_gates.c @@ -33,7 +33,10 @@ #include #include #include +#include #include "omega_physics_dir.h" +#include "omega_clean_clone.h" +#include static int m17_gate_count = 0; static int m17_gate_passed = 0; @@ -991,31 +994,89 @@ fail: return false; } +/* Remove the built copy a clean-clone gate made under its private folder; the + * log beside it stays for the reader. Hundreds of MB per run otherwise pile up + * in /tmp (omega#526). */ +static void m18_clean_clone_remove_checkout(const char *clone) { + char checkout[PATH_MAX]; + int n = snprintf(checkout, sizeof(checkout), "%s/checkout", clone); + if (n < 0 || (size_t)n >= sizeof(checkout)) return; + /* No shell: a file-tree walk that never follows a symlink (omega#565). */ + if (omega_cc_remove_tree(checkout) != 0) { + fprintf(stderr, "M18 clean clone: could not remove %s\n", checkout); + } +} + static bool test_m18_gate16_clean_clone(void) { if (getenv("OMEGA_IN_CLEAN_CLONE") != NULL) { return true; } /* Copy the repo this omegatool runs from (the code under test), not a * hardcoded checkout, and pass the PHYSICS_DIR this process resolves at run time - * (omega_physics_dir.h) as an absolute path so the copy in /tmp does not fall back to - * the Makefile default ../physics (= /tmp/physics). Mirrors M19. */ + * (omega_physics_dir.h) as an absolute path so the copy does not fall back to + * the Makefile default ../physics. Mirrors M19. + * + * The copy and its log live in a private mkdtemp folder (omega#526). A fixed + * /tmp path is shared by every user of the machine, and the sticky /tmp lets + * neither the judge user nor the operator remove or overwrite what the other + * left behind ("rm: Permission denied", "cannot create ...log: Permission denied"), + * so the gate failed for whoever ran second. + * + * OUT_DIR is unset for the nested build: tests/gates/run.sh exports a per-step + * OUT_DIR (omega#511), so `make` in the copy would put the binary at + * $OUT_DIR/omegatool and "./build/omegatool" would not exist (sh exit 127 in + * the judge run of e466b138, omega#526). The copy is private, so it needs no + * per-step build directory. */ char physics_dir_resolved[PATH_MAX], physics_err[OMEGA_PHYSICS_ERR_SIZE]; if (!omega_physics_dir_resolve_pinned(physics_dir_resolved, sizeof(physics_dir_resolved), 0, physics_err, sizeof(physics_err))) { fprintf(stderr, "%s\n", physics_err); return false; } - char command[4608]; - int len = snprintf(command, sizeof(command), - "root=$(git rev-parse --show-toplevel) && " - "rm -rf /tmp/omega_clean_m18 && " - "cp -r \"$root\" /tmp/omega_clean_m18 && " - "cd /tmp/omega_clean_m18 && " - "make OUT_DIR=build clean >/dev/null 2>&1 && " - "make -j OUT_DIR=build PHYSICS_DIR='%s' >/dev/null 2>&1 && " - "OMEGA_IN_CLEAN_CLONE=1 ./build/omegatool --run-m18-gates >/tmp/clean_clone_m18.log 2>&1", - physics_dir_resolved); - if (len < 0 || (size_t)len >= sizeof(command)) return false; - int rc = system(command); + const char *tmp = getenv("TMPDIR"); + if (!tmp || !*tmp) tmp = "/tmp"; + char clone[PATH_MAX]; + int cl = snprintf(clone, sizeof(clone), "%s/omega_clean_m18_XXXXXX", tmp); + if (cl < 0 || (size_t)cl >= sizeof(clone)) return false; + if (!mkdtemp(clone)) { + fprintf(stderr, "M18 clean clone: mkdtemp %s: %s\n", clone, strerror(errno)); + return false; + } + /* No shell (omega#565): each step is its own program with an argument vector, + * so nothing in TMPDIR or PHYSICS_DIR can change what runs. Paths outside the + * plain charset are refused (fail closed); make would also expand a '$'. */ + if (!omega_cc_path_is_plain(clone) || !omega_cc_path_is_plain(physics_dir_resolved)) { + fprintf(stderr, "M18 clean clone: refusing a path with characters outside [A-Za-z0-9/._+-]: %s | %s\n", + clone, physics_dir_resolved); + (void)rmdir(clone); + return false; + } + char root[PATH_MAX], checkout[PATH_MAX], log_path[PATH_MAX], physics_arg[PATH_MAX + 16]; + char *git_top[] = {"git", "rev-parse", "--show-toplevel", NULL}; + if (!omega_cc_capture_line(NULL, "git", git_top, root, sizeof(root))) { + fprintf(stderr, "M18 clean clone: git rev-parse --show-toplevel failed\n"); + (void)rmdir(clone); + return false; + } + int n1 = snprintf(checkout, sizeof(checkout), "%s/checkout", clone); + int n2 = snprintf(log_path, sizeof(log_path), "%s/clean_clone_m18.log", clone); + int n3 = snprintf(physics_arg, sizeof(physics_arg), "PHYSICS_DIR=%s", physics_dir_resolved); + if (n1 < 0 || (size_t)n1 >= sizeof(checkout) || n2 < 0 || (size_t)n2 >= sizeof(log_path) || + n3 < 0 || (size_t)n3 >= sizeof(physics_arg)) { + (void)rmdir(clone); + return false; + } + char *cp_argv[] = {"cp", "-r", "--", root, checkout, NULL}; + char *clean_argv[] = {"make", "clean", NULL}; + char *make_argv[] = {"make", "-j", physics_arg, NULL}; + char *run_argv[] = {"./build/omegatool", "--run-m18-gates", NULL}; + const char *step = "cp"; + int rc = omega_cc_run(NULL, "cp", cp_argv, NULL, false); + if (rc == 0) { step = "make clean"; rc = omega_cc_run(checkout, "make", clean_argv, NULL, false); } + if (rc == 0) { step = "make"; rc = omega_cc_run(checkout, "make", make_argv, NULL, false); } + /* The log sits beside the checkout: /clean_clone_m18.log. */ + if (rc == 0) { step = "omegatool --run-m18-gates"; rc = omega_cc_run(checkout, "./build/omegatool", run_argv, "../clean_clone_m18.log", true); } + if (rc != 0) fprintf(stderr, "M18 clean clone failed at %s (rc %d); log: %s\n", step, rc, log_path); + m18_clean_clone_remove_checkout(clone); return (rc == 0); } diff --git a/src/omega_clean_clone.c b/src/omega_clean_clone.c new file mode 100644 index 000000000..db83e4d17 --- /dev/null +++ b/src/omega_clean_clone.c @@ -0,0 +1,133 @@ +#include "omega_clean_clone.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool omega_cc_path_is_plain(const char *s) { + if (!s || !*s) return false; + for (const char *p = s; *p; p++) { + char c = *p; + bool ok = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || + c == '/' || c == '.' || c == '_' || c == '+' || c == '-'; + if (!ok) return false; + } + return true; +} + +/* Child side: environment, directory, output, then exec. Never returns. */ +static void cc_child(const char *dir, const char *prog, char *const argv[], const char *out_rel, bool in_clean_clone) { + if (unsetenv("OUT_DIR") != 0) _exit(127); + if (in_clean_clone && setenv("OMEGA_IN_CLEAN_CLONE", "1", 1) != 0) _exit(127); + if (dir && chdir(dir) != 0) _exit(127); + /* Opened after chdir: the name is fixed by the caller, never built from a path. */ + int out_fd = out_rel ? open(out_rel, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, 0644) + : open("/dev/null", O_WRONLY | O_CLOEXEC); + if (out_fd < 0) _exit(126); + if (dup2(out_fd, STDOUT_FILENO) < 0) _exit(127); + if (dup2(out_fd, STDERR_FILENO) < 0) _exit(127); + if (out_fd != STDOUT_FILENO && out_fd != STDERR_FILENO) close(out_fd); + execvp(prog, argv); + _exit(127); +} + +static int cc_wait(pid_t pid) { + int status = 0; + while (waitpid(pid, &status, 0) < 0) { + if (errno != EINTR) return -1; + } + if (WIFEXITED(status)) return WEXITSTATUS(status); + if (WIFSIGNALED(status)) return 128 + WTERMSIG(status); + return -1; +} + +int omega_cc_run(const char *dir, const char *prog, char *const argv[], const char *out_rel, bool in_clean_clone) { + if (!prog || !argv || !argv[0]) return -1; + fflush(NULL); + pid_t pid = fork(); + if (pid < 0) return -1; + if (pid == 0) cc_child(dir, prog, argv, out_rel, in_clean_clone); + return cc_wait(pid); +} + +bool omega_cc_capture_line(const char *dir, const char *prog, char *const argv[], char *out, size_t out_size) { + if (!prog || !argv || !argv[0] || !out || out_size == 0) return false; + out[0] = '\0'; + int fds[2]; + if (pipe2(fds, O_CLOEXEC) != 0) return false; + int err_fd = open("/dev/null", O_WRONLY | O_CLOEXEC); + if (err_fd < 0) { + close(fds[0]); + close(fds[1]); + return false; + } + fflush(NULL); + pid_t pid = fork(); + if (pid < 0) { + close(fds[0]); + close(fds[1]); + close(err_fd); + return false; + } + if (pid == 0) { + if (dir && chdir(dir) != 0) _exit(127); + if (dup2(fds[1], STDOUT_FILENO) < 0) _exit(127); + if (dup2(err_fd, STDERR_FILENO) < 0) _exit(127); + execvp(prog, argv); + _exit(127); + } + close(fds[1]); + close(err_fd); + size_t used = 0; + bool overflow = false; + char buf[256]; + for (;;) { + ssize_t n = read(fds[0], buf, sizeof(buf)); + if (n < 0 && errno == EINTR) continue; + if (n <= 0) break; + for (ssize_t i = 0; i < n; i++) { + if (used + 1 < out_size) out[used++] = buf[i]; + else overflow = true; + } + } + close(fds[0]); + out[used] = '\0'; + int rc = cc_wait(pid); + char *nl = strpbrk(out, "\r\n"); + if (nl) *nl = '\0'; + else if (overflow) return false; + return rc == 0 && out[0] != '\0'; +} + +static int cc_remove_entry(const char *path, const struct stat *sb, int type, struct FTW *ftw) { + (void)sb; + (void)ftw; + int rc = (type == FTW_DP) ? rmdir(path) : unlink(path); + if (rc != 0 && errno != ENOENT) { + fprintf(stderr, "clean clone: cannot remove %s: %s\n", path, strerror(errno)); + return -1; + } + return 0; +} + +int omega_cc_remove_tree(const char *path) { + if (!omega_cc_path_is_plain(path) || path[0] != '/' || strcmp(path, "/") == 0) { + fprintf(stderr, "clean clone: refusing to remove '%s' (not a plain absolute path)\n", + path ? path : "(null)"); + return -1; + } + struct stat st; + if (lstat(path, &st) != 0) return (errno == ENOENT) ? 0 : -1; + /* FTW_DEPTH: children before their directory. FTW_PHYS: never follow a symlink, + * so a link inside the copy cannot reach outside it. FTW_MOUNT: stay on one + * file system. */ + return nftw(path, cc_remove_entry, 32, FTW_DEPTH | FTW_PHYS | FTW_MOUNT) == 0 ? 0 : -1; +} diff --git a/src/omega_clean_clone.h b/src/omega_clean_clone.h new file mode 100644 index 000000000..b829f483b --- /dev/null +++ b/src/omega_clean_clone.h @@ -0,0 +1,42 @@ +#ifndef OMEGA_CLEAN_CLONE_H +#define OMEGA_CLEAN_CLONE_H + +#include +#include + +/* Process and file helpers for the M18 and M19 clean-clone gates (omega#526, #565). + * + * No shell anywhere: every child program is started with fork + execvp and an + * argument vector, and trees are removed with nftw + unlink/rmdir. A path is + * never pasted into a command string, so a quote or shell metacharacter in + * TMPDIR, PHYSICS_DIR or a clone path cannot change what runs. + * + * Fail closed: a path outside the plain charset (letters, digits, / . _ + -) + * is refused before anything runs, because it is also handed to make as + * PHYSICS_DIR= and make expands '$' in variable values. */ + +/* True when every byte of s is in [A-Za-z0-9/._+-] and s is non-empty. */ +bool omega_cc_path_is_plain(const char *s); + +/* Run prog (looked up on PATH; callers pass a string literal) with argv in + * directory dir (NULL: the current directory). stdout and stderr go to out_rel, + * a path opened by the child AFTER it changes to dir, so callers pass a fixed + * relative name such as "../qualification.log"; NULL means /dev/null. + * OUT_DIR is removed from the child environment; when in_clean_clone is true + * the child also gets OMEGA_IN_CLEAN_CLONE=1. + * Returns the child's exit code (126: output file could not be opened, 127: + * program could not be started), 128 + signal if it was killed, or -1 if the + * child could not be created. */ +int omega_cc_run(const char *dir, const char *prog, char *const argv[], const char *out_rel, bool in_clean_clone); + +/* Run prog with argv in dir and capture the first line of its stdout (newline + * stripped) into out. stderr goes to /dev/null. Returns true only when the + * program exits 0 and printed a line that fit. */ +bool omega_cc_capture_line(const char *dir, const char *prog, char *const argv[], char *out, size_t out_size); + +/* Remove path and everything under it without following symlinks. + * Refuses an empty path, "/", a relative path, or a path outside the plain + * charset. Returns 0 when the tree is gone (or was never there), -1 otherwise. */ +int omega_cc_remove_tree(const char *path); + +#endif diff --git a/src/omega_world_gates.c b/src/omega_world_gates.c index b78806dad..19779c7e4 100644 --- a/src/omega_world_gates.c +++ b/src/omega_world_gates.c @@ -36,6 +36,7 @@ #include #include #include "omega_physics_dir.h" +#include "omega_clean_clone.h" static int m19_gate_count = 0; static int m19_gate_passed = 0; @@ -56,17 +57,13 @@ static bool m19_fault_zero_device_reset = false; /* Resolve the full 40-hex revision of a working tree via git. */ static bool m19_git_head(const char *repo_dir, char out[41]) { - char cmd[512]; - int n = snprintf(cmd, sizeof(cmd), "git -C %s rev-parse HEAD 2>/dev/null", repo_dir); - if (n < 0 || (size_t)n >= sizeof(cmd)) return false; - FILE *p = popen(cmd, "r"); - if (!p) return false; - char *got = fgets(out, 41, p); - pclose(p); - if (!got) return false; - size_t len = strlen(out); - while (len > 0 && (out[len - 1] == '\n' || out[len - 1] == '\r')) out[--len] = '\0'; - return (len == 40); + /* No shell (omega#565): git gets the directory as an argument. */ + char line[64]; + char *argv[] = {"git", "-C", (char *)repo_dir, "rev-parse", "HEAD", NULL}; + if (!omega_cc_capture_line(NULL, "git", argv, line, sizeof(line))) return false; + if (strlen(line) != 40) return false; + memcpy(out, line, 41); + return true; } static const uint32_t WORLD_SETUP_WORDS[18] = { @@ -1830,6 +1827,15 @@ static void m19_echo_log_tail(const char *dir) { if (buf[got - 1] != '\n') fputc('\n', stderr); } +/* Remove the built copy under the private clone folder; qualification.log stays + * beside it (omega#526: five such copies per day filled /tmp). */ +static void m19_clean_clone_remove_checkout(const char *checkout) { + /* No shell: a file-tree walk that never follows a symlink (omega#565). */ + if (omega_cc_remove_tree(checkout) != 0) { + fprintf(stderr, "M19 clean clone: could not remove %s\n", checkout); + } +} + /* Gate 16: OMEGA_ACCEL_RESIDENT_CLEAN_CLONE_PASS */ static bool test_m19_gate16_clean_clone(void) { char src_sha[41] = {0}; @@ -1898,13 +1904,15 @@ static bool test_m19_gate16_clean_clone(void) { * Echo the tail to stderr, which the gate runner captures into the evidence record. */ fprintf(stderr, "M19 gate 16: nested build or nested run failed; tail of %s:\n", log_path); m19_echo_log_tail(clone); + m19_clean_clone_remove_checkout(checkout); return false; } /* The built checkout must be exactly the named candidate revision. */ char clone_sha[41] = {0}; - if (!m19_git_head(checkout, clone_sha)) return false; - if (strcmp(clone_sha, src_sha) != 0) return false; + bool same = m19_git_head(checkout, clone_sha) && strcmp(clone_sha, src_sha) == 0; + m19_clean_clone_remove_checkout(checkout); + if (!same) return false; memcpy(m19_candidate_commit, src_sha, sizeof(m19_candidate_commit)); return true; ```