Skip to content

Slow read DoS prevention #1715

@b3b

Description

@b3b

Motivation

Because of high memory usage per each connection, possible denial of service exists when large resources are consumed by slow clients.

Related issues: #1714, depends on #498 (single large response fully cached may cause DoS)

Testing

Scenario to reproduce

Host1 (slow clients):

Start a lot of slow (1 byte per second) downloads:
curl --output /dev/null -H 'Connection: close' --parallel-max 999 --parallel --parallel-immediate 'http://tempesta-host/[1-10000]' --limit-rate 1B

Host2 (legitimate client):

Try to access resource: curl -v --output /dev/null http://tempesta-host

Depending on the load, result could be:

  • Empty response, client hangs for some time, and receive [FIN,ACK] from Tempesta:
    curl: (52) Empty reply from server
  • Partial response is downloaded and connection is closed by the Tempesta side [RST, ACK]:
  { [1132 bytes data]
  * Recv failure: Connection reset by peer
  * Closing connection 0
  curl: (56) Recv failure: Connection reset by peer

Tempesta

  • cat /proc/net/sockstat show high value of TCP memory usage
  • ss -l show high Send-Q values
  • DMESG contains messages: TCP: out of memory -- consider tuning tcp_mem
tempesta.cfg
listen 80 proto=http;
server 127.0.0.1:8000;
cache 0;

Backend

Backend on port 8000 should return a large response.
Tested on 200MB, larger responses could trigger #1714

Scenario for quick reproduction

  • Reduce TCP memory bound: sysctl -w net.ipv4.tcp_mem='100 100 100'
  • Start first (slow) client: curl -v --output /dev/null http://127.0.0.1 --limit-rate 1B
  • While first client is running, start second client: curl -v --output /dev/null http://127.0.0.1
  • Second client hangs until the first client has finishing downloading.

Metadata

Metadata

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions