Kill sites in martha tests and probes outside #195 can reach the runner's own group or session (kill(0), kill(-1), a cwd scan of everything) #205

Closed
opened 2026-11-25 20:50:53 +00:00 by uranus · 2 comments
Member

Purpose (defect): every kill in martha's tests and probes reaches only the processes its own code started. None can become kill(0) (the runner's own group), kill(-1) (every process of the user), a kill of the test's own session, or a /proc scan that matches every process.

Found in the read-only kill-scope sweep of main 37fb64bb asked for on #195 (after tonight's two crew-wide SIGKILLs). Refs #195. These sites are outside #195's code, so they get their own issue. What is inside #195's area is posted there.

These come from reading the code. Nothing was run, so each "how it fires" below is a reading, not a reproduction.

Reachable today (a race or a failed spawn)

  1. src/probe_launch_hosts/stop_a_host_that_outlives_the_run.ts:94-125,146: stopTheProcessesLeftIn(scratch) has the same shape as tonight's bug, and it is exported. With "", realpathSync throws, so wanted = {''} and cwd.startsWith('/') matches every process of the user. With /, it matches every process whose cwd is /. A relative path matches everything working under the caller's cwd. Today's callers pass a realpath'd mkdtemp, so it is not firing now. Fix: refuse unless isAbsolute(scratch), realpathSync succeeds, and the path is not /, tmpdir() or homedir(). Drop the unresolved fallback in resolved().
  2. src/end_a_launch_when_its_run_ends/a_run_on_a_pty_ends_whole.node-test.ts:46-47,42: the poll sees stray as soon as the file exists, but the shell's echo $! > file creates the file before it writes to it. An empty read gives Number('') === 0. Line 48 then throws, and t.after runs process.kill(0, 'SIGKILL'), which kills the test runner's whole process group. Fix: wait until the file matches /^\d+$/, and kill only when pid > 1.
  3. installer/prove_a_clean_install/prove_a_clean_install.node-test.mjs:769-776: session = sessionOf(child of script) can be read between script's fork and the child's setsid(). It then holds the test's own session, and nothing compares it with sessionOf(process.pid). The comment at :765-766 names this exact harm. t.after then SIGKILLs every process in the test's session. Fix: accept a session only when it is > 0 and !== sessionOf(process.pid), and keep polling otherwise.
  4. installer/prove_a_clean_install/prove_a_clean_install.node-test.mjs:669-672,664: session is assigned before the assert that it is not the test's own session. When that assert fails, the after-hook kills the test's own session, which is the very case the assert reports. Fix: assert on a local first, then assign session.
  5. prove_the_core/a_test_run_keeps_one_temporary_root/keep_a_test_run_in_one_temporary_root.node-test.ts:187 (-(group ?? 0)) and :290,293 (child.pid ?? 0): a spawn that returns no pid (EAGAIN, EMFILE, a pid limit on a loaded box) turns these into process.kill(-0), that is kill(0, SIGKILL) on the test's own group. Fix: assert.ok(child.pid !== undefined) before registering the hook, as every_test_run_ends.node-test.ts:122 does, and drop the ?? 0.
  6. src/probe_launch_hosts/stop_a_host_that_outlives_the_run.node-test.ts:80: process.kill(-(left.pid ?? 0)) is the same ?? 0 shape, reached when setsid fails to spawn. Fix: as in 5.
  7. trial_the_goose_host/drive_the_trial_with_a_stand_in_engine.node-test.ts:579: Number(readFileSync(survivor.pid)) is a non-atomic write (:493, inside try {} catch {}). An empty file gives kill(0). The chance is low. Fix: signal only when Number.isInteger(pid) && pid > 1.

No floor in a shared helper (nothing bad reaches it today)

  1. src/end_a_launch_when_its_run_ends/the_run_lifeline.ts:163-165: killGroup(group) runs process.kill(-group) with no floor, so killGroup(0) kills the caller's group and killGroup(1) is kill(-1). The one soft caller is launch_a_goose_member.node-test.ts:770-771, which passes Number(pid) from a child's printed line. Fix: make the first line if (!Number.isSafeInteger(group) || group <= 1) throw.
  2. src/linux_process_identity/files_and_processes_on_this_machine.ts:143-146: signalAGroupOnThisMachine refuses pid ≤ 0 through identityOf, but lets pid 1 through, which gives kill(-1). Fix: pid <= 1 → refusal.
  3. src/probe_launch_hosts/stop_a_host_that_outlives_the_run.ts:45: theGroupIn accepts > 0, so a pid file holding 1 gives kill(-1). Fix: > 1, and remove pid_file before each runTheHost.
  4. prove_the_core/a_test_leaves_nothing_behind/a_launcher_ends_with_its_run.ts:96,106: cmdline.includes(home) is true for '', which lets a stale noted pid through. That is one SIGTERM. Fix: require isAbsolute(home).

martha-engine

I read its test and proof code: crates/goose/tests, state_machine/tests, scripts/test_*.sh, martha/sync/, ui/*/test*. No reachable wide kill there. drive_the_trial.ts:288-296 guards pid === 0 and spawns detached. The Rust tests kill pids they spawned themselves.

Done when

  • Items 1-7 are each fixed, and each fix has a test that turns red when the fix is mutated away. Those tests never signal outside a pid namespace: run them under unshare --user --map-root-user --pid --fork --mount-proc.
  • Items 8-11 are fixed or ruled out here by name.
  • No new check (B11).
Purpose (defect): every kill in martha's tests and probes reaches only the processes its own code started. None can become `kill(0)` (the runner's own group), `kill(-1)` (every process of the user), a kill of the test's own session, or a `/proc` scan that matches every process. Found in the read-only kill-scope sweep of main 37fb64bb asked for on #195 (after tonight's two crew-wide SIGKILLs). Refs #195. These sites are outside #195's code, so they get their own issue. What is inside #195's area is posted there. These come from reading the code. Nothing was run, so each "how it fires" below is a reading, not a reproduction. ## Reachable today (a race or a failed spawn) 1. `src/probe_launch_hosts/stop_a_host_that_outlives_the_run.ts:94-125,146`: `stopTheProcessesLeftIn(scratch)` has the same shape as tonight's bug, and it is exported. With `""`, `realpathSync` throws, so `wanted = {''}` and `cwd.startsWith('/')` matches every process of the user. With `/`, it matches every process whose cwd is `/`. A relative path matches everything working under the caller's cwd. Today's callers pass a realpath'd mkdtemp, so it is not firing now. Fix: refuse unless `isAbsolute(scratch)`, `realpathSync` succeeds, and the path is not `/`, `tmpdir()` or `homedir()`. Drop the unresolved fallback in `resolved()`. 2. `src/end_a_launch_when_its_run_ends/a_run_on_a_pty_ends_whole.node-test.ts:46-47,42`: the poll sees `stray` as soon as the file exists, but the shell's `echo $! > file` creates the file before it writes to it. An empty read gives `Number('') === 0`. Line 48 then throws, and `t.after` runs `process.kill(0, 'SIGKILL')`, which kills the test runner's whole process group. Fix: wait until the file matches `/^\d+$/`, and kill only when `pid > 1`. 3. `installer/prove_a_clean_install/prove_a_clean_install.node-test.mjs:769-776`: `session = sessionOf(child of script)` can be read between `script`'s fork and the child's `setsid()`. It then holds the test's own session, and nothing compares it with `sessionOf(process.pid)`. The comment at :765-766 names this exact harm. `t.after` then SIGKILLs every process in the test's session. Fix: accept a session only when it is `> 0` and `!== sessionOf(process.pid)`, and keep polling otherwise. 4. `installer/prove_a_clean_install/prove_a_clean_install.node-test.mjs:669-672,664`: `session` is assigned before the assert that it is not the test's own session. When that assert fails, the after-hook kills the test's own session, which is the very case the assert reports. Fix: assert on a local first, then assign `session`. 5. `prove_the_core/a_test_run_keeps_one_temporary_root/keep_a_test_run_in_one_temporary_root.node-test.ts:187` (`-(group ?? 0)`) and `:290,293` (`child.pid ?? 0`): a spawn that returns no pid (EAGAIN, EMFILE, a pid limit on a loaded box) turns these into `process.kill(-0)`, that is `kill(0, SIGKILL)` on the test's own group. Fix: `assert.ok(child.pid !== undefined)` before registering the hook, as `every_test_run_ends.node-test.ts:122` does, and drop the `?? 0`. 6. `src/probe_launch_hosts/stop_a_host_that_outlives_the_run.node-test.ts:80`: `process.kill(-(left.pid ?? 0))` is the same `?? 0` shape, reached when `setsid` fails to spawn. Fix: as in 5. 7. `trial_the_goose_host/drive_the_trial_with_a_stand_in_engine.node-test.ts:579`: `Number(readFileSync(survivor.pid))` is a non-atomic write (:493, inside `try {} catch {}`). An empty file gives `kill(0)`. The chance is low. Fix: signal only when `Number.isInteger(pid) && pid > 1`. ## No floor in a shared helper (nothing bad reaches it today) 8. `src/end_a_launch_when_its_run_ends/the_run_lifeline.ts:163-165`: `killGroup(group)` runs `process.kill(-group)` with no floor, so `killGroup(0)` kills the caller's group and `killGroup(1)` is `kill(-1)`. The one soft caller is `launch_a_goose_member.node-test.ts:770-771`, which passes `Number(pid)` from a child's printed line. Fix: make the first line `if (!Number.isSafeInteger(group) || group <= 1) throw`. 9. `src/linux_process_identity/files_and_processes_on_this_machine.ts:143-146`: `signalAGroupOnThisMachine` refuses pid ≤ 0 through `identityOf`, but lets pid 1 through, which gives `kill(-1)`. Fix: `pid <= 1` → refusal. 10. `src/probe_launch_hosts/stop_a_host_that_outlives_the_run.ts:45`: `theGroupIn` accepts `> 0`, so a pid file holding `1` gives `kill(-1)`. Fix: `> 1`, and remove `pid_file` before each `runTheHost`. 11. `prove_the_core/a_test_leaves_nothing_behind/a_launcher_ends_with_its_run.ts:96,106`: `cmdline.includes(home)` is true for `''`, which lets a stale noted pid through. That is one SIGTERM. Fix: require `isAbsolute(home)`. ## martha-engine I read its test and proof code: `crates/goose/tests`, `state_machine/tests`, `scripts/test_*.sh`, `martha/sync/`, `ui/*/test*`. No reachable wide kill there. `drive_the_trial.ts:288-296` guards `pid === 0` and spawns detached. The Rust tests kill pids they spawned themselves. ## Done when - Items 1-7 are each fixed, and each fix has a test that turns red when the fix is mutated away. Those tests never signal outside a pid namespace: run them under `unshare --user --map-root-user --pid --fork --mount-proc`. - Items 8-11 are fixed or ruled out here by name. - No new check (B11).
Member

Threat model (Jupiter, before code; kill-safety, per the Supervisor's placement)

What is at stake. Every process of the user that the tests run as on host00: the crew's sessions, the CI runners' jobs, a pilot's processes. Tonight's two crew-wide SIGKILLs (#195) show what one bad signal costs.

Who does harm. No outside attacker. The harm is our own test or probe code signalling a number it did not get from a child it started. The ways a number goes wrong, from the sweep above:

  • 0: an empty pid file read early (2, 7), or ?? 0 after a spawn with no pid (5, 6). This becomes kill(0) or kill(-0), the runner's own group.
  • 1: a pid file holding 1 (10), or killGroup(1) / signalAGroupOnThisMachine(1) (8, 9). This becomes kill(-1), every process of the user.
  • The test's own session, taken for the child's: read before setsid (3), or assigned before the assert (4).
  • A scan root that is "", /, relative, tmpdir() or homedir(): it matches far more than the run's scratch (1, 11).

The control. One pure rule, used at every site: a number is signalled only when it is a safe integer > 1, and never when it is this process's own pid, group or session; a folder is scanned only when it is absolute, resolves, and is none of /, tmpdir() or homedir(). Each site refuses (throws, or skips in an after-hook) instead of signalling. No fallback widens the target: the unresolved fallback in resolved() goes.

How it is proved without risk.

  • Each guard gets a test that is red when the guard is mutated away.
  • Those tests drive the guard through an injected finder and signaller that record, never signal, so a surviving mutant kills nothing.
  • No test passes "", / or a relative root to a real killer.
  • Every local run is inside unshare --user --map-root-user --pid --fork --mount-proc, in the one crew-wide slot.

Out of scope. #195's area (Pallas), #203 (Uranus), and martha-engine (read in the sweep; nothing reachable). No new check (B11).

Threat model (Jupiter, before code; kill-safety, per the Supervisor's placement) **What is at stake.** Every process of the user that the tests run as on host00: the crew's sessions, the CI runners' jobs, a pilot's processes. Tonight's two crew-wide SIGKILLs (#195) show what one bad signal costs. **Who does harm.** No outside attacker. The harm is our own test or probe code signalling a number it did not get from a child it started. The ways a number goes wrong, from the sweep above: - **0:** an empty pid file read early (2, 7), or `?? 0` after a spawn with no pid (5, 6). This becomes `kill(0)` or `kill(-0)`, the runner's own group. - **1:** a pid file holding `1` (10), or `killGroup(1)` / `signalAGroupOnThisMachine(1)` (8, 9). This becomes `kill(-1)`, every process of the user. - **The test's own session, taken for the child's:** read before `setsid` (3), or assigned before the assert (4). - **A scan root that is `""`, `/`, relative, `tmpdir()` or `homedir()`:** it matches far more than the run's scratch (1, 11). **The control.** One pure rule, used at every site: *a number is signalled only when it is a safe integer > 1, and never when it is this process's own pid, group or session; a folder is scanned only when it is absolute, resolves, and is none of `/`, `tmpdir()` or `homedir()`.* Each site refuses (throws, or skips in an after-hook) instead of signalling. No fallback widens the target: the unresolved fallback in `resolved()` goes. **How it is proved without risk.** - Each guard gets a test that is red when the guard is mutated away. - Those tests drive the guard through an injected finder and signaller that record, never signal, so a surviving mutant kills nothing. - No test passes `""`, `/` or a relative root to a real killer. - Every local run is inside `unshare --user --map-root-user --pid --fork --mount-proc`, in the one crew-wide slot. **Out of scope.** #195's area (Pallas), #203 (Uranus), and martha-engine (read in the sweep; nothing reachable). No new check (B11).
Member

Purpose met (defect). Landed on main as bc8c2c25 (PR 209: 22ce4755 + r2 c398d9ac), Mars VERDICT r=2 PASS. Main push CI run 5096 (ci.yml) ended success.

  • Items 1-7 are fixed. Each fix has a test that turns red when it is mutated away, and every test runs confined in a pid namespace with a recording signaller.
  • Items 8-11 are fixed by name: killGroup, signalAGroupWith, theGroupIn and theShellThatWaitsOnUs.
  • One rule now decides what a signal or a scan may reach: linux_process_identity/what_a_signal_may_reach.ts. A pid, group or session must be at least 2 and none of the caller's own. A folder must be absolute, must resolve, and must not be /, a shared root or an ancestor of one.
  • No new check was added.

Threat model: issuecomment-5167. Refs #195.

Purpose met (defect). Landed on main as bc8c2c25 (PR 209: 22ce4755 + r2 c398d9ac), Mars VERDICT r=2 PASS. Main push CI run 5096 (ci.yml) ended success. - Items 1-7 are fixed. Each fix has a test that turns red when it is mutated away, and every test runs confined in a pid namespace with a recording signaller. - Items 8-11 are fixed by name: killGroup, signalAGroupWith, theGroupIn and theShellThatWaitsOnUs. - One rule now decides what a signal or a scan may reach: linux_process_identity/what_a_signal_may_reach.ts. A pid, group or session must be at least 2 and none of the caller's own. A folder must be absolute, must resolve, and must not be /, a shared root or an ancestor of one. - No new check was added. Threat model: issuecomment-5167. Refs #195.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
martha-ai/martha#205
No description provided.