cdaa84cb6689ef9cbf902e2687134dfee2e4d78b
[AGL/documentation.git] / docs / 3_Architecture_Guides / 2_Security_Blueprint / 3_Secure_Boot.md
1 ---
2 title: Secure Boot
3 ---
4
5 Domain          | Improvement
6 --------------- | ----------------------------------------------------
7 Boot-Abstract-1 | More generic and add examples (The chain of trust).
8
9 Secure boot refers to preventing malicious software applications and
10 “unauthorized” operating systems from loading during the system start-up
11 process. The goal is to protect users from rootkits and other low-level malware
12 attacks. Modern bootloaders come with features that can be used to enable secure
13 boot in the system.
14
15 **Boot Hardening**: Steps/requirements to configure the boot sequence, in order
16 to restrict the device from executing anything other than the approved software
17 image.
18
19 In this part, we will see a series of settings that will allow us to improve
20 security during boot phase. For the purposes of reference and explanation, we
21 are providing guidance on how to configure an embedded device that runs with a
22 3.10.17 Linux kernel. If the integrity is not checked or if a critical error
23 occurs, the system must boot on a very stable backup image.
24
25 **Requirements**: These requirements must be met even if an alternative version
26 of the Linux kernel is chosen.
27
28 **Recommendations**: Detailed best practices that should be applied in order to
29 secure a device. Although they are not currently listed as hard requirements,
30 they may be upgraded to requirements status in the future. In addition, specific
31 operators may change some of these recommendations into requirements based on
32 their specific needs and objectives.
33
34 Domain          | Improvement
35 --------------- | -------------------------------------------
36 Boot-Abstract-1 | Review the definition of the "boot loader".
37
38 **Boot loader**: The boot loader consists of the Primary boot loader residing in
39 **OTP** memory, sboot, U-Boot and Secure loader residing in external flash (NAND
40 or SPI/NOR flash memory). The CPU on power on or reset executes the primary boot
41 loader. The **OTP** primary boot loader makes the necessary initial system
42 configuration and then loads the secondary boot loader sboot from external flash
43 memory to ram memory. The sboot then loads the U-Boot along with the Secure
44 loader. U-Boot then verifies the Kernel/system image integrity, then loads the
45 Kernel/system image before passing control to it.
46
47 --------------------------------------------------------------------------------
48
49 ## Acronyms and Abbreviations
50
51 The following table lists the terms utilized within this part of the document.
52
53 Acronyms or Abbreviations | Description
54 ------------------------- | -----------------------------------------------------------------------
55 _FUSE_                    | **F**ilesystem in **U**ser**S**pac**E**
56 _OTP_                     | **O**ne-**T**ime-**P**rogrammable
57 _DOCSIS_                  | **D**ata **O**ver **C**able **S**ervice **I**nterface **S**pecification
58
59 # Image
60
61 ## Image selection
62
63 The boot process shall be uninterruptible and shall irrevocably boot the image
64 as specified in the boot environment.
65
66 In U-Boot set the "_bootdelay_" environment variable and/or define
67 `CONFIG_BOOTDELAY` to _-2_.
68
69 Domain                 | _Variable_ / `Config` name | `Value`
70 ---------------------- | -------------------------- | -------
71 Boot-Image-Selection-1 | `CONFIG_BOOTDELAY`         | `-2`
72 Boot-Image-Selection-2 | _bootdelay_                | `-2`
73
74 --------------------------------------------------------------------------------
75
76 ## Image authenticity
77
78 It shall not be possible to boot from an unverified image. The secure boot
79 feature in U-Boot shall be enabled. The secure boot feature is available from
80 U-Boot 2013.07 version. To enable the secure boot feature, enable the following
81 features:
82
83 ```sh
84 CONFIG_FIT: Enables support for Flat Image Tree (FIT) uImage format.
85 CONFIG_FIT_SIGNATURE: Enables signature verification of FIT images.
86 CONFIG_RSA: Enables RSA algorithm used for FIT image verification.
87 CONFIG_OF_CONTROL: Enables Flattened Device Tree (FDT) configuration.
88 CONFIG_OF_SEPARATE: Enables separate build of u-Boot from the device tree.
89 CONFIG_DEFAULT_DEVICE_TREE: Specifies the default Device Tree used for the run-time configuration of U-Boot.
90 ```
91
92 Generate the U-Boot image with public keys to validate and load the image. It
93 shall use RSA2048 and SHA256 for authentication.
94
95 Domain                    | `Config` name                | _State_
96 ------------------------- | ---------------------------- | --------
97 Boot-Image-Authenticity-1 | `CONFIG_FIT`                 | _Enable_
98 Boot-Image-Authenticity-2 | `CONFIG_FIT_SIGNATURE`       | _Enable_
99 Boot-Image-Authenticity-3 | `CONFIG_RSA`                 | _Enable_
100 Boot-Image-Authenticity-4 | `CONFIG_OF_CONTROL`          | _Enable_
101 Boot-Image-Authenticity-5 | `CONFIG_OF_SEPARATE`         | _Enable_
102 Boot-Image-Authenticity-6 | `CONFIG_DEFAULT_DEVICE_TREE` | _Enable_
103
104 # Communication modes
105
106 ## Disable USB, Serial and DOCSIS Support
107
108 To disable USB support in U-Boot, following config's shall not be defined:
109
110 ```
111 CONFIG_CMD_USB: Enables basic USB support and the usb command.
112 CONFIG_USB_UHCI: Defines the lowlevel part.
113 CONFIG_USB_KEYBOARD: Enables the USB Keyboard.
114 CONFIG_USB_STORAGE: Enables the USB storage devices.
115 CONFIG_USB_HOST_ETHER: Enables USB Ethernet adapter support.
116 ```
117
118 In addition, disable unnecessary communication modes like Ethernet, Serial
119 ports, DOCSIS in U-Boot and sboot that are not necessary.
120
121 Linux Kernel support for USB should be compiled-out if not required. If it is
122 needed, the Linux Kernel should be configured to only enable the minimum
123 required USB devices. User-initiated USB-filesystems should be treated with
124 special care. Whether or not the filesystems are mounted in userspace
125 (**FUSE**), restricted mount options should be observed.
126
127 Domain               | Communication modes       | _State_
128 -------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------
129 Boot-Communication-1 | `USB`                     | _Disabled_ and _Compiled-out_ if not required.
130 Boot-Communication-2 | `USB`                     | Else, Kernel should be configured to only enable the minimum required USB devices and filesystems should be treated with special care.
131 Boot-Communication-3 | `Ethernet`                | _Disabled_
132 Boot-Communication-4 | U-boot and sboot `DOCSIS` | _Disabled_
133 Boot-Communication-5 | `Serial ports`            | _Disabled_
134
135 Domain                   | `Config` name           | _State_
136 ------------------------ | ----------------------- | -------------
137 Boot-Communication-USB-1 | `CONFIG_CMD_USB`        | _Not defined_
138 Boot-Communication-USB-2 | `CONFIG_USB_UHCI`       | _Not defined_
139 Boot-Communication-USB-3 | `CONFIG_USB_KEYBOARD`   | _Not defined_
140 Boot-Communication-USB-4 | `CONFIG_USB_STORAGE`    | _Not defined_
141 Boot-Communication-USB-5 | `CONFIG_USB_HOST_ETHER` | _Not defined_
142
143 --------------------------------------------------------------------------------
144
145 ## Disable all unused Network Interfaces
146
147 Only used network interfaces should be enabled. Where possible, services should
148 also be limited to those necessary.
149
150 Domain               | Communication modes  | _State_
151 -------------------- | -------------------- | ---------------------------------------------------------------------------------------------
152 Boot-Communication-1 | `Network interfaces` | Preferably _no network interface is allowed_, otherwise, restrict the services to those used.
153
154 ## Remove or Disable Unnecessary Services, Ports, and Devices
155
156 Restrict the `services`, `ports` and `devices` to those used.
157
158 Domain               | Object                            | Recommendations
159 -------------------- | --------------------------------- | -------------------------------------------------------------
160 Boot-Communication-1 | `Services`, `ports` and `devices` | Restrict the `services`, `ports` and `devices` to those used.
161
162 ## Disable flash access
163
164 **Recommendation**:
165
166 In U-Boot following flash memory commands shall be disabled:
167
168 **NAND**: Support for nand flash access available through `do_nand` has to be
169 disabled.
170
171 Domain                     | `Command` name | _State_
172 -------------------------- | -------------- | ---------
173 Boot-Communication-Flash-1 | `do_nand`      | _Disable_
174
175 Similarly sboot should disable flash access support through command line if any.
176
177 # Consoles
178
179 ## Disable serial console
180
181 Serial console output shall be disabled. To disable console output in U-Boot,
182 set the following macros:
183
184 Domain                 | `Config` name                           | `Value`
185 ---------------------- | --------------------------------------- | ---------
186 Boot-Consoles-Serial-1 | `CONFIG_SILENT_CONSOLE`                 | `Disable`
187 Boot-Consoles-Serial-2 | `CONFIG_SYS_DEVICE_NULLDEV`             | `Disable`
188 Boot-Consoles-Serial-3 | `CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC` | `Disable`
189
190 Domain          | Improvement
191 --------------- | ------------------------------------
192 Boot-Consoles-1 | Secure loader: No reference earlier?
193
194 And set "**silent**" environment variable. For the Secure loader, disable the
195 traces by not defining the below macro:
196
197 Domain                 | `Environment variable` name | _State_
198 ---------------------- | --------------------------- | -------------
199 Boot-Consoles-Serial-1 | `INC_DEBUG_PRINT`           | _Not defined_
200
201 For sboot proper configuration needs to be done to disable the serial console.
202
203 --------------------------------------------------------------------------------
204
205 ## Immutable environment variables
206
207 In U-Boot, ensure Kernel command line, boot commands, boot delay and other
208 environment variables are immutable. This will prevent side-loading of alternate
209 images, by restricting the boot selection to only the image in FLASH.
210
211 The environment variables shall be part of the text region in U-Boot as default
212 environment variable and not in non-volatile memory.
213
214 Remove configuration options related to non-volatile memory, such as:
215
216 Domain                     | `Config` name                | _State_
217 -------------------------- | ---------------------------- | ---------
218 Boot-Consoles-Variables-1  | `CONFIG_ENV_IS_IN_MMC`       | `#undef`
219 Boot-Consoles-Variables-2  | `CONFIG_ENV_IS_IN_EEPROM`    | `#undef`
220 Boot-Consoles-Variables-3  | `CONFIG_ENV_IS_IN_FLASH`     | `#undef`
221 Boot-Consoles-Variables-4  | `CONFIG_ENV_IS_IN_DATAFLASH` | `#undef`
222 Boot-Consoles-Variables-5  | `CONFIG_ENV_IS_IN_FAT`       | `#undef`
223 Boot-Consoles-Variables-6  | `CONFIG_ENV_IS_IN_NAND`      | `#undef`
224 Boot-Consoles-Variables-7  | `CONFIG_ENV_IS_IN_NVRAM`     | `#undef`
225 Boot-Consoles-Variables-8  | `CONFIG_ENV_IS_IN_ONENAND`   | `#undef`
226 Boot-Consoles-Variables-9  | `CONFIG_ENV_IS_IN_SPI_FLASH` | `#undef`
227 Boot-Consoles-Variables-10 | `CONFIG_ENV_IS_IN_REMOTE`    | `#undef`
228 Boot-Consoles-Variables-11 | `CONFIG_ENV_IS_IN_UBI`       | `#undef`
229 Boot-Consoles-Variables-12 | `CONFIG_ENV_IS_NOWHERE`      | `#define`
230
231 --------------------------------------------------------------------------------
232
233 ## (Recommendation) Removal of memory dump commands
234
235 In U-Boot, following commands shall be disabled to avoid memory dumps:
236
237 ```
238 md : Memory Display command.
239 mm : Memory modify command - auto incrementing address.
240 nm : Memory modify command - constant address.
241 mw : Memory write.
242 cp : Memory copy.
243 mwc : Memory write cyclic.
244 mdc : Memory display cyclic.
245 mtest : Simple ram read/write test.
246 loopw : Infinite write loop on address range.
247 ```
248
249 Domain                  | `Command` name | _State_
250 ----------------------- | -------------- | ----------
251 Boot-Consoles-MemDump-1 | `md`           | _Disabled_
252 Boot-Consoles-MemDump-2 | `mm`           | _Disabled_
253 Boot-Consoles-MemDump-3 | `nm`           | _Disabled_
254 Boot-Consoles-MemDump-4 | `mw`           | _Disabled_
255 Boot-Consoles-MemDump-5 | `cp`           | _Disabled_
256 Boot-Consoles-MemDump-6 | `mwc`          | _Disabled_
257 Boot-Consoles-MemDump-7 | `mdc`          | _Disabled_
258 Boot-Consoles-MemDump-8 | `mtest`        | _Disabled_
259 Boot-Consoles-MemDump-9 | `loopw`        | _Disabled_
260
261 Similarly, memory dump support shall be disabled from sboot.