Skip to content

fix(ssh): corroborate an empty lsof answer before calling an endpoint free - #20585

Merged
nwparker merged 1 commit into
mainfrom
astra/relay-lsof-blind-uid
Sep 15, 2026
Merged

nwparker merged 1 commit into
mainfrom
astra/relay-lsof-blind-uid

Conversation

@nwparker

@nwparker nwparker commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​94 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​90
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22

Follow-up to #18304, which fixed the general case: enumerability decided after lsof runs, keying on stderr, non-numeric output, and an abnormal exit. One failure carries none of those signals.

The gap

Probing as a uid that does not own the socket's holder, lsof -t -a -U <path> exits 1 with no stdout and no stderr. Measured on Debian 12 against #18304's own probe — a live relay owned by root, socket mode 666, probed as nobody:

probe uid path marker pids
main nobody held.sock lsof [] live relay holds it
main nobody stale.sock lsof [] genuinely nobody
main root held.sock lsof [10]
main root stale.sock lsof []

The first two rows are byte-identical. Nothing about lsof's answer separates them, so this is not reachable by inspecting the answer harder.

The first row reaches verdict: exited / evidence: no-holder, which classifySupersededRelay maps to stale-endpoint-removed → rm -f on an inode a live relay still holds. hidepid=2 produces the same shape.

Why a positive control doesn't work

The obvious shape — ask lsof about something that must have a holder, and treat a blank control as blindness — fails here. A control on something the probe itself holds passes precisely when we are blind:

as nobody:  lsof -t -p $$              -> [48]      control passes
as nobody:  lsof -t -a -U held.sock    -> []        socket query blind

Blindness is to other uids, and another uid's process is not ours to manufacture. So the control has to come from outside lsof.

What does work

/proc/net/unix is world-readable and lists every bound unix socket regardless of owner. Measured identically as root and as nobody:

/proc/net/unix  held.sock   -> inode=[8399387]
/proc/net/unix  stale.sock  -> inode=[]

An entry for the path alongside no reported pid proves lsof was blind, rather than that the path is free. Same run as the table above, with this change:

probe uid path marker pids
fixed nobody held.sock unavailable [] no longer reapable
fixed nobody stale.sock lsof [] still reapable
fixed root held.sock lsof [10] unchanged
fixed root stale.sock lsof [] unchanged

Only an otherwise-clean empty answer is corroborated: a reported pid still stands on its own, and the check is skipped when the answer was already unavailable or cleanup-unconfirmed. The marker can only ever move from lsof toward unavailable, so this never authorises an unlink #18304 refuses.

Non-Linux, and why it is not conservative there

There is no /proc/net/unix off Linux; the check returns false and behaviour is exactly as before. That is deliberate. Defaulting to unavailable there would stop every macOS host from reaping a genuinely stale endpoint — trading a rare destructive bug for a universal accumulation one. The gap remains on macOS hosts and is called out in the source.

The tests are Linux-gated for the same reason, with an assertion that /proc/net/unix actually exists so the block cannot pass vacuously on a runner that lacks it.

Mutation table

Every row was re-introduced and run; each maps to a distinct assertion.

mutation test that fails
origin/main unmodified reports unavailable when nothing was reported for a socket that is still bound
drop the corroboration same
corroborate even when pids were reported keeps a reported pid even while the path is still bound
match bound-path-starts-with-target does not treat a prefix of the bound path as bound
match target-starts-with-bound-path does not treat a path the bound one prefixes as bound
treat every path as still bound both prefix cases and still reports lsof for an empty answer about a path nothing has bound

The last row is the control that matters: it is the one that fails if this change ever makes a healthy host stop reaping.

Verified on Linux (node 22 container, repo config): 19 passed, 0 skipped, and confirmed able to fail there by breaking the cross-uid assertion (1 failed | 17 passed). oxlint clean; tsc clean for these files.

Two caveats on the local run, for the record: four src/main/ai-vault/* test files fail to import and one tsc error is reported in session-document-stream.ts, both from a missing @streamparser/json in the node_modules snapshot this scratch checkout borrowed. Neither touches this change, and both reproduce without it.


Rebased onto main @ caa465d1da886b2697c85c18bf36f79f2d3b9e68 (2026-09-15).

  • Old head: 10bbcc2cd4c781bbc4bff995b9ae230a43e5d372
  • New head: f29baa6c547a6b304d38c09f1ea4cdaf9d3303be

Rebase only; the commit is byte-identical under git range-diff. Rebased so CI re-evaluates against current main. The branch already cleared every tightened gate locally at the new base.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 16d552cf-24b0-4595-8e87-e9ad5fbb199d

📥 Commits

Reviewing files that changed from the base of the PR and between 0c81284 and 10bbcc2.

📒 Files selected for processing (2)
  • src/shared/child-process/posix-lsof-probe.test.ts
  • src/shared/child-process/posix-lsof-probe.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The POSIX lsof probe now checks /proc/net/unix on Linux when lsof returns no output. It reports unavailable for a still-bound socket and preserves existing behavior for unbound paths and non-Linux systems. Tests now support custom lsof output and socket paths, and cover bound, unbound, reported-pid, prefix, and prefixed-by paths.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 10bbc

The Linux corroboration retains bound sockets as unavailable without introducing a supported cleanup or endpoint-detection regression.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: corroborating empty lsof results before treating an SSH endpoint as free.
Description check ✅ Passed The description provides a detailed explanation of the problem, solution, platform scope, linked issue reference, test coverage, mutation testing, and known unrelated local failures. It does not use a…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Corroborating an empty lsof answer — pathStillBound in posix-lsof-probe.ts reads the world-readable /proc/net/unix and, when a clean lsof answer reported no pids for a path the kernel still lists as bound, moves the marker to unavailable. That propagates to HOLDERS_SOURCE=unavailable → holdersEnumerable=false → verdict unverifiable, so the superseded-relay sweep no longer rm -fs an inode a live relay (owned by another uid, or hidden by hidepid=2) still holds.
  • Gate shape — the check runs only for an otherwise-clean empty answer (!unconfirmed && !unavailable && !stderrSeen && !pids.length); a reported pid still stands alone, and the marker can only move from lsof toward unavailable, never toward authorising an unlink the prior fix refuses.
  • Linux-gated coverage — runProbe gains lsof/sockPath overrides, and a new suite binds a real unix socket while stubbing a blind lsof. It pins blind-and-bound → unavailable, blind-and-unbound → lsof (the anti-accumulation control), reported-pid precedence, and exact-path rather than substring matching on both prefix and suffix neighbours, plus an assertion that /proc/net/unix exists so the block cannot pass vacuously.

I verified the line-and-inode regex against real /proc/net/unix output for a bound socket (exact capture), ran posix-lsof-probe.test.ts (19 passed), the incumbent and shell-integration suites with real lsof present (42 passed), oxlint on both changed files (clean), and the changed-code quality gate against 0c81284 (all four scans passed). The residual macOS gap is deliberate and documented in the source; it does not regress the prior behavior.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

… free

#18304 decided enumerability after `lsof` runs, keying on stderr, non-numeric
output, and an abnormal exit. One failure carries none of those signals: probing
as a uid that does not own the socket's holder, `lsof -t -a -U <path>` exits 1
with no stdout and no stderr. Measured on Debian 12 against #18304's own probe, a
live relay owned by root probed as `nobody`:

  probe    uid      path         marker        pids
  merged   nobody   held.sock    lsof          []      <- live relay holds it
  merged   nobody   stale.sock   lsof          []      <- genuinely nobody
  merged   root     held.sock    lsof          [10]
  merged   root     stale.sock   lsof          []

The first two rows are byte-identical, so nothing about lsof's answer can
separate them. The first reaches `verdict: exited / evidence: no-holder`, which
`classifySupersededRelay` maps to `stale-endpoint-removed` and `rm -f` on an
inode a live relay is still holding. `hidepid=2` produces the same shape.

A positive control does not solve this. Controlling on something the probe itself
holds passes precisely when we are blind: as `nobody`, `lsof -t -p $$` returns a
pid while the socket query returns nothing. Blindness is to *other* uids, and
another uid's process is not ours to manufacture.

/proc/net/unix is. It is world-readable and lists every bound unix socket
regardless of owner, so an entry for the path alongside no reported pid proves
lsof was blind rather than that the path is free. Only an otherwise-clean empty
answer is corroborated; a reported pid still stands on its own, and the check is
skipped when the answer was already unavailable. Same run, with this change:

  fixed    nobody   held.sock    unavailable   []      <- no longer reapable
  fixed    nobody   stale.sock   lsof          []      <- still reapable
  fixed    root     held.sock    lsof          [10]    <- unchanged
  fixed    root     stale.sock   lsof          []      <- unchanged

The marker can only ever move from `lsof` toward `unavailable`, so this never
authorises an unlink that #18304 refuses.

Off Linux there is no /proc/net/unix, the check returns false, and behaviour is
exactly as before -- deliberately, because defaulting to `unavailable` there
would stop every macOS host from reaping a stale endpoint and trade a rare
destructive bug for a universal accumulation one. The tests are Linux-gated for
the same reason, with an assertion that the evidence they depend on is actually
present so the block cannot pass vacuously.
@nwparker
nwparker force-pushed the astra/relay-lsof-blind-uid branch from 10bbcc2 to f29baa6 Compare September 15, 2026 10:25
@nwparker
nwparker merged commit 72a8c09 into main Sep 15, 2026
27 of 28 checks passed
@nwparker
nwparker deleted the astra/relay-lsof-blind-uid branch September 15, 2026 23:01
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
… free (stablyai#20585)

stablyai#18304 decided enumerability after `lsof` runs, keying on stderr, non-numeric
output, and an abnormal exit. One failure carries none of those signals: probing
as a uid that does not own the socket's holder, `lsof -t -a -U <path>` exits 1
with no stdout and no stderr. Measured on Debian 12 against stablyai#18304's own probe, a
live relay owned by root probed as `nobody`:

  probe    uid      path         marker        pids
  merged   nobody   held.sock    lsof          []      <- live relay holds it
  merged   nobody   stale.sock   lsof          []      <- genuinely nobody
  merged   root     held.sock    lsof          [10]
  merged   root     stale.sock   lsof          []

The first two rows are byte-identical, so nothing about lsof's answer can
separate them. The first reaches `verdict: exited / evidence: no-holder`, which
`classifySupersededRelay` maps to `stale-endpoint-removed` and `rm -f` on an
inode a live relay is still holding. `hidepid=2` produces the same shape.

A positive control does not solve this. Controlling on something the probe itself
holds passes precisely when we are blind: as `nobody`, `lsof -t -p $$` returns a
pid while the socket query returns nothing. Blindness is to *other* uids, and
another uid's process is not ours to manufacture.

/proc/net/unix is. It is world-readable and lists every bound unix socket
regardless of owner, so an entry for the path alongside no reported pid proves
lsof was blind rather than that the path is free. Only an otherwise-clean empty
answer is corroborated; a reported pid still stands on its own, and the check is
skipped when the answer was already unavailable. Same run, with this change:

  fixed    nobody   held.sock    unavailable   []      <- no longer reapable
  fixed    nobody   stale.sock   lsof          []      <- still reapable
  fixed    root     held.sock    lsof          [10]    <- unchanged
  fixed    root     stale.sock   lsof          []      <- unchanged

The marker can only ever move from `lsof` toward `unavailable`, so this never
authorises an unlink that stablyai#18304 refuses.

Off Linux there is no /proc/net/unix, the check returns false, and behaviour is
exactly as before -- deliberately, because defaulting to `unavailable` there
would stop every macOS host from reaping a stale endpoint and trade a rare
destructive bug for a universal accumulation one. The tests are Linux-gated for
the same reason, with an assertion that the evidence they depend on is actually
present so the block cannot pass vacuously.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant