provenance: bind running-image checks to process start time (closes #60)

Merged
IC
3mo ago
+193-15

Closes #60.

ExecutableIdentityProbe::observe read /proc/<pid>/exe without confirming the PID still belonged to the process the supervisor spawned. If a child exits and the OS recycles its PID before the probe runs, that path points at an unrelated process.

The dangerous outcome is not the false alarm. If the recycled process happens to be running the same binary — another ck-subc, another copy of the same module, which is entirely plausible on a busy box — the probe returns Match, the strongest positive attestation the daemon makes, about a process that is not ours. An attestation that fails open is worse than one that fails loudly.

Fix

Pair the PID with the process start time, which the kernel assigns at exec and a recycled PID cannot reproduce. The supervisor captures it alongside the existing spawn facts; the probe re-reads it and compares before touching the image.

When identity cannot be confirmed — recorded and current start times differ, or the value is unreadable — the probe returns a new typed process_identity_unconfirmed, never a verdict.

Precedence is load-bearing. The identity check runs strictly before the digest comparison, and its unavailable wins. A recycled PID running a different binary makes both facts true at once, and reporting Mismatch there would assert "the running image is the wrong binary" about a process we cannot identify. An unconfirmable identity forfeits the right to make any claim about the image, in either direction. unavailable is not the cautious middle between Match and Mismatch — it is the only honest answer when we cannot say whose process we are looking at.

Tests

Four arms, each proved load-bearing by breaking the seam it guards and showing it goes red:

ArmRed proof
differing start time → unavailableguard removed → returned Match
live un-recycled child still returns Matchguard inverted → arm failed
precedence: differing time beats differing digestchecks reordered → returned Mismatch
/proc comm-field parsenaive split_whitespace → 18 instead of 424242

The positive arm is the one that matters. A gate that always returns unavailable passes the obvious mismatch test while destroying the feature, and it looks like caution while doing it — so the test that a real, live, un-recycled process still returns Match is what proves the check does not manufacture false unavailables. It spawns a real process and captures its start time through the production path.

The parse arm covers a trap worth naming: field 2 of /proc/<pid>/stat is the executable name in parentheses and can contain both spaces and parentheses, so a naive split_whitespace().nth(21) misparses for any such process and yields a permanent false unavailable. The parser splits on the last ) instead. That test is deliberately not platform-gated — it parses a string, touches no /proc, and the trap is equally wrong everywhere, so it runs on every platform's CI.

Start-time values are compared exactly as read, in raw clock ticks. No conversion to wall time: every conversion introduces rounding or drift, and drift here manufactures false unavailable results on healthy processes.

Scope

Linux only. The macOS arm compares file identity and already discards the PID, so it has no exposure to this race; Windows remains UnsupportedPlatform. Wire surface is additive — one new RunningImageUnavailableReason variant, subc-control 0.6.0 → 0.7.0 with the dependent cascade. subc-protocol and subc-transport are untouched. No golden fixtures changed.

CI will be red, and not from this change

Master is currently red for both platforms — the history rewrite removed docs/team-mode/ while three code paths still reference fixtures there, so agent-token-vectors fails to compile its test target and one subc-core test panics. Filed as #75. Any branch cut from current master inherits it.

Attribution against that baseline: 2 workspace failures, both traced to the two missing fixture files, leaving 0 attributable to this change. Everything else is green, run independently of the implementer's own report — cargo fmt --all --check, cargo build --workspace --locked, clippy --all-targets -D warnings (excluding the uncompilable crate), check-wire-crate-versions.sh origin/master, and the full provenance suite at 15/15.

I did not generate the missing fixtures to get a green gate. A fabricated conformance vector passes the tests while encoding values nobody verified, and the next reader cannot tell it from a real one.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes a Linux-only PID-recycling race in running-image provenance checks (closes #60). The probe previously read /proc/<pid>/exe without confirming the PID still belonged to the spawned process, so a recycled PID running the same binary could produce a false Match; it now captures the process start time at spawn, compares it against the current process, and returns a new ProcessIdentityUnconfirmed unavailable verdict when identity cannot be confirmed.

  • The probe opens the running executable first and hashes the retained descriptor, so a PID recycled between validation and hashing cannot substitute a different image.
  • The identity check runs strictly before the digest comparison, so an unconfirmable identity never reports Match or Mismatch.
  • Start-time values are compared in raw clock ticks with no wall-clock conversion; the /proc/<pid>/stat parser splits on the last ) so executable names containing spaces or parentheses parse correctly.
  • The supervisor captures start time at spawn for supervised children and daemon identity facts; macOS and Windows are unaffected.

Migration

  • subc-control bumps 0.6.0 → 0.7.0 with the additive ProcessIdentityUnconfirmed reason; consumers must handle the new unavailable case.
  • subc-client-rs (0.8.0 → 0.9.0) and subc-core (0.8.1 → 0.9.0) bump via the dependency cascade.
  • CI is red on master from a pre-existing missing-fixtures issue (#75), unrelated to this change.