daemon: no cap on concurrent connections + unbounded outer read wait (local DoS) #11
Labels
No labels
code-review
correctness
dos
performance
security
severity/high
severity/low
severity/medium
tech-debt
Kind/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
h-dv/code-index#11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: High · Category: DoS
accept_loop(crates/daemon/src/server.rs:153-166) spawns one unbounded tokio task per accepted socket.active_connectionsisfetch_add/fetch_sub-bracketed but never read to reject — it is a dead metric (onlylast_activitydrives idle-shutdown). A local peer can open thousands of sockets; each can sit inread_frame's unbounded outer wait for the next length prefix (protocol.rs:104-105documents this as deliberate — only the body read is bounded byFRAME_BODY_TIMEOUT), holding a task + fd + a potential 16 MiB buffer (see sibling frame-before-auth issue).Fix
tokio::sync::Semaphorepermit (e.g. 8–16) beforeserve_connection; drop over-cap connections.active_connectionsso a handler panic can't skew the gauge (server.rs:154/165).Impact / scope
Filed from a deep multi-agent code review of the workspace (v0.5.7). Severity/category per the review; file:line refs were accurate at review time — verify against current
master.Fixed in
0f4bfe7(branchfix/ultradeep-review-findings).Reassessed on current master — all three claims held: unbounded task-per-socket,
active_connectionsa dead metric never read to reject, unbounded outer length-prefix wait. Fix:Semaphore(64)inaccept_loop; over-cap sockets are closed immediately (try_acquire_owned→ drop) rather than queued. One legit client uses a handful of connections, so normal traffic never reaches the cap.CONNECTION_IDLE_TIMEOUTwraps only the between-requests wait (never an in-flight request); a quiet connection frees its slot and the client'sRpcIndexreconnects transparently (covered byreconnect_e2e). Reaps idle squatters well before the 30-min daemon idle-shutdown.ConnGaugereplaces the manualfetch_add/fetch_subso theactive_connectionscount can't leak on a handler panic (also closes the #18 sub-item for this gauge).Combined with #10's 1 MiB request cap, worst-case unauthenticated footprint is bounded to 64 × 1 MiB. Full daemon suite green (193 tests).