Section 20.10

Tree 10: “If memory is safe, can malicious code still deny service?”

Setting

A sensor gateway is a small device that collects readings from sensors and passes them on. In this invented example the gateway also accepts a small decision program, delivered through a phone from a publisher, the one party authorized to change the gateway’s rules. The gateway’s own software, the host, runs the decision program, the guest, inside a virtual machine §2.3 (VM), a part of the host that carries out the guest’s instructions one at a time. For every management request, a request to change one of the gateway’s settings, the host runs the guest, which answers ALLOW or DENY. Meanwhile the gateway keeps sampling its sensors and handling radio traffic.

It has been established that the guest cannot read or write memory outside the regions the host gave it. To stop endless loops, the VM gives each run an instruction budget §2.32, also called fuel, of 1000 guest instructions and stops the run when the budget is used up. The guest may call helper functions §2.19, host routines offered to it, and the slowest helper takes up to 300 microseconds. Suppose an attacker has got a malicious guest accepted, or the publisher has shipped a harmful one. The question is whether a guest that cannot corrupt memory can still deny service.

Short answer

Yes. Memory safety limits where the guest reads and writes, not how much it consumes or what it decides. A confined guest can spend its whole budget on every run, call slow helpers, start work that outlives the run, fill host queues, or answer DENY to every request. Each of these is a denial of service §1.28: the device stops being useful to its legitimate users. Each resource needs its own limit and accounting, and the owner needs a way to override the guest’s decisions.

Follow-up questions

First answer

Yes. Memory safety, the guarantee that a downloaded program, the guest, never touches memory outside the regions it was given, says nothing about the resources the guest uses or the decisions it makes. A confined guest can still:

Each of these is a denial of service, a loss of availability §1.10. Each resource needs its own limit, charged on every path that uses it, which is complete mediation §1.16 applied to resources. The last case needs a recovery authority §1.46 as well: a way, not subject to the guest’s own verdict, for the owner or publisher to replace the guest.

Does fuel solve it?

No. Fuel bounds one quantity, the number of guest instructions in one run, and denial of service has other sources. Fuel, also called an instruction budget, is a counter that the virtual machine (VM) running a downloaded program, the guest, decreases for every guest instruction it executes; at zero the VM stops the run. If every path that executes guest instructions decreases the counter, including backward jumps and calls between the guest’s own functions, then a run executes at most the budget, say 1000 instructions. That guarantees that the guest’s own instructions cannot keep a run going forever. It does not bound:

Turning fuel into a time bound needs more: a maximum time per instruction, a bound on each helper’s running time with no unlimited waits, limits on work that continues after the run, and a model of scheduling and interference.

Write a conditional time bound

A conditional time bound is an upper limit on running time that holds only when named assumptions hold. Take one run of a downloaded program, the guest, inside a virtual machine (VM), from the moment the VM starts the guest until the guest’s verdict is returned. Define:

If these parts do not overlap, so that no time is counted twice, the run time TT satisfies T≤Sc+Hh+F+I.T \le S c + H h + F + I. With the values above, Sc=1000×2=2000S c = 1000 \times 2 = 2000 microseconds and Hh=2×300=600H h = 2 \times 300 = 600 microseconds, so T≤2000+600+100+500=3200T \le 2000 + 600 + 100 + 500 = 3200 microseconds, which is 3.2 milliseconds.

This is a bound derived from assumptions, not a measured time, and each term needs its own justification. cc must cover the slowest instruction, such as a division, including any time the processor waits for memory. HH must be enforced, for example by limiting the number of helper calls per run. hh needs an analysis of each helper. II needs a bound on how often each interrupt and each higher-priority thread can arrive and how long each takes. A longer run lets more interference arrive, so II must be computed for a time window at least as long as the resulting TT; fixed-priority response-time analysis §19.4.7 does this by recomputing the bound until its value stops changing.

Why can pacing help and still fail a deadline?

Pacing caps the share of the processor that a kind of work can take, but it does so by making requests wait, and a request that waits too long misses its deadline. Pacing, a form of rate limiting §9.38, starts work at no more than a fixed rate. Suppose each run of a downloaded decision program takes at most 3.2 milliseconds and a gateway starts at most one run every 4.5 milliseconds. Decision runs can then use at most 3.2/4.5≈0.713.2 / 4.5 \approx 0.71, about 71%, of the processor however many requests arrive, and the rest remains for sensor sampling and radio work. That is the help.

Now three requests arrive together, a burst, and each needs its answer within 10 milliseconds of arrival, its deadline. Runs are served in arrival order.

The response time §9.32 of request 3, from arrival to answer, is 12.2 milliseconds: 9 milliseconds of waiting plus 3.2 milliseconds of running. It misses the 10-millisecond deadline by 12.2−10=2.212.2 - 10 = 2.2 milliseconds. If such bursts come once a minute, the average load is 3×3.2=9.63 \times 3.2 = 9.6 milliseconds of work in every 60,000 milliseconds, about 0.016%. A low average says nothing about the worst response. An attacker who can send requests can also create bursts on purpose and push legitimate requests to the back of the queue.

A guarantee on response time needs a model of arrivals (the largest burst and the long-run rate), the worst-case service time of each request, the interference from other work, and the time spent waiting for resources that other work holds. Pacing supplies part of the arrival model; it guarantees no deadline by itself.

Does stopping a process after 40 seconds prove a 40-second WCET §9.33?

No. The worst-case execution time (WCET) of a computation is the longest time it can take, over every input and starting state, on the given hardware, when it runs without interruption. A rule that stops a process after 40 seconds is a timeout §9.34: it decides how long the caller is willing to wait, and it says nothing about how long the computation needs.

What the rule can give, once cancellation §9.29 is enforced and confirmed, is a bound on how long one attempt occupies the system: at most 40 seconds plus the time to cancel, whether the attempt completed or not. A 40-second WCET needs a different argument: an analysis of the longest path through the computation, with the cost of every step and every wait bounded.

Related entries: Instruction budget (fuel) (§2.32), Resource confinement (§2.40), Deadline versus timeout (§9.34), Schedulability (§9.37). Further reading: [89].