T09 · Insecure Skill Coding Practices
- Location
scripts/codex_scheduler/runner.py:654- Finding
Codex child PID reuse may terminate an unrelated process
- Content
View full analysis
dict[str, Any]: run, run_dir = store.resolve_run(reference) if run.get("status") not in {"starting", "running"}: raise SchedulerError(f"run is not active: {run['status']}") atomic_write_text(run_dir / "cancel.requested", f"{iso()}\n") codex_pid = run.get("codex_pid") if codex_pid and process_alive(codex_pid): terminate_process_tree(codex_pid) ``` The invoked termination function operates on the PID without validating a process creation token: ```python def terminate_process_tree(pid: int, *, grace_seconds: float = 10) -> None: """Request termination, then force a still-running process tree to stop.""" if not process_alive(pid): return if os.name == "nt": run_checked( ["taskkill", "/PID", str(pid), "/T"], timeout=max(5, grace_seconds), ) else: try: os.killpg(pid, signal.SIGTERM) except ProcessLookupError: return deadline = time.monotonic() + grace_seconds while process_alive(pid) and time.monotonic() < deadline: time.sleep(0.1) if not process_alive(pid): return if os.name == "nt": run_checked(["taskkill", "/PID", str(pid), "/T", "/F"], timeout=15) else: try: os.killpg(pid, signal.SIGKILL) except ProcessLookupError: pass ``` ### Technical Analysis The scheduler stores a creation token for its runner process and uses that token to protect runner-related operations against PID reuse. It does not store an equivalent creation token for the spawned Codex child process. After Codex terminates, the ...[truncated 2485 chars]- Remediation
View remediation
