Section 17.7

Authentication does not establish safe behavior

Question

Why validate code or a policy after its authentication §1.6 tag verifies?

Short answer

Validation is needed because a verified tag proves where the bytes came from, not what they will do. An authentication tag is a short value that only a holder of the key can compute over exactly these bytes; a verified tag shows only that a key holder tagged them. An authorized author can still ship a mistake, such as an out-of-bounds access or an endless loop, and anyone who steals the key can tag hostile code. Validation checks the properties safety needs, so the device stays safe either way.

Terms in the question

Full answer

Step 1: what a verified tag establishes. A MAC algorithm treats its input as a string of bytes whose meaning it never reads. When the tag verifies, the receiver learns one fact: a holder of the key computed this tag over exactly these bytes. A digital signature gives the same fact, with the holder of the private key in place of a holder of the shared key. The fact rests on two assumptions: the key has stayed secret, and the algorithm §14.1 resists forgery, meaning that nobody without the key can compute a valid tag for bytes that a key holder never tagged. Nothing in the tag check reads the bytes as instructions or rules, so the tag check cannot tell whether using them is safe.

Step 2: what safety needs. Safety is a property of the content. For a program, safety means that every memory access stays inside a region the program was given, every call goes to a helper function §2.19 that the host permits, every jump lands on an instruction of the program, and every run ends within a set limit. A helper function is a function of the host that the program may call. For a policy, safety means that every value lies in its allowed range, every reference names an entry that exists, and the rules do not contradict each other. Only a check that reads the content can establish these properties.

Step 3: authentic content can be unsafe. There are three common ways.

  1. An honest mistake. An authorized author writes a bug, a compiler produces wrong output, or the content was built for a different version of the device software, whose memory layout differs. The author tags whatever the build produced, so the tag verifies.

  2. A stolen or misused key. An attacker who steals the key, or an insider who holds it, can tag hostile content. The tag on that content is mathematically valid.

  3. An old version sent again. A program that was once authentic and was later withdrawn for a flaw still carries its valid tag. Unless the tag covers a version number that the device compares with the last version it accepted, the device accepts the old program again.

Step 4: validation limits what a key can do. Without validation, the safety of the device depends on every key holder and every build tool being correct, and a stolen key lets its thief make the device do anything the device can do. With validation, a careless or hostile key holder can make the device do only what a valid program or policy may do. The two checks fail for different reasons: authentication keeps out strangers, and validation keeps a mistake or a stolen key from crashing or corrupting the device. Layering checks that fail for different reasons is called defense in depth §1.18.

Step 5: order the checks, and check the bytes that will be used. Verify the tag first. Tag verification is cheap, and it keeps bytes from strangers away from the validator, which is more complex and therefore more likely to contain bugs. This shrinks the attack surface §1.5, the code that an outsider can reach with input of the outsider’s choice. The validator must still be safe for every possible input, because a key thief can reach it. Next, check authorization §1.7: whether this key holder may make this change to this device. Then validate, and only then use the content. All of these checks must apply to the copy of the bytes that will actually be used. Copy the content once into memory that nothing else can change, then verify, validate and use that one copy. Otherwise the device can check one copy and use another, a time-of-check to time-of-use §9.26 (TOCTOU) error.

Worked example

A device gives each program one input region of 8 bytes, at offsets 0 to 7. An authorized developer means to load 4 bytes from offset 4 but writes offset 7 by mistake. The developer’s build machine computes the tag over the program bytes with the shared key and sends the program and the tag.

  1. The device recomputes the tag over the received program bytes with its own copy of the key. The bytes are exactly the bytes the developer tagged, so the two tags are equal, and the tag verifies.

  2. The validator works out which bytes the load touches: offsets 7 to 7+4−1=107 + 4 - 1 = 10, that is offsets 7, 8, 9 and 10. From offset 7 to the end of the region, 8−7=18 - 7 = 1 byte remains, and the load needs 4 bytes. The test 4≤14 \le 1 is false, so the validator rejects the program.

  3. Without validation, the load would also read offsets 8, 9 and 10, which lie outside the region. If other data sits at those addresses, the program reads data it was never given. If no memory exists there, the processor raises a fault, and the device may stop.

A policy fails in the same way. Suppose a device holds a table of 8 rules, numbered 0 to 7, and an authentic policy selects rule 9 because its author used a newer table of 12 rules. The tag verifies, because the author tagged exactly those bytes. A range check tests 9<89 < 8, finds it false and rejects the policy. Without the range check, the device would read the entry 9−7=29 - 7 = 2 places past its last rule, in memory that belongs to something else.

Follow-up questions and limits

If the device validates everything, why authenticate at all? Validation establishes safety, not intent. A program that an attacker writes can pass every safety check and still do harm that the rules permit, such as refusing every legitimate request. Authentication and authorization decide whose intentions the device follows; validation decides whether following them is safe.

Could the developer validate before tagging instead? Validation on the build machine catches mistakes early and is worth doing. If it is the only validation, the safety of the device rests on that machine, its tools and the secrecy of the key, and the rules that the build machine checks must match the device software exactly. Validation on the device removes all of these from the trusted computing base §1.4, the set of components whose correctness the safety of the device depends on.

Does a digital signature instead of a MAC change the answer? No. A signature changes who can create a valid tag: only the holder of the private key, while devices hold only the public key. A signature still says nothing about what the content does.

Does validation prove the content correct? No. Validation establishes the listed safety properties §1.11. A program can pass validation and still make wrong decisions; finding those is the job of testing and review.

This answer does not describe how a validator works. Two designs are a verifier, which proves the rules for every path through the program before it runs, and a runtime bounds check §2.27, which tests each memory access at the moment the program makes it.

Fullest treatment: Bytecode authenticity versus safety (§2.43).

Related entries: Authentication (§1.6), Authorization (§1.7), Authentication coverage (§5.41), Runtime bounds check (§2.27), Structural bytecode admission (§2.26), Defense in depth (§1.18), Time-of-check to time-of-use (TOCTOU) (§9.26), eBPF verifier (§3.3).