Hi,
my relay (non-exit) is hit by the BEGIN_DIR/HSDir flood, and memory keeps growing even on 0.4.9.15 (where it probably should be fixed?)
Setup
-
Relay: 54A29E2BBE66F472813D9A937A103F37966205C7, flags: Fast, Guard, HSDir, Running, Stable, V2Dir, Valid
-
Tor 0.4.9.15 on Debian 13 (kernel 6.12), KVM VPS with 4 vCPU and 8 GB RAM
-
RelayBandwidthRate 64 Mbit, MaxAdvertisedBandwidth 24 Mbit, MaxMemInQueues 1 GB (was 3 GB before attack), default DoS options
Yesterday
- Open circuits went from ~7k to 962k. After restarts there were 349k after 8 min.
- About 100k ntor v3 handshakes per minute, and “Your computer is too slow to handle this many circuit creation requests!”
- The DoS heartbeat at 52 min:
959479 BEGIN_DIR HSDir requests rejected,34023 BEGIN_DIR rate rejected,0 circuits rejected,[DoSBeginDirLimitEnabled disabled] - 93% of inbound connections come from relay IPs in the consensus, so the client DoS defences don’t apply.
- Tor’s RSS grew 30-100 MB/min to 4.8 GB. The main thread was at ~95% CPU. MaxMemInQueues doesn’t limit this (no OOM-handler messages), so it seems to be the circuits themselves.
Today
It hasn’t stopped and is larger: about 1.5M circuits whenever Tor reaches the 5 GB cap, 2,000-2,800 ntor v3 handshakes/s (normal ~30/s), 250-940 HSDir/BEGIN_DIR rejections/s, and ~50% CPU on 4 vCPUs. The memory cap restarts Tor about once an hour (12 times in 10 h). The flags have survived so far. My other relay, on a home connection is unaffected (~800 circuits).
A kernel side effect on virtio_net VPS:
Tor couldn’t drain its ~8k sockets, so about 2.5 GB of RAM ended up in kernel packet buffers. That memory doesn’t show in any process or /proc/meminfo field: each small queued packet keeps a 32 KB page alive. There were 1.5M TCPRcvQDrop in about an hour. Setting net.core.high_order_alloc_disable = 1 (as below) brought it down from 2.5 GB to 0.6 GB within 5 minutes.
My current workaround:
# /etc/sysctl.d/60-net-high-order-alloc.conf
net.core.high_order_alloc_disable = 1
# Tor gets OOM-killed in its own cgroup and restarted, instead of pushing the host into swap
systemctl set-property tor@default.service MemoryMax=5G MemorySwapMax=0
The host is stable now but Tor restarts about once an hour (MemoryMax) and is down ~17 s each time.
(first ram spike - tor + system packet buffers, later spikes - oom-kill by MemoryMax - to not influence host)
Can I do anything else (enable DoSBeginDirLimitEnabled, add DirCache 0 but it is not recommended) or just wait till it ends?
edit: things I found in meantime:
In torrc set dircache 0. Will remove the relay from guard and HSDir flags and the majority of the attacks. Still able to serve traffic and contribute to Tor with less stress on the server resources.
So as last resort - link (I cannot add more as new user
, search “Shutting down my ~40 guards” in last link below)
The circuit-building attack is under control on my relays, since I’m
protecting from it on the firewall-level using a ruleset inspired by
toralf’s iptables generator. Unfortunately, the BEGIN_DIR flood cannot
be mitigated using that method since each connection contains multiple
multiplexed circuits, each of which can multiplex multiple streams.
I have also nft firewall based on torutils and it not help with hsdir flood (but at least blocks circuit ddos) - link (I cannot add more as new user
, search “Shutting down my ~40 guards” in last link below)
So it is probably coordinated action to identify visitor and fix is tested since last week so there is a hope (last two messages): link
