blob: 711fac321e34bc850967a283ffb165a96274eaf0 [file] [log] [blame]
Tamas Ban1f951d52019-11-15 16:38:34 +00001#######################################
2Rollback protection in TF-M secure boot
3#######################################
4
5:Author: Tamas Ban
6:Organization: Arm Limited
7:Contact: Tamas Ban <tamas.ban@arm.com>
8:Status: Accepted
9
10Anti-rollback protection
11========================
12The goal of anti-rollback protection is to prevent downgrading of the device to
13an older version of its software, which has been deprecated due to security
14concerns.
15
16Elements of software upgrade
17============================
18During a software upgrade the following entities are involved:
19
20 - Boot loader
21 - Manifest data: Metadata of the software image: size, version, hash,
22 signature, etc.
23 - Software image: binary data, elf, etc.
24
25Validation of new image
26=======================
27Boot loader is responsible to authenticate the new image according to the
28required policies and decide whether the new image is fulfilling all the
29requirements. Boot loader verifies the image integrity (hash calculation) and
30the origination (signature validation), and might verify other requirements as
31well. If the new image is successfully authenticated then the boot loader is in
32charge to do the necessary steps (load to execute address, etc.) to enable the
33new image to be executed. During the validation process the image and the
34manifest data is checked.
35
36Manifest format in MCUBoot
37==========================
38MCUBoot has a custom manifest format, which is composed of two parts:
39
40 - Image header: Prepended to the beginning of the image.
41 It is integrity protected:
42 - TLV section: Appended to the end of the image. It is not integrity protected:
43
44 - Hash of public key, hash of image, signature of image
45
46.. code-block:: c
47
48 struct image_header {
49 uint32_t ih_magic;
50 uint32_t ih_load_addr;
51 uint16_t ih_hdr_size;
52 uint16_t _pad1;
53 uint32_t ih_img_size;
54 uint32_t ih_flags;
55 struct image_version ih_ver;
56 uint32_t _pad2;
57 };
58
59Security counter
60================
61The aim of a security counter is to have an independent (from the image version)
62counter in the image manifest to ensure anti-rollback protection. During
63software release the value of this counter must be increased if a security flaw
64was fixed in the current version. Later when this image is installed on the
65device then it is not allowed to go back to earlier versions. It is beneficial
66to handle this counter independently from image main version number:
67
68 - It does not need to increase with each software release
69 - It makes it possible to do software downgrade to some extent: if the security
70 counter has the same value in the older image then it is accepted.
71 - If the boot loader verifies multiple images then these can be handled
72 independently.
73
74However, as an alternative solution the image version number also could serve
75as the security counter of the image. Even the version number itself could be
76checked during the anti-rollback verification or the value of the security
77counter could be derived from the image main version. It is the responsibility
78of the software issuer to define which policy to apply.
79
80Implementation of security counter
81==================================
82The value of the security counter is a security critical data. Any change in
83its value has a security implication. Therefore it must be in the integrity
84protected part of the image manifest. Because the image header is almost fully
Edison Aif7990c82020-07-16 18:31:48 +080085utilized (few unused fields) and the change of image header structure could
Tamas Ban1f951d52019-11-15 16:38:34 +000086lead to compatibility issues between boot loader and runtime software, it is
87proposed to extend the integrity protection to some part of the TLV section.
88One of the unused fields in the image header can be used to store the size of
89the integrity protected area of the TLV section. This is necessary to know how
90to calculate properly the image hash and signature. With this extension of the
91integrity protected area other attributes that require integrity protection
92can easily be added to the image manifest.
93
94Trusted non-volatile (NV) counters
95==================================
96The Trusted Base System Architecture (TBSA-M) defines non-volatile (NV) counters
97or version counters as a counter with the following properties:
98
99 - It must only be possible to increment a version counter through a Trusted
100 access.
101 - It must only be possible to increment a version counter. It must not be
102 possible to decrement it.
103 - When a version counter reaches its maximum value, it must not roll over,
104 and no further changes must be possible.
105 - A version counter must be non-volatile, and the stored value must survive
106 a power down period up to the lifetime of the device.
107
108Trusted non-volatile counters can be used to store the value of security
109counters per updatable software image. Ideally all independently updatable
110software images should have a separate security counter. In current TF-M
111implementation the BL2 is not updatable and the secure and non-secure images
112are updated together as a single binary. Therefore, one counter is enough to
113implement rollback protection. In future the secure and non-secure binaries
114will be handled independently; at that time the introduction of a second
115counter will be necessary.
116
117Currently the NV counters can be manipulated through the interface described
118in ``tfm_plat_nv_counters.h``.
119
120NV counters and anti-rollback protection
121========================================
122Trusted non-volatile counters might not be supported by a hardware platform.
123In this case anti-rollback protection might still be feasible.
124
125The device threat model needs to consider the following aspects:
126
127 - What is the trust level of the boot loader towards the active software
128
129 - If the boot loader cannot protect the anti-rollback mechanism from the
130 secure image then the following threat is unmitigated: The content of the
131 memory area which holds the active image could be replaced with a valid but
132 an older version of the software with software only attack, i.e.: remote
133 code execution.
134 - If the boot loader does not trust the loaded image at all then security
135 counter must have a copy in NV counter area.
136
137 - Another aspect to consider is where the active image is stored
138
139 - Trusted memory: i.e. on-chip flash (eFlash). The threat that a malicious
140 actor can modify the content of trusted memory with HW attack is out of
141 scope for the current implementation. It is assumed that if an active image
142 and related manifest data is stored in trusted memory then the included
143 security counter cannot be compromised.
144 - Untrusted memory: i.e. external (off-chip) storage, where malicious actor
145 can physically access it so it is possible to modify its content, therefore
146 the value of included security counter is unreliable.
147
148If the active image is stored in untrusted storage and it is feasible to modify
149its content (i.e. replace the whole image to an older version including
150corresponding manifest) then the value of security counter must be copied to
151the NV counter area. During software validation the boot loader must compare
152the new image's security counters against the security counter stored in
153non-volatile counters.
154
155If the active image is stored in trusted memory and boot loader trusts in the
156active software then it is not mandatory to store the security counter to
157non-volatile counter area. During software validation the boot loader is
158allowed to compare the new image's security counters against active image's
159security counter.
160
161The evaluation of trusted and untrusted memory must be done per target platform
162during threat modelling.
163
164For the most robust implementation the following principles should be applied:
165
166 - Always use NV counters for storing security counter value if supported by
167 the hardware.
168 - Each software stage must not be able to decrease their corresponding NV
169 counter.
170
171Boot flow with anti-rollback protection
172=======================================
173During software upgrade as part of the image validation process the new and
174active image security counters must be compared. The new image can be accepted
175if its security counter has a greater or equal value than the active image
176security counter. From where to extract the active image security counter it
177can be platform dependent. It might read out directly from active image
178manifest data (only if it is in trusted memory) or the corresponding
179non-volatile counter is read.
180
181If non-volatile counters are used to save security counters then their value
182must be updated:
183
184 - If the boot loader does not support to revert previous images (just
185 overwrites the previously active image with the new one) in case of faulty
186 update then the non-volatile counter can be updated to be equal with the
187 new image security counter after successful authentication of the new image.
188 - If revert is supported then non-volatile counter can be updated just after
189 a test run of the new software when its health check is done. Just in case
190 of successful health check can the counter updated to avoid the prevention
191 of the revert. This might require a secondary restart of the device.
192
193Tool support
194============
195There is a Python script, ``imgtool.py`` which is used to prepare the new image
196for upgrade (add header, sign the image, append TLV section). This script must
197be modified to get an additional command line argument which serves as security
198counter. The security counter must be included in the integrity protected part
199of the TLV section.
200
201--------------
202
Edison Aif7990c82020-07-16 18:31:48 +0800203*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*