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.

Five questions this page answers
Question
1Why does the Boot ROM not check every program itself?
2Where does a stage get the key for its check?
3An image has a correct signature and is refused. Why?
4A stage refuses an image. Who has control afterwards, and until when?
5The 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

New words on this page
WordMeaning
Boot stageOne program in the row of programs that start a chip. Here: the Boot ROM, the loader, the monitor, the operating system.
VerifierThe stage that is running and checks the next image.
Candidate imageThe image that is offered to the verifier. Candidate for short.
Checking keyWhat a verifier needs to check a signature. It is enough to check one, and useless for making one.
Root keyThe first checking key. It is fixed in the Boot ROM or in one-time memory.
Handed-on keyA checking key that a checked image carries inside it, for the check of the stage after it.
Latched stopA refusal that stays. The verifier accepts no further image until the next reset.
OSShort for operating system. The lab prints it as os.

One Picture: Three Checks in a Row

Three Checks in a RowStep through the picture. It starts with the Boot ROM alone and adds one checked stage at a time.
  • Memory
  • Power
  • Processor
Three Checks in a RowStep through the picture. It starts with the Boot ROM alone and adds one checked stage at a time. component Boot ROM cannot be changed;holds key 12 component Loader carries key 34 insideit component Monitor carries key 56 insideit component Operating system the last stage, in thenormal world component One-time memory holds a version floorfor each stage checks with key 12checks with key 34checks with key 56floorfloorfloor
  1. component Boot ROMcannot be changed; holds key 12
    • checks with key 12 → Loader
  2. component Loadercarries key 34 inside it
    • checks with key 34 → Monitor
  3. component Monitorcarries key 56 inside it
    • checks with key 56 → Operating system
  4. component Operating systemthe last stage, in the normal world
  5. component One-time memoryholds a version floor for each stage
    • floor → Boot ROM
    • floor → Loader
    • floor → Monitor
  1. The root

    After reset the Boot ROM runs. Nobody checked it, and nobody can change it. It holds the first key.

  2. The first check

    The Boot ROM checks the loader with key 12, and nothing else. If the check passes, it jumps.

  3. 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.

  4. The last check

    The monitor checks the operating system with key 56. The jump that follows leaves the secure world.

  5. 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.

A good boot, by hand
VerifierIts keyCandidateSignatureVersion and floorAfter the check
Boot ROM12Loadergood4 and 4the loader runs
Loader34Monitorgood7 and 7the monitor runs
Monitor56OSgood9 and 2the OS runs

Now the update of the dark phone. Its package holds an older monitor, version 6. The signature is genuine.

An old monitor, by hand
VerifierIts keyCandidateSignatureVersion and floorAfter the check
Boot ROM12Loadergood4 and 4the loader runs
Loader34Monitorgood6 and 7refused: the loader keeps control
Loader34Monitor, a newer onegood9 and 7refused: 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

  1. Rule 1: The first verifier is code that cannot be changed, and it holds the root key.

    Every later check rests on it.

  2. 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.

  3. 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.

  4. 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.

  5. Rule 5: A refusal is latched.

    The verifier keeps control, nothing later runs, and only a reset starts the chain again.

  6. 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.

Printed by the lab on Icarus. Each reset starts a boot. Each offer is one check.
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=0

Rule 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

ChoiceThe alternativeIts cost
A chain of checksThe Boot ROM checks every imageThe 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 verifierThe key inside the candidateAnybody can sign with a key of his own. The check would accept every image.
A floor for each stageOne floor for all imagesA repair of the OS would raise the floor for the loader too. Every image would have to be released at once.
A latched stopTry the next offerAn 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 lab3 checks of 1 byte
A phonemany stages, each of millions of bytes

This section looks ahead, to updates, to lost keys and to the time a boot takes.

  1. 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.

  2. 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.

  3. 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.

  4. 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
NameMeaning
resetA reset of the chain. The Boot ROM runs again.
offerThe image that is offered to the running stage: loader, monitor or os.
keyThe number of the key that the running stage used, in hex.
verify1 if the tag of the image fits the image, its version and that key.
version, floorThe version in the image, and the lowest version that this stage accepts.
stageWho has control after the offer: 0 the Boot ROM, 1 the loader, 2 the monitor, 3 the operating system.
stopped1 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.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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=0
Read 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

Predict the outputIn this run the loader and the monitor pass. Then an OS of version 1 is offered against a floor of 2, with a correct tag. Then the good OS of version 9 is offered. What is the last line? Its form is: offer=os key=56 verify=.. version=9 floor=2 stage=.. stopped=..
module tb;
  bit clk, reset, check_image;
  logic [7:0] payload, supplied_tag;
  logic [3:0] image_version, minimum_version;
  wire [1:0] stage;
  wire stopped;
  // The key that the running stage holds. Stage 0 is the Boot ROM.
  wire [7:0] key_id = stage == 0 ? 8'h12 : stage == 1 ? 8'h34 : 8'h56;
  // A stand-in for a signature check: anybody can work this sum out. A real check needs cryptography.
  wire verified = supplied_tag == (payload ^ key_id ^ {4'b0, image_version});
  boot_handoff chain (.*);
  always #5 clk = !clk;

  task automatic restart;
    @(negedge clk);
    reset = 1;
    @(negedge clk);
    reset = 0;
    $display("reset stage=%0d", stage);
  endtask

  // The running stage is offered the next image. It checks the tag with its own key, and the version against a floor.
  task automatic offer(input string name, input logic [7:0] image_byte, tag, input int version, floor_version);
    logic [7:0] key;
    bit verdict;
    payload = image_byte;
    supplied_tag = tag;
    image_version = version;
    minimum_version = floor_version;
    check_image = 1;
    #1;
    key = key_id;
    verdict = verified;
    @(negedge clk);
    check_image = 0;
    $display("offer=%s key=%02h verify=%b version=%0d floor=%0d stage=%0d stopped=%b",
             name, key, verdict, image_version, minimum_version, stage, stopped);
  endtask

  initial begin
    restart;
    offer("loader", 8'h41, 8'h57, 4, 4);
    offer("monitor", 8'h42, 8'h71, 7, 7);
    offer("os", 8'h43, 8'h74, 1, 2);
    offer("os", 8'h43, 8'h1c, 9, 2);
    $finish;
  end
endmodule
Read 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
ConceptWhy does the Boot ROM not check every program itself?
ConceptWhere does a stage get the key for its check?
ConceptAn image has a correct signature and is refused. What is the likely reason?
ConceptThe loader refuses the monitor. Who has control, and until when?

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.

Practice

Report a problem with this page