ocgo stop can kill wrong process (PID file TOCTOU) #2

Open
opened 2026-05-18 02:18:33 +00:00 by renekv · 0 comments
Contributor

Severity: Critical

stopCmd reads a PID from ~/.config/ocgo/ocgo.pid (world-readable 0644) then calls os.FindProcess(pid) followed by p.Kill(). On Unix, os.FindProcess always succeeds, so a malicious local user can write a fake PID to that file and cause ocgo stop to kill an arbitrary process. Even without malice, recycled PIDs can cause the wrong process to be killed.

File: cmd/ocgo/main.go:314-321

Fix: Verify the PID belongs to an actual ocgo process (e.g. check /proc/<pid>/exe or cmdline) before killing. Also restrict PID file permissions to 0600.

**Severity: Critical** `stopCmd` reads a PID from `~/.config/ocgo/ocgo.pid` (world-readable 0644) then calls `os.FindProcess(pid)` followed by `p.Kill()`. On Unix, `os.FindProcess` always succeeds, so a malicious local user can write a fake PID to that file and cause `ocgo stop` to kill an arbitrary process. Even without malice, recycled PIDs can cause the wrong process to be killed. **File:** `cmd/ocgo/main.go:314-321` **Fix:** Verify the PID belongs to an actual ocgo process (e.g. check `/proc/<pid>/exe` or `cmdline`) before killing. Also restrict PID file permissions to 0600.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
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: opencode/ocgo#2
No description provided.