enable secure erase confirmation in loader (leaks one chaff key)

A problem was discovered while implementing the secure boot
hardening. Namely, an attacker could trick the loader into
loading a devkey-signed kernel by incrementing the
developer mode counter without actually triggering the
secure erase of the keys, and finding a way to glitch
over the check of the developer mode counter check.

Two countermeasuers are implemented:

1. if the developer mode flag is set, trigger a secure erase
even if the image signatures aren't developer mode

2. leak one of the chaff keys into the loader, so there are
now at least two indpendent checks of being in developer
mode in the loader. One is based on the counter, which
is only weakly correlated with the erased state. The
other is checking for the erase value in the leaked key,
which is a strong indicator of being in developer mode.

The leaked key is, of course, erased before entering the
kernel (and the key is leaked into a region of memory
that is, in theory, securely claimed by the keystore, so
it's not like anyone can just read it; however, it is
in a less secure location than the protected key area).

The impact of an adversary obtaining the key is only
a slight weakening of security because the chaff keys
are numerous, they still have thousands of bits to
guess even if they got a couple hundred of them.

The next series of patches implements the scheme outlined
above, starting with defining the key to be leaked. The
leaked key is intentionally the last key in the slice
of keys used in the erasure algorithm, so that presumably
if the leaked key is showing an erased value, all other
keys have been erased.
This commit is contained in:
bunnie 2025-12-06 18:24:40 +08:00
parent 9ddf6beae6
commit eee9cd62c9
No known key found for this signature in database
2 changed files with 14 additions and 0 deletions

View file

@ -116,6 +116,19 @@ pub const NUISANCE_KEYS: [SlotIndex; 2] = [NUISANCE_KEYS_0, NUISANCE_KEYS_1];
/// running your own code on the device).
pub const CHAFF_KEYS: SlotIndex = SlotIndex::DataRange(128..256, PartitionAccess::Fw0, RwPerms::ReadWrite);
/// This is intentionally the very last key in the chaff key range. It's "sampled" by copying
/// the full value of this key into the BURAM, which is later passed on to the loader. It's then
/// checked for a value being equal to the erasure value to confirm that a device is in developer
/// mode or not. This process does introduce a risk that this one key is leaked but it also
/// closes a loophole where an attacker can simply manipulate the value of the DEVELOPER_KEY
/// one way counter and fool the system into running a developer-key signed image without the
/// secret keys being erased.
///
/// Placing this at the end of the key array ostensibly means that all the keys before it were
/// erased; it might be possible to glitch all the way to the end and just have this one erased
/// but I think that is reasonably unlikely...
pub const ERASE_PROOF: SlotIndex = SlotIndex::Data(256, PartitionAccess::Fw0, RwPerms::ReadWrite);
/// All the slots of concern located in a single iterator. The idea is that everything is
/// condensed here and used to check for access integrity using the array below.
pub const DATA_SLOTS: [SlotIndex; 8] = [

View file

@ -43,6 +43,7 @@ pub const DATA_SLOTS: [SlotIndex; 8] = [
crate::offsets::DEV_PUBKEY,
];
pub use crate::baosec::ERASE_PROOF;
pub use crate::baosec::{
CHAFF_KEYS, NUISANCE_KEYS, NUISANCE_KEYS_0, NUISANCE_KEYS_1, RMA_KEY, ROOT_SEED, THE_FLAG_1,
};