blob: c13a3db375022db136f947452e189cd883da65f8 [file] [log] [blame]
Clay Murphyfcf8f182015-03-11 22:43:31 -07001page.title=Verifying Boot
Clay Murphy0d596682014-10-23 12:06:03 -07002@jd:body
3
4<!--
Clay Murphybc8a22a2015-03-02 18:49:17 -08005 Copyright 2015 The Android Open Source Project
Clay Murphy0d596682014-10-23 12:06:03 -07006
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
19<div id="qv-wrapper">
20 <div id="qv">
21 <h2>In this document</h2>
22 <ol id="auto-toc">
23 </ol>
24 </div>
25</div>
Clay Murphy0d596682014-10-23 12:06:03 -070026
Clay Murphybc8a22a2015-03-02 18:49:17 -080027<p>Verified boot guarantees the integrity of the device software starting from a
28hardware root of trust up to the system partition. During boot, each stage
29verifies the integrity and authenticity of the next stage before executing it.</p>
Clay Murphy0d596682014-10-23 12:06:03 -070030
Clay Murphybc8a22a2015-03-02 18:49:17 -080031<p>This capability can be used to warn users of unexpected changes to the
32software when they acquire a used device, for example. It will also provide an
33additional signal of device integrity for remote attestation, and together with
34encryption and Trusted Execution Environment (TEE) root of trust binding, adds
35another layer of protection for user data against malicious system software.</p>
Clay Murphy0d596682014-10-23 12:06:03 -070036
Danielle Roberts1a1441a2016-06-17 13:50:20 -070037<p>If verification fails at any stage, the user is visibly
38notified.</p>
Clay Murphy0d596682014-10-23 12:06:03 -070039
Clay Murphybc8a22a2015-03-02 18:49:17 -080040<h2 id=glossary>Glossary</h2>
Clay Murphy0d596682014-10-23 12:06:03 -070041
Clay Murphybc8a22a2015-03-02 18:49:17 -080042<table>
Danielle Roberts1a1441a2016-06-17 13:50:20 -070043 <col width="15%">
44 <col width="85%">
Clay Murphybc8a22a2015-03-02 18:49:17 -080045 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -070046 <th>Term</th>
47 <th>Definition</th>
Clay Murphybc8a22a2015-03-02 18:49:17 -080048 </tr>
49 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -070050 <td>Boot state</td>
51 <td>The boot state of the device describes the level of protection provided
52 to the end user if the device boots. Boot states are GREEN, YELLOW,
53 ORANGE, and RED.</td>
Clay Murphybc8a22a2015-03-02 18:49:17 -080054 </tr>
55 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -070056 <td>Device state</td>
57 <td>The device state indicates how freely software can be flashed to the device.
58 Device states are LOCKED and UNLOCKED.</td>
Clay Murphybc8a22a2015-03-02 18:49:17 -080059 </tr>
60 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -070061 <td>dm-verity</td>
62 <td>Linux kernel driver for verifying the integrity of a partition at runtime using
63 a hash tree and signed metadata.</td>
Clay Murphybc8a22a2015-03-02 18:49:17 -080064 </tr>
65 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -070066 <td>OEM key</td>
67 <td>The OEM key is a fixed, tamper-protected key available to the bootloader that
68 must be used to verify the boot image.</td>
Clay Murphybc8a22a2015-03-02 18:49:17 -080069 </tr>
Clay Murphybc8a22a2015-03-02 18:49:17 -080070</table>
Clay Murphy0d596682014-10-23 12:06:03 -070071
Clay Murphybc8a22a2015-03-02 18:49:17 -080072<h2 id=overview>Overview</h2>
Clay Murphy0d596682014-10-23 12:06:03 -070073
Danielle Roberts1a1441a2016-06-17 13:50:20 -070074<p>In addition to device state—which already exists in devices and controls
75whether the bootloader allows new software to be flashed—verified boot introduces
76the concept of boot state that indicates the state of device integrity.</p>
Clay Murphye25f9da2015-05-18 14:57:31 -070077
78<h3 id=classes>Classes</h3>
79
Danielle Roberts1a1441a2016-06-17 13:50:20 -070080<p>Two implementation classes exist for verified boot. Depending on how
81fully the device implements this specification, they are defined as follows:</p>
Clay Murphye25f9da2015-05-18 14:57:31 -070082
83<p><strong>Class A</strong> implements verified boot with full chain of trust
Danielle Roberts1a1441a2016-06-17 13:50:20 -070084up to verified partitions. In other words, the implementation supports the
85LOCKED device state, and GREEN and RED boot states.</p>
Clay Murphye25f9da2015-05-18 14:57:31 -070086
Danielle Roberts1a1441a2016-06-17 13:50:20 -070087<p><strong>Class B</strong> implements Class A, and additionally supports the
Clay Murphye25f9da2015-05-18 14:57:31 -070088UNLOCKED device state and the ORANGE boot state.</p>
Clay Murphy0d596682014-10-23 12:06:03 -070089
Clay Murphybc8a22a2015-03-02 18:49:17 -080090<h3 id=verification_keys>Verification keys</h3>
Clay Murphy0d596682014-10-23 12:06:03 -070091
Danielle Roberts1a1441a2016-06-17 13:50:20 -070092<p>Bootloader integrity is always verified using a hardware root of trust. For
93verifying boot and recovery partitions, the bootloader has a fixed OEM key
94available to it. It always attempts to verify the boot partition using the OEM
Clay Murphye25f9da2015-05-18 14:57:31 -070095key first and try other possible keys only if this verification fails.</p>
Clay Murphy0d596682014-10-23 12:06:03 -070096
Danielle Roberts1a1441a2016-06-17 13:50:20 -070097<p>In Class B implementations, it is possible for the user to flash
Clay Murphye25f9da2015-05-18 14:57:31 -070098software signed with other keys when the device is UNLOCKED. If the device is
Danielle Roberts1a1441a2016-06-17 13:50:20 -070099then LOCKED and verification using the OEM key fails, the bootloader tries
Clay Murphye25f9da2015-05-18 14:57:31 -0700100verification using the certificate embedded in the partition signature.
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700101However, using a partition signed with anything other than the OEM key
102results in a notification or a warning, as described below.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700103
Clay Murphybc8a22a2015-03-02 18:49:17 -0800104<h3 id=boot_state>Boot state</h3>
Clay Murphy0d596682014-10-23 12:06:03 -0700105
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700106<p>A verified device will ultimately boot into one of the four states during
107each boot attempt:</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700108
109<ul>
Clay Murphye25f9da2015-05-18 14:57:31 -0700110 <li>GREEN, indicating a full chain of trust extending from the bootloader to
111verified partitions, including the bootloader, boot partition, and all verified
112partitions.
113
114 <li>YELLOW, indicating the boot partition has been verified using the
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700115embedded certificate, and the signature is valid. The bootloader
116displays a warning and the fingerprint of the public key before allowing
117the boot process to continue.
Clay Murphye25f9da2015-05-18 14:57:31 -0700118
119 <li>ORANGE, indicating a device may be freely modified. Device integrity is
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700120left to the user to verify out-of-band. The bootloader displays a warning
Clay Murphye25f9da2015-05-18 14:57:31 -0700121to the user before allowing the boot process to continue.
122
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700123 <li>RED, indicating the device has failed verification. The bootloader
124displays a warning and stops the boot process.
Clay Murphy0d596682014-10-23 12:06:03 -0700125</ul>
126
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700127<p>The recovery partition is verified in the exact same way, as well.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800128
Clay Murphye25f9da2015-05-18 14:57:31 -0700129<h3 id=device_state>Device state</h3>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800130
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700131<p>The possible device states and their relationship with the four verified
132boot states are:</p>
Clay Murphye25f9da2015-05-18 14:57:31 -0700133<ol>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700134 <li>LOCKED, indicating the device cannot be flashed. A LOCKED device
135boots into the GREEN, YELLOW, or RED states during any attempted boot.
Clay Murphye25f9da2015-05-18 14:57:31 -0700136
137 <li>UNLOCKED, indicating the device may be flashed freely and is not intended
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700138to be verified. An UNLOCKED device always boots to the ORANGE boot state.
Clay Murphye25f9da2015-05-18 14:57:31 -0700139</ol>
Clay Murphy0d596682014-10-23 12:06:03 -0700140
Clay Murphy1b77cc22014-12-17 18:20:06 -0800141<img src="../images/verified_boot.png" alt="Verified boot flow" id="figure1" />
Clay Murphy0d596682014-10-23 12:06:03 -0700142<p class="img-caption"><strong>Figure 1.</strong> Verified boot flow</p>
143
Clay Murphybc8a22a2015-03-02 18:49:17 -0800144<h2 id=detailed_design>Detailed design</h2>
Clay Murphy0d596682014-10-23 12:06:03 -0700145
Clay Murphybc8a22a2015-03-02 18:49:17 -0800146<p>Achieving full chain of trust requires support from both the bootloader and the
Clay Murphye25f9da2015-05-18 14:57:31 -0700147software on the boot partition, which is responsible for mounting further
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700148partitions. Verification metadata is also appended to the system partition
Clay Murphye25f9da2015-05-18 14:57:31 -0700149and any additional partitions whose integrity should be verified.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800150
151<h3 id=bootloader_requirements>Bootloader requirements</h3>
152
Clay Murphye25f9da2015-05-18 14:57:31 -0700153<p>The bootloader is the guardian of the device state and is responsible for
154initializing the TEE and binding its root of trust.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800155
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700156<p>Most importantly, the bootloader verifies the integrity of the boot and/or
Clay Murphybc8a22a2015-03-02 18:49:17 -0800157recovery partition before moving execution to the kernel and display the
Clay Murphye25f9da2015-05-18 14:57:31 -0700158warnings specified in the section <a href="#boot_state">Boot state</a>.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800159
Clay Murphye25f9da2015-05-18 14:57:31 -0700160<h4 id=changing_device_state>Changing device state</h4>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800161
162<p>State changes are performed using the <code>fastboot flashing [unlock |
Clay Murphye25f9da2015-05-18 14:57:31 -0700163lock]</code> command. And to protect user data, <strong>all</strong>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700164state transitions wipe the data partitions and ask the user for
Clay Murphybc8a22a2015-03-02 18:49:17 -0800165confirmation before data is deleted.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700166
Clay Murphybc8a22a2015-03-02 18:49:17 -0800167<ol>
168 <li>The UNLOCKED to LOCKED transition is anticipated when a user buys a used
Clay Murphy0d596682014-10-23 12:06:03 -0700169development device. As a result of locking the device, the user should have
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700170confidence that it is in a state produced by the device manufacturer, as long
171as there is no warning.
Clay Murphy0d596682014-10-23 12:06:03 -0700172
Clay Murphybc8a22a2015-03-02 18:49:17 -0800173 <li>The LOCKED to UNLOCKED transition is expected in the case where a developer
174wishes to disable verification on the device.
Clay Murphybc8a22a2015-03-02 18:49:17 -0800175</ol>
176
Clay Murphye25f9da2015-05-18 14:57:31 -0700177
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700178<p><code>fastboot</code> commands that alter device state are listed in the table below:</p>
Clay Murphye25f9da2015-05-18 14:57:31 -0700179
Clay Murphy0d596682014-10-23 12:06:03 -0700180<table>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700181 <col width="25%">
182 <col width="75%">
Clay Murphybc8a22a2015-03-02 18:49:17 -0800183 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700184 <th><code>fastboot</code> command</th>
185 <th>Description</th>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800186 </tr>
187 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700188 <td><code>flashing lock</code></td>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800189 <td>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700190 <ul>
191 <li>Wipe data after asking the user for confirmation
192 <li>Clear a write-protected bit, readable by the bootloader, indicating
193 the device is unlocked
194 </ul>
195 </td>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800196 </tr>
197 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700198 <td><code>flashing unlock</code></td>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800199 <td>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700200 <ul>
201 <li>If the unlock device setting has not been enabled by the user,
202 abort unlocking
203 <li>Wipe data after asking the user for confirmation
204 <li>Set a write-protected bit, readable by the bootloader, indicating
205 the device is unlocked
206 </ul>
207 </td>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800208 </tr>
209</table>
Clay Murphy0d596682014-10-23 12:06:03 -0700210
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700211<p>When altering partition contents, the bootloader checks the bits set by
Clay Murphybc8a22a2015-03-02 18:49:17 -0800212the above commands as described in the following table:</p>
Clay Murphye25f9da2015-05-18 14:57:31 -0700213
Clay Murphybc8a22a2015-03-02 18:49:17 -0800214<table>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700215 <col width="25%">
216 <col width="75%">
Clay Murphybc8a22a2015-03-02 18:49:17 -0800217 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700218 <th><code>fastboot</code> command</th>
219 <th>Description</th>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800220 </tr>
221 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700222 <td><code>flash &lt;partition&gt;</code></td>
223 <td>If the bit set by <code>flashing unlock</code> is set, flash the
224 partition. Otherwise, do not allow flashing.
Clay Murphybc8a22a2015-03-02 18:49:17 -0800225 </td>
226 </tr>
227</table>
Clay Murphy0d596682014-10-23 12:06:03 -0700228
Clay Murphye25f9da2015-05-18 14:57:31 -0700229<p>The same checks should be performed for any <code>fastboot</code> command
230that can be used to change the contents of partitions.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700231
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700232<p class="note"><strong>Note</strong>: Class B implementations support
Clay Murphye25f9da2015-05-18 14:57:31 -0700233changing device state.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700234
Clay Murphye25f9da2015-05-18 14:57:31 -0700235<h4 id=binding_tee_root_of_trust>Binding TEE root of trust</h4>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800236
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700237<p>If TEE is available, the bootloader passes the following information to
238the TEE after boot/recovery partition verification and TEE initialization
239to bind the Keymaster root of trust:</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700240
Clay Murphybc8a22a2015-03-02 18:49:17 -0800241<ol>
Clay Murphye25f9da2015-05-18 14:57:31 -0700242 <li>the public key that was used to sign the boot partition
243 <li>the current device state (LOCKED or UNLOCKED)
Clay Murphybc8a22a2015-03-02 18:49:17 -0800244</ol>
Clay Murphy0d596682014-10-23 12:06:03 -0700245
Clay Murphye25f9da2015-05-18 14:57:31 -0700246<p>This changes the keys derived by the TEE. Taking disk encryption as an example,
247this prevents user data from being decrypted when the device state changes.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700248
Clay Murphybc8a22a2015-03-02 18:49:17 -0800249<p class="note"><strong>Note:</strong> This means if the system software or the
250device state changes, encrypted user data will no longer be accessible as the
251TEE will attempt to use a different key to decrypt the data.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700252
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700253<h4 id="initializing-attestation">Initializing attestation</h4>
254<p>
255Similar to root of trust binding, if TEE is available, the bootloader passes it
256the following information to initialize attestation:
257</p>
258<ol>
259<li>the current boot state (GREEN, YELLOW, ORANGE)
260<li>the operating system version
261<li>the operating system security patch level
262</ol>
Clay Murphye25f9da2015-05-18 14:57:31 -0700263<h4 id=booting_into_recovery>Booting into recovery</h4>
Clay Murphy0d596682014-10-23 12:06:03 -0700264
Clay Murphye25f9da2015-05-18 14:57:31 -0700265<p>The recovery partition should be verified in exactly the same manner as the
266boot partition.</p>
267
268<h4 id=comm_boot_state>Communicating boot state</h4>
269
270<p>System software needs to be able to determine the verification status of
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700271previous stages. The bootloader specifies the current boot state as a
Clay Murphye25f9da2015-05-18 14:57:31 -0700272parameter on the kernel command line (or through the device tree under
273<code>firmware/android/verifiedbootstate</code>) as described in the table
274below:</p>
275
Clay Murphye25f9da2015-05-18 14:57:31 -0700276<table>
277 <tr>
278 <th>Kernel command line parameter</th>
279 <th>Description</th>
280 </tr>
281 <tr>
282 <td><code>androidboot.verifiedbootstate=green</code></td>
283 <td>Device has booted into GREEN boot state.<br>
284 Boot partition has been verified using the OEM key and it’s valid.</td>
285 </tr>
286 <tr>
287 <td><code>androidboot.verifiedbootstate=yellow</code></td>
288 <td>Device has booted into YELLOW boot state.<br>
289 Boot partition has been verified using the certificate embedded into
290 the signature and it’s valid.</td>
291 </tr>
292 <tr>
293 <td><code>androidboot.verifiedbootstate=orange</code></td>
294 <td>Device has booted into ORANGE boot state.<br>
295 The device is unlocked and no verification has been performed.</td>
296 </tr>
Clay Murphye25f9da2015-05-18 14:57:31 -0700297</table>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700298<p class="note"><strong>Note</strong>: The device cannot boot into kernel when
299in the RED boot state, and therefore the kernel command line never includes the
300parameter <code>androidboot.verifiedbootstate=red</code>.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800301
302<h3 id=boot_partition>Boot partition</h3>
303
Clay Murphye25f9da2015-05-18 14:57:31 -0700304<p>Once execution has moved to the boot partition, the software there is responsible
305for setting up verification of further partitions. Due to its large size, the
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700306system partition typically cannot be verified similarly to previous parts but is
Clay Murphye25f9da2015-05-18 14:57:31 -0700307verified as it’s being accessed instead using the dm-verity kernel driver or a
308similar solution.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800309
Clay Murphye25f9da2015-05-18 14:57:31 -0700310<p>If dm-verity is used to verify large partitions, the signature of the verity
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700311metadata appended to each verified partition is verified before the
Clay Murphye25f9da2015-05-18 14:57:31 -0700312partition is mounted and dm-verity is set up for it.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800313
Clay Murphye25f9da2015-05-18 14:57:31 -0700314<h4 id=managing_dm-verity>Managing dm-verity</h4>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800315
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700316<p>Implemented as a device mapper target in kernel, dm-verity adds a layer
317on top of a partition and verifies each read block against a hash tree passed to
318it during setup. If it comes across a block that fails to verify, it makes the
319block inaccessible to user space.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800320
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700321<p>When mounting partitions during boot, fs_mgr sets up dm-verity for a
322partition if the <code>verify</code> fs_mgr flag is specified for it in the
323device’s fstab. Verity metadata signature is verified against the public key
324in <code>/verity_key</code>.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800325
Clay Murphye25f9da2015-05-18 14:57:31 -0700326<h4 id=recovering_from_dm-verity_errors>Recovering from dm-verity errors</h4>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800327
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700328<p>Because the system partition is by far larger than the boot partition, the
Clay Murphybc8a22a2015-03-02 18:49:17 -0800329probability of verification errors is also higher. Specifically, there is a
330larger probability of unintentional disk corruption, which will cause a
331verification failure and can potentially make an otherwise functional device
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700332unusable if a critical block in the partition can no longer be accessed.
333Forward error correction can be used with dm-verity to mitigate this risk.
334Providing this alternative recovery path is recommended, though it comes at the
335expense of increasing metadata size.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800336
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700337<p>
338By default, dm-verity is configured to function in a “restart” mode where it
339immediately restarts the device when a corrupted block is detected. This makes
340it possible to safely warn the user when the device is corrupted, or to fall
341back to device specific recovery, if available.
342</p>
343
344<p>
345To make it possible for users to still access their data, dm-verity switches
346to I/O Error (EIO) mode if the device boots with known corruption. When in EIO mode,
347dm-verity returns I/O errors for any reads that access corrupted blocks but
348allows the device to keep running. Keeping track of the current mode requires
349persistently storing dm-verity state. The state can be managed either by fs_mgr
350or the bootloader:
351</p>
352
353<ol>
354 <li>To manage dm-verity state in fs_mgr, an additional argument is specified to
355 the <code>verify</code> flag to inform fs_mgr where to store dm-verity state.
356 For example, to store the state on the metadata partition, specify
357 <code>verify=/path/to/metadata</code>.
358 <p class="note"><strong>Note:</strong> fs_mgr switches dm-verity to EIO
359 mode after the first corruption has been detected and resets the mode
360 back to “restart” after the metadata signature of any verified partition
361 has changed.</p>
362 </li>
363 <li>Alternatively, to manage dm-verity state in the bootloader, pass the current
364 mode to the kernel in the <code>androidboot.veritymode</code> command line
365 parameter as follows:
366
367 <table>
368 <tr>
369 <th>Kernel command line parameter</th>
370 <th>Description</th>
371 </tr>
372 <tr>
373 <td><code>androidboot.veritymode=enforcing</code></td>
374 <td>Set up dm-verity in the default “restart” mode.</td>
375 </tr>
376 <tr>
377 <td><code>androidboot.veritymode=eio</code></td>
378 <td>Set up dm-verity in EIO mode.</td>
379 </tr>
380 </table>
381
382 <p class="note">
383 <strong>Note:</strong> Managing state in the bootloader also requires the kernel
384 to set the restart reason correctly when the device restarts due to dm-verity.
385 After corruption has been detected, the bootloader should switch back to
386 “restart” mode when any of the verified partitions have changed.</p>
387 </li>
388</ol>
389
390<p>
391If dm-verity is not started in the “restart” mode for any reason, or verity
392metadata cannot be verified, a warning displays to the user if the device is
393allowed to boot, similar to the one shown before booting into the RED boot
394state. The user must consent to the device to continue booting in EIO mode. If
395user consent is not received in 30 seconds, the device powers off.
396</p>
397
398<p class="note">
399<strong>Note:</strong> dm-verity never starts in logging mode to prevent
400unverified data from leaking into userspace.
401</p>
402
403
Clay Murphybc8a22a2015-03-02 18:49:17 -0800404
405<h3 id=verified_partition>Verified partition</h3>
406
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700407<p>In a verified device, the system partition is always verified. But any
Clay Murphye25f9da2015-05-18 14:57:31 -0700408other read-only partition should also be set to be verified, as well. Any
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700409read-only partition that contains executable code is verified on a
Clay Murphye25f9da2015-05-18 14:57:31 -0700410verified device. This includes vendor and OEM partitions, if they exist, for example.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800411
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700412<p>To verify a partition, signed verity metadata is
Clay Murphybc8a22a2015-03-02 18:49:17 -0800413appended to it. The metadata consists of a hash tree of the partition contents
414and a verity table containing signed parameters and the root of the hash tree.
Clay Murphye25f9da2015-05-18 14:57:31 -0700415If this information is missing or invalid when dm-verity is set up for the
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700416partition, the device doesn't boot.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700417
418<h2 id=implementation_details>Implementation details</h2>
419
420<h3 id=key_types_and_sizes>Key types and sizes</h3>
421
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700422<p>The OEM key used in AOSP is an RSA key with a modulus of 2048 bits or
423higher and a public exponent of 65537 (F4), meeting the CDD requirements of
Clay Murphy0d596682014-10-23 12:06:03 -0700424equivalent or greater strength than such a key.</p>
425
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700426<p>Note that the OEM key typically cannot be rotated if it's compromised, so
427protecting it is important, preferably using a Hardware Security Module (HSM)
428or a similar solution. It's also recommended to use a different key for each
429type of device.</p>
430
Clay Murphy0d596682014-10-23 12:06:03 -0700431<h3 id=signature_format>Signature format</h3>
432
Clay Murphybc8a22a2015-03-02 18:49:17 -0800433<p>The signature on an Android verifiable boot image is an ASN.1 DER-encoded
434message, which can be parsed with a decoder similar to the one found at: <a
435href="https://android.googlesource.com/platform/bootable/recovery/+/f4a6ab27b335b69fbc419a9c1ef263004b561265/asn1_decoder.cpp">platform/bootable/recovery/asn1_decoder.cpp</a><br/>
Clay Murphy0d596682014-10-23 12:06:03 -0700436The message format itself is as follows:</p>
437
438<pre>
439AndroidVerifiedBootSignature DEFINITIONS ::=
Clay Murphybc8a22a2015-03-02 18:49:17 -0800440 BEGIN
441 FormatVersion ::= INTEGER
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700442 Certificate ::= Certificate
Clay Murphybc8a22a2015-03-02 18:49:17 -0800443 AlgorithmIdentifier ::= SEQUENCE {
444 algorithm OBJECT IDENTIFIER,
445 parameters ANY DEFINED BY algorithm OPTIONAL
446 }
447 AuthenticatedAttributes ::= SEQUENCE {
448 target CHARACTER STRING,
449 length INTEGER
450 }
Clay Murphy0d596682014-10-23 12:06:03 -0700451
Clay Murphybc8a22a2015-03-02 18:49:17 -0800452 Signature ::= OCTET STRING
453 END
Clay Murphy0d596682014-10-23 12:06:03 -0700454</pre>
455
Clay Murphybc8a22a2015-03-02 18:49:17 -0800456<p>The <code>Certificate</code> field is the full X.509 certificate containing
457the public key used for signing, as defined by <a
Clay Murphy0d596682014-10-23 12:06:03 -0700458href="http://tools.ietf.org/html/rfc5280#section-4.1.1.2">RFC5280</a> section
Danielle Roberts1a1441a2016-06-17 13:50:20 -07004594.1. When LOCKED, the bootloader uses the OEM key for verification
Clay Murphye25f9da2015-05-18 14:57:31 -0700460first, and only boot to YELLOW or RED states if the embedded certificate is
461used for verification instead.</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700462
Clay Murphybc8a22a2015-03-02 18:49:17 -0800463<p>The remaining structure is similar to that defined by <a
464href="http://tools.ietf.org/html/rfc5280#section-4.1.1.2">RFC5280</a> sections
4654.1.1.2 and 4.1.1.3 with the exception of the
466<code>AuthenticatedAttributes</code> field. This field contains the length of
467the image to be verified as an integer and the partition where the image can
468be found (boot, recovery, etc.).</p>
Clay Murphy0d596682014-10-23 12:06:03 -0700469
470<h3 id=signing_and_verifying_an_image>Signing and verifying an image</h3>
471
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700472<p><strong>To produce a signed image:</strong></p>
Clay Murphy0d596682014-10-23 12:06:03 -0700473<ol>
474 <li>Generate the unsigned image.
Clay Murphybc8a22a2015-03-02 18:49:17 -0800475 <li>0-pad the image to the next page size boundary (omit this step if already
476aligned).
Clay Murphye25f9da2015-05-18 14:57:31 -0700477 <li>Populate the fields of the <code>AuthenticatedAttributes</code> section
478 above based on the padded image and desired target partition.
Clay Murphy0d596682014-10-23 12:06:03 -0700479 <li>Append the <code>AuthenticatedAttributes</code> structure above to the image.
480 <li>Sign the image.
481</ol>
482
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700483<p><strong>To verify the image:</strong></p>
Clay Murphy0d596682014-10-23 12:06:03 -0700484<ol>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700485 <li>Determine the size of the image to be loaded including padding (e.g. by reading
Clay Murphybc8a22a2015-03-02 18:49:17 -0800486a header).
Clay Murphy0d596682014-10-23 12:06:03 -0700487 <li>Read the signature located at the offset above.
Clay Murphybc8a22a2015-03-02 18:49:17 -0800488 <li>Validate the contents of the <code>AuthenticatedAttributes</code> field.
Clay Murphye25f9da2015-05-18 14:57:31 -0700489 If these values do not validate, treat it as a signature validation error.
Clay Murphy0d596682014-10-23 12:06:03 -0700490 <li>Verify the image and <code>AuthenticatedAttributes</code> sections.
491</ol>
492
Clay Murphybc8a22a2015-03-02 18:49:17 -0800493<h3 id=user_experience>User experience</h3>
494
495<p>A user in the GREEN boot state should see no additional user interaction besides that
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700496required by normal device boot. In ORANGE and YELLOW boot states, the user sees a
Clay Murphybc8a22a2015-03-02 18:49:17 -0800497warning for at least five seconds. Should the user interact with the device during
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700498this time, the warning remains visible at least 30 seconds longer, or until
499the user dismisses the warning. In the RED boot state, the warning is shown for
500at least 30 seconds, after which the device powers off.</p>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800501
502<p>Sample user interaction screens for other states are shown in the following table:</p>
Clay Murphye25f9da2015-05-18 14:57:31 -0700503
Clay Murphybc8a22a2015-03-02 18:49:17 -0800504<table>
505 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700506 <th>Device state</th>
507 <th>Sample UX</th>
508 <th> </th>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800509 </tr>
510 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700511 <td>YELLOW</td>
512 <td><img src="../images/boot_yellow1.png" alt="Yellow device state 1" id="figure2" />
513 <p class="img-caption"><strong>Figure 2.</strong> Before user interaction</p>
514 </td>
515 <td><img src="../images/boot_yellow2.png" alt="Yellow device state 2" id="figure3" />
516 <p class="img-caption"><strong>Figure 3.</strong> After user interaction</p>
517 </td>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800518 </tr>
519 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700520 <td>ORANGE</td>
521 <td><img src="../images/boot_orange.png" alt="Orange device state" id="figure4" />
522 <p class="img-caption"><strong>Figure 4.</strong> Warning that device is
523 unlocked and can’t be verified.</p>
524 </td>
525 <td> </td>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800526 </tr>
527 <tr>
Danielle Roberts1a1441a2016-06-17 13:50:20 -0700528 <td>RED</td>
529 <td><img src="../images/boot_red1.png" alt="Red device state" id="figure5" />
530 <p class="img-caption"><strong>Figure 5.</strong> Verified boot failure
531 warning</p>
532 </td>
533 <td><img src="../images/boot_red2.png" alt="Red device state" id="figure6" />
534 <p class="img-caption"><strong>Figure 6.</strong> Booting into EIO mode
535 warning</p>
536 </td>
Clay Murphybc8a22a2015-03-02 18:49:17 -0800537 </tr>
538</table>