1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

config: Check metadata magic before upgrading storage from version 10. Bump config version.

This commit is contained in:
Andrew Kozlik 2019-02-14 16:28:29 +01:00 committed by Pavol Rusnak
parent 0b79d0e596
commit 55bc3c7430
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -46,9 +46,15 @@
#include "supervise.h" #include "supervise.h"
#include "storage.h" #include "storage.h"
/* Magic constant to check validity of storage block for storage versions 1 to 10. */ /* Magic constants to check validity of storage block for storage versions 1 to 10. */
static const uint32_t CONFIG_MAGIC_V10 = 0x726f7473; // 'stor' as uint32_t static const uint32_t CONFIG_MAGIC_V10 = 0x726f7473; // 'stor' as uint32_t
#if !EMULATOR
static const uint32_t META_MAGIC_V10 = 0x525a5254; // 'TRZR' as uint32_t
#else
static const uint32_t META_MAGIC_V10 = 0xFFFFFFFF;
#endif
#define APP 0x0100 #define APP 0x0100
#define FLAG_PUBLIC 0x8000 #define FLAG_PUBLIC 0x8000
#define FLAGS_WRITE 0xC000 #define FLAGS_WRITE 0xC000
@ -121,7 +127,7 @@ static char CONFIDENTIAL sessionPassphrase[51];
static secbool autoLockDelayMsCached = secfalse; static secbool autoLockDelayMsCached = secfalse;
static uint32_t autoLockDelayMs = autoLockDelayMsDefault; static uint32_t autoLockDelayMs = autoLockDelayMsDefault;
static const uint32_t CONFIG_VERSION = 10; static const uint32_t CONFIG_VERSION = 11;
static const uint8_t FALSE_BYTE = '\x00'; static const uint8_t FALSE_BYTE = '\x00';
static const uint8_t TRUE_BYTE = '\x01'; static const uint8_t TRUE_BYTE = '\x01';
@ -195,7 +201,8 @@ static secbool config_upgrade_v10(void)
{ {
#define OLD_STORAGE_SIZE(last_member) (((offsetof(Storage, last_member) + pb_membersize(Storage, last_member)) + 3) & ~3) #define OLD_STORAGE_SIZE(last_member) (((offsetof(Storage, last_member) + pb_membersize(Storage, last_member)) + 3) & ~3)
if (memcmp(FLASH_PTR(FLASH_STORAGE_START), &CONFIG_MAGIC_V10, sizeof(CONFIG_MAGIC_V10)) != 0) { if (memcmp(FLASH_PTR(FLASH_META_MAGIC), &META_MAGIC_V10, sizeof(META_MAGIC_V10)) != 0 ||
memcmp(FLASH_PTR(FLASH_STORAGE_START), &CONFIG_MAGIC_V10, sizeof(CONFIG_MAGIC_V10)) != 0) {
// wrong magic // wrong magic
return secfalse; return secfalse;
} }