Skip to content

Commit 0527170

Browse files
committed
improve canDropPrivs() signature index check
1 parent 852f8ac commit 0527170

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

include/keepkey/board/pubkeys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <inttypes.h>
2424

2525
#define PUBKEYS 5
26-
#define EXP_PUBKEYS 5
26+
#define BLK_v2_0_0_PUBKEYS 5
2727
#define PUBKEY_LENGTH 65
2828
#define SIGNATURES 3
2929

tools/firmware/keepkey_main.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,18 @@ static bool canDropPrivs(void) {
8484
case BLK_v1_1_0:
8585
return true;
8686
case BLK_v2_0_0:
87-
case BLK_v2_1_0:
87+
case BLK_v2_1_0: {
8888
// sigs already checked in bootloader. If a sig is present we are in priv mode, drop privs.
89-
return *((uint8_t *)FLASH_META_SIGINDEX1) != 0;
89+
fi_defense_delay(); // delay before the fetch from flash
90+
uint8_t sigindex1 = *((uint8_t *)FLASH_META_SIGINDEX1);
91+
// Future signature format enhancements may use higher indexes for different keys, but
92+
// existing v2 bootloaders only recognize signatures up to BLK_v2_0_0_PUBKEYS. As such,
93+
// even if a sig with a higher index is present, these bootloaders will have dropped privs
94+
// by this point already, and trying to drop privs *again* will cause a fault.
95+
bool sigPresent = sigindex1 >= 1 && sigindex1 <= BLK_v2_0_0_PUBKEYS;
96+
// delay before the security-critical branch instruction
97+
return !fi_defense_delay(sigPresent);
98+
}
9099
}
91100
__builtin_unreachable();
92101
}

0 commit comments

Comments
 (0)