Section 1.28

Denial of service (DoS)

Definition

Denial of service (DoS) is an attack on availability §1.10: the attacker stops legitimate users from getting a service, or delays them longer than they can wait, by exhausting, holding or disrupting a resource that the service needs, such as processor time, memory, connection slots, network capacity or battery energy. The attacker needs no secret and need not defeat any check: well-formed, even authenticated, requests deny service if together they cost more than the system can supply. A distributed denial of service (DDoS) uses many machines at once.

The idea

A device runs small programs that others may supply, and runs one of them each time a message arrives. Each program is checked before it is accepted: it can touch only its own memory, and it always finishes. One accepted program performs a long but finite computation that takes 2 ms per run. If messages arrive 600 times per second, the program needs 600×2=1,200600 \times 2 = 1{,}200 ms of processor time every second, more than the 1,000 ms that a second contains. If the program runs at a higher priority than the device’s other tasks, those tasks get no processor time at all. This is starvation §9.18: a task waits without end for a resource that others keep taking. Every check passed, and the device has stopped doing its job.

Checks on one request and capacity for all requests are different questions. Memory safety, termination and authentication §1.6 each decide whether one request is allowed. Denial of service concerns the total: what every admitted request costs, how often requests come, and what is left for everything else. A one-lane road is a fair picture: every truck on it is legal, yet a slow convoy keeps an ambulance from getting through. The picture stops being accurate in one respect: on a network an attacker can send the convoy at almost no cost, from many places at once.

How it works

Denial of service works in a few distinct ways.

A defense takes the same steps for each scarce resource.

  1. Name the resource and every path by which outside input can consume it.

  2. Bound the cost of one request, and count each expensive operation at its real cost, not as one step.

  3. Bound the number of requests: rate limiting §9.38 caps how many are admitted per unit of time, and a fixed maximum caps how many are in progress at once.

  4. Make cheap checks before expensive work, and reject early.

  5. Reserve capacity for essential work, through scheduling priority, a fixed time share or a separate pool, so that admitted work cannot take everything.

  6. Make every timeout §9.34 release what it guards, and keep a recovery path that does not compete for the exhausted resource.

Worked example

A device’s interpreter §2.13 runs a supplied program at 25 ns per instruction, and an instruction budget §2.32 stops each run after at most 10,000 instructions. One run therefore costs at most 10,000×25=250,00010{,}000 \times 25 = 250{,}000 ns, which is 0.25 ms.

The per-run budget alone did not prevent this; a limit on the rate is needed as well.

Now let the program call a helper function §2.19, a routine of the device’s own code that programs may call. This helper writes to flash memory §6.6 and takes 0.5 ms, but the budget counts each call as one instruction. A run with 8 calls costs at most 0.25+8×0.5=4.250.25 + 8 \times 0.5 = 4.25 ms. To keep the program within 250 ms of processor time per second, the device may allow at most 250/4.25≈58.8250 / 4.25 \approx 58.8 runs per second, so the limit is 58. A designer who counted each call as one instruction would set the limit at 1,000 runs per second, which in fact demands 1,000×4.25=4,2501{,}000 \times 4.25 = 4{,}250 ms of processor time per second, more than four times what exists.

Stated precisely

Take one resource with capacity CC per second; for the time of one processor, CC is 1 second per second. Let work of kind ii arrive at rate λi\lambda_i items per second, with worst-case cost wiw_i per item, measured on the actual hardware and including every helper call, lock hold and wait. Let RR be the capacity that essential work needs, and let AA be the set of kinds of work that an attacker can trigger or supply. Essential work keeps its capacity only if ∑i∈Aλiwi≤C−R.\sum_{i \in A} \lambda_i\, w_i \le C - R. Both λi\lambda_i and wiw_i must be bounded: a bound on one factor leaves the product unbounded.

Total capacity is not the only condition. Let essential work need its result within time DD and run for at most EE itself. In the simplest case, one essential task and nothing else competing, the longest time BB for which one attacker-influenced item can keep the processor from the essential task, because it runs at higher priority or cannot be paused, must satisfy B+E≤DB + E \le D. The same two conditions apply to memory, connection slots and queue entries, with sizes and holding times in place of processor time.

Limits and common mistakes

No finite system serves unlimited hostile demand. Traffic that fills a network link or a radio channel arrives before any check runs, and radio jamming, transmitting noise on the channel, cannot be stopped by any protocol check.

Valid does not mean affordable. A program that passed memory-safety and termination checks, or a correctly authenticated request, can still cost more than the system can pay.

Termination is not a time bound. A program that always finishes may still run longer than anyone can wait.

Defenses cost resources too. Verifying a signature on every incoming message is expensive work that an attacker can trigger with invalid signatures; a cheaper check first, such as a length check or a fast keyed tag, limits that.

A timeout that does not release its resource changes nothing: if a stuck operation keeps its memory or its lock, the caller’s timeout only stops the waiting.

Denial of service can outlast the attack. An input that is stored and processed again at every start keeps the device down after the attacker leaves, and forced writes can wear out flash memory for good.

A claim of resistance must name its load: which requests, at what rate, from how many sources, and what service essential work is guaranteed meanwhile.

Questions answered

Can a valid but expensive program starve unrelated work?

Yes. A program that passes every check for memory safety, termination and authenticity can still starve unrelated work, because those checks limit what one run may do, not how much processor time, memory and shared resources all runs take together.

It starves other work in two ways. The first is when the rate of runs, multiplied by the worst-case cost of one run including helper calls, lock holding and waiting, exceeds the share of the processor that the other work can give up. The second is when one run keeps the processor, at a higher priority or without the possibility of being paused, longer than the other work can wait. Preventing both needs four explicit limits: a per-run budget that charges expensive calls at their real cost, a limit on how often the program runs, a scheduling rule that reserves a share of the processor for the other work, and caps on the memory, locks and queue entries the program can hold.

Related entries: Instruction budget (fuel) (§2.32), Termination versus time bound (§2.33), Resource confinement (§2.40), Rate limiting (§9.38), Availability (§1.10), Starvation (§9.18), Jamming versus protocol DoS (§7.40).