Tor 0.4.9.15 BEGIN_DIR/HSDir flood, oom-kill despite MaxMemInQueues

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 :confused:, 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 :confused:, 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

Unnamed:

Hi,

my relay 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

  • default DoS options

Yesterday (2026-11-01 ~13:00 UTC)

  • Open circuits went from ~7k to 962k after 52 min of uptime. After a restart 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 (2026-11-02 10:00 UTC)
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. I left DoSBeginDir* to the consensus, as the release post asks.

(first ram spike - tor + system packet buffers, later spikes - oom-kill by MemoryMax - to not influence host)

Can I do anything else (enable DoSBeginDirLimitEnabled, that post tell not to add DirCache 0) or just wait till it ends?

Hard to say. It seems your relay is not restarting anymore once an hour,
it seems. So, things have stabilized so far?

Georg

···

Visit Topic or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, click here.

I’m experiencing a similar OOM issue on my Tor relay running Ubuntu with Tor 0.4.9.16.

Server specifications:

  • RAM: 4 GB (3.8 GiB available)

  • SWAP: 0 GB (not configured at the time of the incident)

  • Tor version: 0.4.9.16

  • ORPort: 9090

Observed memory issue:

Tor automatically configured:

MaxMemInQueues = 2901 MB

The Linux OOM Killer terminated Tor twice:

  • 13:46 – Tor RSS: approximately 2.5 GB

  • 14:01 – Tor RSS: approximately 2.44 GB

Relevant kernel log:

Out of memory: Killed process 182832 (tor)

Current observations:

  • 1,478 connections on ORPort 9090

  • Current Tor memory usage: approximately 260 MB

  • 26,578 circuits rejected

  • 35,243 INTRODUCE2 requests rejected

  • 0 BEGIN_DIR rate rejections

  • 0 BEGIN_DIR HSDir request rejections

I’m investigating whether this is related to the BEGIN_DIR/HSDir flood described in this thread.

I’m considering manually reducing MaxMemInQueues to 512 MB and applying systemd memory limits (MemoryHigh=1024M, MemoryMax=1536M).

Questions:

  1. Has anyone observed similar memory growth on Tor 0.4.9.16?

  2. Could circuit creation or HSDir/BEGIN_DIR activity cause this memory consumption independently of MaxMemInQueues?

  3. Would reducing MaxMemInQueues to 512 MB be reasonable for a 4 GB relay?

Any suggestions or diagnostic recommendations would be appreciated.

I was hit by this hsdir attack again, with memory grow, adding this two options

# /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

(5GB set for 8 GB of RAM on VPS) does not prevent it, but after reaching 5GB tor service was restarted, so with this options host below is at least stable.

More concerning for me is that after restart relay lost (as in earlier attack - and this is probably it’s purpose) HSDir flag, and if attacker do this to many relays, users will have much higher chance to use working, attacker relays, so it could be used to block access to some sites (but probably not deanonimise - but someone else should check this - link to different topic about this)