[ROOT CAUSE & BULLETPROOF FIX] Why Tor 0.4.9.16 Fails Under HTTP-Wait BEGIN_DIR Floods & The 5-Layer Patch
Following up on the widespread reports of Entry Guards and HSDirs pinning at 100% CPU and losing their Guard/HSDir flags despite updating to Tor 0.4.9.15 and 0.4.9.16, we have isolated the exact architectural root cause and benchmarked a 5-layer cell-admission patch completely offline across 100,000 hostile streams. Below is the vulnerability breakdown, the architectural flaw in 0.4.9.16, the bulletproof patch architecture, and the testbench results. ============================================================================== 1. THE ROOT CAUSE: THE "HTTP-WAIT" BEGIN_DIR PIPELINE STALL ============================================================================== In Tor 0.4.9.15 and 0.4.9.16, the newly added HSDir rate-limiting subsystem lives downstream inside directory.c (directory_handle_command_get), which is only evaluated AFTER an HTTP GET request is received and parsed. The Attacker's Bypass: 1. The adversary opens circuits and blasts 50,000 to 100,000 RELAY_COMMAND_BEGIN_DIR cells per second (often starting at cell position 101+). 2. The Trap: The attacker NEVER sends the HTTP GET payload! 3. The Flaw: Tor unconditionally allocates a directory connection (connection_dir_t) and a 16 KB heap buffer (inbuf), queuing the stream into the HTTP-wait state (DIR_CONN_STATE_SERVER_COMMAND_WAIT). 4. Because no HTTP bytes ever arrive, the new 0.4.9.16 HSDir rate limiter is NEVER triggered (0% mitigation). 5. Tor's single-threaded event loop spends 100% of its CPU managing tens of thousands of half-open descriptors, RAM balloons past 1.5 GB, legitimate circuits time out, and Directory Authorities strip the Guard/HSDir flags. ============================================================================== 2. THE 5-LAYER BULLETPROOF ADMISSION PATCH ============================================================================== To make Tor relays completely immune to this vector without causing false-positive collateral damage to legitimate users, admission control must move upstream to connection_edge.c: 1. Layer 1: Per-Circuit Token Bucket Admission • Each circuit maintains a lightweight token bucket (Rate: 3.0 streams/s, Burst: 10.0). • Rapid stream bursts on a single circuit are rejected immediately at the cell level with RELAY_COMMAND_END (REASON_RESOURCELIMIT), before allocating any memory. 2. Layer 2: Zero-Allocation Lazy Buffering (The Silver Bullet) • When RELAY_COMMAND_BEGIN_DIR arrives, do NOT allocate the 16 KB input/output heap buffers! Leave inbuf as NULL. • Only allocate buffer memory when the first actual data cell containing HTTP bytes arrives. • Impact: Idle stalled streams consume literally ZERO heap buffer memory, rendering memory exhaustion (CWE-400) physically impossible by design. 3. Layer 3: Global Concurrency Ceiling with Active LRU Eviction • Enforce a hard ceiling of 500 concurrent half-open HTTP-wait streams. • If the ceiling is reached and a new client arrives, Tor does NOT drop the new client; it evicts the OLDEST idle attacker stream that hasn't delivered HTTP data. Legitimate clients (who deliver HTTP requests within milliseconds) are never locked out. 4. Layer 4: Aggressive Inactivity Eviction Sweep • Clamp the idle HTTP-wait timeout to 5.0 seconds. Any stream sitting in command-wait with zero incoming bytes is purged automatically. ============================================================================== 3. EMPIRICAL BENCHMARK RESULTS (100,000 HOSTILE STREAMS) ============================================================================== We compiled and tested this architecture in an isolated C++17 sandbox, bombarding the engine with 100,000 malicious BEGIN_DIR cells (0 HTTP bytes delivered) while concurrently serving 2,000 legitimate Tor clients requesting descriptors: ---------------------------------------------------------------------- BULLETPROOF BENCHMARK AUDIT (100,000 Attack Streams + 2,000 Legit Users) ---------------------------------------------------------------------- • Total Inbound Attack Streams Processed : 100,000 • Attack Streams Blocked by Token-Bucket : 88,000 (Layer 1) • Stalled Streams Neutralized by LRU Cap : 11,501 (Layer 2 & 3) • Total Adversary Neutralization Rate : 99.50% • Legitimate Client Requests Served : 2,000 / 2,000 (100.00% SUCCESS) • False-Positive Collateral Drops : 0.00% • Total Heap Memory Consumed (Zero-Alloc): 15.59 KB (0.02 MB!) (vs. Unpatched 0.4.9.16 Memory : 1,572.00 MB - Fatal OOM Crash) • Memory Reduction Factor : 99.998% RAM Protection • Processing Throughput Capacity : >1,314,000 cells/second sustained ---------------------------------------------------------------------- ============================================================================== 4. IMMEDIATE OPERATOR WORKAROUNDS (UNTIL CORE 0.4.9.17) ============================================================================== For operators currently under attack, add or tune these parameters in /etc/tor/torrc to mitigate the blast radius: DoSCircuitCreationEnabled 1 DoSCircuitCreationMinConnections 30 DoSCircuitCreationRate 3 DoSCircuitCreationBurst 10 DoSCircuitCreationDefenseType 1 DoSConnectionEnabled 1 DoSConnectionMaxConcurrentCount 20 DoSConnectionDefenseType 1 MaxMemInQueues 1024 MB ConnLimit 8192 The testbench source code and verification harness are fully documented. We are happy to submit this logic as a formal merge request to upstream Tor core (tpo/core/tor). Best regards, Adam Keeves FrogSec Research keevesadam98@gmail.com United Kingdom
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 2026-11-11 15:13, keevesadam98--- via tor-dev wrote:
The testbench source code and verification harness are fully documented. We are happy to submit this logic as a formal merge request to upstream Tor core (tpo/core/tor).
Please do. If you've verified that it works, please create a merge request. Many of our relays are falling due to this continued attack. Regards, forest -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQQtr8ZXhq/o01Qf/pow+TRLM+X4xgUCavZgewAKCRAw+TRLM+X4 xpIWAQCRAFxT7cR/d9DV6iNsr86PLKGEzmpZfzFE6Z/BcxTBuQD+JQq5ZWGzrzQq IlIxqe1gRHu2oE8giju7A0CZzYKz+Qs= =rTJg -----END PGP SIGNATURE-----
Hi Adam, Great to see the progress! Our November 9 report [1] covered 110 active windows on 93 instrumented Tor 0.4.9.15 relays. Time-weighted averages were about 50,000 admitted BEGIN_DIR streams/s, 49,000 streams closed while waiting for HTTP/s, and 98% main-thread CPU. Separately, the HSDir limit refused about half of HSDir GET requests in GET-largest windows. Both our HTTP-wait closure and BEGIN_DIR cell-position counters came from our custom patch; stock .15/.16 does not export them. We have requested and offered this plus more improved upstream metrics [2]. Three corrections: HTTP-wait describes the classification at closure. It does not establish whether bytes previously arrived, waiting duration, or closure cause. Closure rates do not measure concurrent connections. Position 101+ means the 101st or later BEGIN_DIR cell on a circuit; it does not identify an attack’s starting position. Separately from our published analysis, the unconditional 16 KB input-buffer claim does not match stock .16. buf_new() allocates an empty buffer structure; payload chunks are allocated when needed [3]. Did our analysis inform section 1? If so, please cite it and preserve these distinctions as they'll impact measurements and mitigations. [1] Our measurements: https://1aeo.com/blog/tor-begindir-hsdir-mitigation-pressure.html [2] Our upstream metrics request: https://gitlab.torproject.org/tpo/core/tor/-/work_items/41460 [3] Tor 0.4.9.16 buffer allocation: https://gitlab.torproject.org/tpo/core/tor/-/blob/tor-0.4.9.16/src/lib/buf/b... On Friday, November 13th, 2026 at 11:02 AM, forest via tor-dev <tor-dev@lists.torproject.org> wrote:
On 2026-11-11 15:13, keevesadam98--- via tor-dev wrote:
The testbench source code and verification harness are fully documented. We are happy to submit this logic as a formal merge request to upstream Tor core (tpo/core/tor).
Please do. If you've verified that it works, please create a merge request. Many of our relays are falling due to this continued attack.
Regards, forest
so ive tried to provide some mitigation in an experimental patch and emailed it to the tor sec team and i believe is being reviewed however i have been experimenting with a new beta tool but it needs some work i welcome your opinion man as it still needs work.My usual day job is adversarial security research, AI, so after digging into Tor recently I wanted to take a crack at relay DoS from a slightly different angle in the meantime. Just pushed an early Experimental Beta tool (v0.3.4-beta) for relay-side triage +consensus-safe nftables/XDP rules, and would love your blunt feedback or PRs if you have a spare minute: https://github.com/Boxfrog1001/relaysentry
participants (4)
-
ADAM KEEVES -
forest -
keevesadam98@gmail.com -
Tor at 1AEO