Skip to content

Commit 84da51b

Browse files
almir-okatogustavonihei
authored andcommitted
espressif: add downgrade prevention feature
Signed-off-by: Almir Okato <almir.okato@espressif.com>
1 parent 421730e commit 84da51b

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

boot/espressif/hal/include/mcuboot_config/mcuboot_config.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@
8484
*/
8585
#define MCUBOOT_VALIDATE_PRIMARY_SLOT
8686

87+
#ifdef CONFIG_ESP_DOWNGRADE_PREVENTION
88+
#define MCUBOOT_DOWNGRADE_PREVENTION 1
89+
/* MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER is used later as bool value so it is
90+
* always defined, (unlike MCUBOOT_DOWNGRADE_PREVENTION which is only used in
91+
* preprocessor condition and my be not defined) */
92+
# ifdef CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER
93+
# define MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER 1
94+
# else
95+
# define MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER 0
96+
# endif
97+
#endif
98+
8799
/*
88100
* Flash abstraction
89101
*/

boot/espressif/port/esp32/bootloader.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ CONFIG_ESP_MCUBOOT_WDT_ENABLE=y
1212
CONFIG_ESP_SCRATCH_OFFSET=0x210000
1313
CONFIG_ESP_SCRATCH_SIZE=0x40000
1414

15+
# When enabled, prevents updating image to an older version
16+
# CONFIG_ESP_DOWNGRADE_PREVENTION=y
17+
# This option makes downgrade prevention rely also on security
18+
# counter (defined using imgtool) instead of only image version
19+
# CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER=y
20+
1521
# Enables the MCUboot Serial Recovery, that allows the use of
1622
# MCUMGR to upload a firmware through the serial port
1723
# CONFIG_ESP_MCUBOOT_SERIAL=y

boot/espressif/port/esp32c3/bootloader.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ CONFIG_ESP_MCUBOOT_WDT_ENABLE=y
1212
CONFIG_ESP_SCRATCH_OFFSET=0x210000
1313
CONFIG_ESP_SCRATCH_SIZE=0x40000
1414

15+
# When enabled, prevents updating image to an older version
16+
# CONFIG_ESP_DOWNGRADE_PREVENTION=y
17+
# This option makes downgrade prevention rely also on security
18+
# counter (defined using imgtool) instead of only image version
19+
# CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER=y
20+
1521
# Enables the MCUboot Serial Recovery, that allows the use of
1622
# MCUMGR to upload a firmware through the serial port
1723
# CONFIG_ESP_MCUBOOT_SERIAL=y

boot/espressif/port/esp32s2/bootloader.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ CONFIG_ESP_MCUBOOT_WDT_ENABLE=y
1212
CONFIG_ESP_SCRATCH_OFFSET=0x210000
1313
CONFIG_ESP_SCRATCH_SIZE=0x40000
1414

15+
# When enabled, prevents updating image to an older version
16+
# CONFIG_ESP_DOWNGRADE_PREVENTION=y
17+
# This option makes downgrade prevention rely also on security
18+
# counter (defined using imgtool) instead of only image version
19+
# CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER=y
20+
1521
# Enables the MCUboot Serial Recovery, that allows the use of
1622
# MCUMGR to upload a firmware through the serial port
1723
# CONFIG_ESP_MCUBOOT_SERIAL=y

boot/espressif/port/esp32s3/bootloader.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ CONFIG_ESP_MCUBOOT_WDT_ENABLE=y
1212
CONFIG_ESP_SCRATCH_OFFSET=0x210000
1313
CONFIG_ESP_SCRATCH_SIZE=0x40000
1414

15+
# When enabled, prevents updating image to an older version
16+
# CONFIG_ESP_DOWNGRADE_PREVENTION=y
17+
# This option makes downgrade prevention rely also on security
18+
# counter (defined using imgtool) instead of only image version
19+
# CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER=y
20+
1521
# Enables multi image, if it is not defined, it is assumed
1622
# only one updatable image
1723
# CONFIG_ESP_IMAGE_NUMBER=2

docs/readme-espressif.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ For signing with a crypto key and guarantee the authenticity of the image being
130130
esptool.py -p <PORT> -b <BAUD> --before default_reset --after hard_reset --chip <TARGET> write_flash --flash_mode dio --flash_size <FLASH_SIZE> --flash_freq 40m <SLOT_OFFSET> <SIGNED_BIN>
131131
```
132132

133+
# [Downgrade prevention](#downgrade-prevention)
134+
135+
Downgrade prevention (avoid updating of images to an older version) can be enabled using the following configuration:
136+
137+
```
138+
CONFIG_ESP_DOWNGRADE_PREVENTION=y
139+
```
140+
141+
MCUboot will then verify and compare the new image version number with the current one before perform an update swap.
142+
143+
Version number is added to the image when signing it with `imgtool` (`-v` parameter, e.g. `-v 1.0.0`).
144+
145+
### [Downgrade prevention with security counter](#downgrade-prevention-with-security-counter)
146+
147+
It is also possible to rely on a security counter, also added to the image when signing with `imgtool` (`-s` parameter), apart from version number. This allows image downgrade at some extent, since any update must have greater or equal security counter value. Enable using the following configuration:
148+
149+
```
150+
CONFIG_ESP_DOWNGRADE_PREVENTION_SECURITY_COUNTER=y
151+
```
152+
153+
E.g.: if the current image was signed using `-s 1` parameter, an eventual update image must have been signed using security counter `-s 1` or greater.
154+
133155
# [Security Chain on Espressif port](#security-chain-on-espressif-port)
134156

135157
[MCUboot encrypted images](encrypted_images.md) do not provide full code confidentiality when only external storage is available (see [Threat model](encrypted_images.md#threat-model)) since by MCUboot design the image in Primary Slot, from where the image is executed, is stored plaintext.

0 commit comments

Comments
 (0)