Skip to content

rocmd: stopping a managed service signals recorded PIDs without verifying process identity #498

Closed

Description

@rominf

Current behavior

rocmd's managed-service stop reads engine_pid and supervisor_pid out of a persisted service record and signals them directly — SIGTERM, then SIGKILL 750 ms later — without checking that those PIDs still identify the recorded processes. It then expands descendants against a live process listing, so a stale root PID drags whatever now owns that PID and all of that process's children into the kill set.

Two compounding problems:

  1. No identity check at stop time. apps/rocm does the same job correctly: it pairs each PID with its own start-time token and calls rocm_core::terminate_verified, which returns IdentityMismatch and signals nothing when the identity is refuted. apps/rocmd contains no reference to terminate_verified, ProcessIdentity, or the token fields, though it reads the same record type from the same location.

  2. No identity recorded at write time. apps/rocmd never captured supervisor_start_ticks/engine_start_ticks at all. Every record it wrote has None, which rocm_core::identity_state classifies as Matches via its documented legacy branch ("no recorded identity: best-effort proceed"). So merely adding a verified stop would have changed nothing for records rocmd created.

Expected behavior

A recorded PID is signalled only when it still identifies the recorded process, as rocm services stop already does.

Steps to reproduce

Three realistic routes make a recorded PID stale while the record still names it:

  • Reboot — records persist under services/*.json; PIDs restart from low numbers, so a recorded 4-6 digit PID is likely re-allocated.
  • Repeat stop — the stop set status = "stopped" but left the PIDs in the record, so a second stop re-signalled them.
  • Crash — the service dies and the record still reports ready with the old PIDs.

Then stop the service. Observed with a live bystander occupying the recorded PID: it is SIGTERM'd and SIGKILL'd, and when the bystander has a child, the child is signalled too.

Consequence

SIGTERM followed by SIGKILL of an arbitrary process tree on the user's machine.

Reachability

Both the CLI (rocmd sandbox-tool stop-server --service-id <id>) and the daemon's MCP tool surface (stop_server), so an LLM agent can invoke it.

Environment

  • Observed on Linux against main. The missing identity check is platform-independent; on Windows rocm_core cannot read process start times at all, so identity is unverifiable there regardless.

Related

rocm comfyui stop has the same shape: ComfyUiState stores only pid with no kernel identity token, and the stop calls terminate_process_tree after a bare liveness check. Fixing it needs a state-schema addition, so it is tracked separately.

How it was found

Property-based testing of the process-lifecycle code. The tree walkers themselves came out clean under properties; this was found by reading outward from them to the callers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions