The Multi-Stage Secure Boot Chain
A large chip starts several programs in a row. Each one checks the next before it jumps, with a key that it brought itself. One refusal stops the row where it stands.
You Will Be Able To
- Follow a boot through three checked stages, and name the verifier and the key of each check.
- Tell an image with a bad signature from a good image that is too old.
- Say who has control after a refusal, and what starts the chain again.
- Lesson
- S10.15
- Time
- 25 min
- Runs on
- Your browser
- Check
- 5 questions
A signed update goes out to a million phones. One of them stays dark: no logo, no console, nothing.
Its image is genuine, and the signature is right. Some stage of the boot looked at it and still said no.
Before You Start
You need Secure Boot, Life Cycle and Debug Lock: the root of trust, the signature, the version floor and rollback.
You need The Boot Flow: the Boot ROM, the loader, an image and the handover.
You need The Secure World: the secure world, the normal world and the monitor.
| Question | |
|---|---|
| 1 | Why does the Boot ROM not check every program itself? |
| 2 | Where does a stage get the key for its check? |
| 3 | An image has a correct signature and is refused. Why? |
| 4 | A stage refuses an image. Who has control afterwards, and until when? |
| 5 | The operating system is one version below its floor. What does the lab print last? |
The Idea: Each Stage Checks the Next
On ap_soc the Boot ROM checked one image and jumped to it. A phone starts several programs in a row: a loader, then the secure firmware with its monitor, then the operating system. Different teams write them, and each is updated at its own pace.
The Boot ROM cannot check them all. It can never be changed, so it must stay small and know little. If it knew the form of the operating system, every change of that form would need a new chip.
So the check is passed on, like a baton. The Boot ROM checks the loader only. The loader, now trusted, checks the monitor. The monitor checks the operating system. Each running stage checks the next one, and only then jumps. Such a row is called a chain of trust.
Every check needs a key. If the image brought the key along, the check would prove nothing. So the key comes from the stage that checks. The Boot ROM holds the first one, and each checked image carries the key for the stage after it.
Each stage also has a version floor of its own. And when a stage refuses an image, the chain stops right there until the next reset.
New Words
| Word | Meaning |
|---|---|
| Boot stage | One program in the row of programs that start a chip. Here: the Boot ROM, the loader, the monitor, the operating system. |
| Verifier | The stage that is running and checks the next image. |
| Candidate image | The image that is offered to the verifier. Candidate for short. |
| Checking key | What a verifier needs to check a signature. It is enough to check one, and useless for making one. |
| Root key | The first checking key. It is fixed in the Boot ROM or in one-time memory. |
| Handed-on key | A checking key that a checked image carries inside it, for the check of the stage after it. |
| Latched stop | A refusal that stays. The verifier accepts no further image until the next reset. |
| OS | Short for operating system. The lab prints it as os. |
One Picture: Three Checks in a Row
- Memory
- Power
- Processor
- The root
After reset the Boot ROM runs. Nobody checked it, and nobody can change it. It holds the first key.
- The first check
The Boot ROM checks the loader with key 12, and nothing else. If the check passes, it jumps.
- The key moves on
The loader was checked, so what it carries can be trusted. It carries key 34, and checks the monitor with it.
- The last check
The monitor checks the operating system with key 56. The jump that follows leaves the secure world.
- A floor for each stage
Each check also compares the version of the image with a floor. The floors live in one-time memory, outside every image.
Read the diagram as text
- Boot ROM: cannot be changed; holds key 12
- Loader: carries key 34 inside it
- Monitor: carries key 56 inside it
- Operating system: the last stage, in the normal world
- One-time memory: holds a version floor for each stage
- Boot ROM → Loader: checks with key 12
- Loader → Monitor: checks with key 34
- Monitor → Operating system: checks with key 56
- One-time memory → Boot ROM: floor
- One-time memory → Loader: floor
- One-time memory → Monitor: floor
The key numbers are those of the lab, in hex. They are names of keys, not keys.
The Smallest Example, Worked by Hand
No simulator yet. The floors are 4 for the loader, 7 for the monitor and 2 for the OS. A version passes if it is at the floor or above it. First a boot in which every image is good.
| Verifier | Its key | Candidate | Signature | Version and floor | After the check |
|---|---|---|---|---|---|
| Boot ROM | 12 | Loader | good | 4 and 4 | the loader runs |
| Loader | 34 | Monitor | good | 7 and 7 | the monitor runs |
| Monitor | 56 | OS | good | 9 and 2 | the OS runs |
Now the update of the dark phone. Its package holds an older monitor, version 6. The signature is genuine.
| Verifier | Its key | Candidate | Signature | Version and floor | After the check |
|---|---|---|---|---|---|
| Boot ROM | 12 | Loader | good | 4 and 4 | the loader runs |
| Loader | 34 | Monitor | good | 6 and 7 | refused: the loader keeps control |
| Loader | 34 | Monitor, a newer one | good | 9 and 7 | refused: the stop is latched |
The second row is the surprise. Nothing is wrong with the signature. The image is simply older than this phone still accepts. The third row is the other surprise: a good image, offered too late, changes nothing. Only a reset starts the chain again.
The Rules
Rule 1: The first verifier is code that cannot be changed, and it holds the root key.
Every later check rests on it.
Rule 2: Each running stage checks the next image before the jump, and checks only that one.
So the Boot ROM needs to know the loader and nothing after it.
Rule 3: The key for a check comes from the verifier, never from the candidate.
A checked image may carry the key for the stage after it.
Rule 4: Each stage has a version floor of its own.
A version passes at the floor or above it. A correct signature does not help an image below the floor.
Rule 5: A refusal is latched.
The verifier keeps control, nothing later runs, and only a reset starts the chain again.
Rule 6: The last jump enters the normal world.
Every stage before it ran in the secure world, and the monitor stays there.
Sources for These Rules
Rules 1, 3 and 4 apply the rules of the earlier lesson on secure boot to more than one stage.
No standard for secure boot or for version floors is in the library of this site. The chain of three stages, the latched stop and rule 6 are given as common usage.
The names of the stages follow the lessons of this track. Real chips use other names and often more stages.
Now Run It
The lab at the end of this page boots three times. The first boot has a loader with one changed byte. The second is the old monitor of the hand table. The third is the good boot.
reset stage=0
offer=loader key=12 verify=0 version=4 floor=4 stage=0 stopped=1
reset stage=0
offer=loader key=12 verify=1 version=4 floor=4 stage=1 stopped=0
offer=monitor key=34 verify=1 version=6 floor=7 stage=1 stopped=1
offer=monitor key=34 verify=1 version=9 floor=7 stage=1 stopped=1
reset stage=0
offer=loader key=12 verify=1 version=4 floor=4 stage=1 stopped=0
offer=monitor key=34 verify=1 version=7 floor=7 stage=2 stopped=0
offer=os key=56 verify=1 version=9 floor=2 stage=3 stopped=0Rule 2 at work, in the second row. One byte of the loader is wrong, so verify=0. The stage stays 0: the Boot ROM never jumped.
Rule 3, in the key column. The loader is checked with key 12, the monitor with 34 and the OS with 56. Each key belongs to the stage that was running.
Rule 4, in the fifth row. It says verify=1 and still stopped=1, because version=6 is below floor=7. In the third boot, version=7 meets floor=7 and the stage goes to 2.
Rule 5, in the sixth row. Version 9 would pass, and the stage stays 1. The stop of the row before is latched.
The last row is the hand-off of rule 6: stage=3, and the OS runs.
This lab leaves things out. Its tag is a sum that anybody can work out, where a real chip checks a signature. No instruction runs. And it shows no world: the stage is only a number.
Why It Is Built This Way
| Choice | The alternative | Its cost |
|---|---|---|
| A chain of checks | The Boot ROM checks every image | The ROM would have to know every later image. It cannot be changed, so each new form would need a new chip. |
| The key from the verifier | The key inside the candidate | Anybody can sign with a key of his own. The check would accept every image. |
| A floor for each stage | One floor for all images | A repair of the OS would raise the floor for the loader too. Every image would have to be released at once. |
| A latched stop | Try the next offer | An attacker could feed images until one slips through, on a chip that is already half started. |
The chain has a weak point by design: it is only as good as its first link. A fault in the Boot ROM cannot be repaired in any phone already sold.
The Trap: The Update That Left One Phone Dark
Back to the dark phone. Months ago a security update raised its floor for the monitor to 7. The new package was built from an older branch and still held monitor 6. Every signature in it was right.
The loader refused the monitor, and so no OS ever ran. A console belongs to the OS, so the phone had no way to say what was wrong. The cause was not in the image. It was in a floor on that one phone.
The second trap is the floor that is raised too early. Raise it first, lose power before the new image is stored, and no image on the phone passes any more. Store and check the new image, and only then raise the floor.
The third trap is the image that changes after its check. The signature was right for the bytes that were read. If another manager can still write that memory before the jump, other bytes will run.
At Scale
This section looks ahead, to updates, to lost keys and to the time a boot takes.
Two copies
A phone keeps two copies of each image. An update is written to the copy that is not running. If the new one is refused, the old one still starts.
A key that must go
A signing key can leak. Then the chip must stop trusting it. Bits of one-time memory mark a key as withdrawn, and the chain uses the next one.
The time of a check
A check reads every byte of an image. For large images that takes a visible part of the start. A crypto engine does that work faster than a core.
Still a separate door
A boot that reaches the OS says that the software is genuine. It opens no debug port. That door has its own lock.
Try It
Run the lab. It boots three times. Find the stage at which each boot ends.
In the second boot, change the floor of the first monitor offer from 7 to 6. Predict the stage after that offer and after the next one.
In the third boot, change the first number of the monitor offer from 42 to 43. That is one changed byte of the image. Predict where the boot ends.
Names Printed by the Lab
| Name | Meaning |
|---|---|
| reset | A reset of the chain. The Boot ROM runs again. |
| offer | The image that is offered to the running stage: loader, monitor or os. |
| key | The number of the key that the running stage used, in hex. |
| verify | 1 if the tag of the image fits the image, its version and that key. |
| version, floor | The version in the image, and the lowest version that this stage accepts. |
| stage | Who has control after the offer: 0 the Boot ROM, 1 the loader, 2 the monitor, 3 the operating system. |
| stopped | 1 once a stage has refused an image. It stays 1 until the next reset. |
Sources and What the Lab Leaves Out
The chain is a small circuit, boot_handoff: a counter for the stage and one bit for the stop. No instruction runs.
The tag is a sum of the image byte, the key number and the version. It stands in for a signature, and anybody can work it out. A real check needs cryptography.
The bench hands each floor to the circuit. On a real chip the floors are read from one-time memory.
reset stage=0 offer=loader key=12 verify=0 version=4 floor=4 stage=0 stopped=1 reset stage=0 offer=loader key=12 verify=1 version=4 floor=4 stage=1 stopped=0 offer=monitor key=34 verify=1 version=6 floor=7 stage=1 stopped=1 offer=monitor key=34 verify=1 version=9 floor=7 stage=1 stopped=1 reset stage=0 offer=loader key=12 verify=1 version=4 floor=4 stage=1 stopped=0 offer=monitor key=34 verify=1 version=7 floor=7 stage=2 stopped=0 offer=os key=56 verify=1 version=9 floor=2 stage=3 stopped=0Read included file: soc-s107-boot.sv
// Each verdict stands for verification of the exact candidate and its signed
// version with the key delegated by the current stage. No cryptography here.
module boot_handoff (
input logic clk, reset, check_image, verified,
input logic [3:0] image_version, minimum_version,
output logic [1:0] stage,
output logic stopped
);
always_ff @(posedge clk) begin
if (reset) begin
stage <= 0;
stopped <= 0;
end else if (check_image && !stopped && stage != 3) begin
if (verified && image_version >= minimum_version)
stage <= stage + 1'b1;
else
stopped <= 1;
end
end
endmodule
// Policy slice: one protected control word and one normal console word.
module world_port (
input logic request, secure,
input logic [31:0] address,
output logic sysctl_write, uart_write
);
assign sysctl_write = request && secure && address == 32'h10004000;
assign uart_write = request && !secure && address == 32'h10000000;
endmodule
// Exercise a separate debug requester. A reset closes the service session.
module service_debug (
input logic clk, reset, service_lifecycle, authenticated, read_request,
output logic read_grant
);
logic session;
always_ff @(posedge clk) begin
if (reset || !service_lifecycle)
session <= 0;
else if (authenticated)
session <= 1;
end
assign read_grant = read_request && service_lifecycle && session && !reset;
endmodule
Check Yourself
Common Mistakes
Wrong Let an image bring the key that checks it.
Anybody can sign with a key of his own.
Fix Use a key that the verifier already holds.
Wrong Accept every image with a correct signature.
A genuine image can be older than the floor.
Fix Check the version against the floor of that stage, at every hand-off.
Wrong Offer a better image after a refusal and expect a boot.
The stop is latched.
Fix Reset, and start the chain from the Boot ROM.
Remember
- Each running stage checks the next image before the jump, and only that one.
- The key for a check comes from the verifier, never from the candidate.
- Each stage has a floor of its own. A correct signature does not help an image below it.
- A refusal is latched: the verifier keeps control until reset.