From eee9cd62c93c4a28d4b0b630133f0c0d833e6545 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 6 Dec 2025 18:24:40 +0800 Subject: [PATCH] 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. --- libs/bao1x-api/src/offsets/baosec.rs | 13 +++++++++++++ libs/bao1x-api/src/offsets/dabao.rs | 1 + 2 files changed, 14 insertions(+) diff --git a/libs/bao1x-api/src/offsets/baosec.rs b/libs/bao1x-api/src/offsets/baosec.rs index 1fac3cd1b..d9a245e97 100644 --- a/libs/bao1x-api/src/offsets/baosec.rs +++ b/libs/bao1x-api/src/offsets/baosec.rs @@ -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] = [ diff --git a/libs/bao1x-api/src/offsets/dabao.rs b/libs/bao1x-api/src/offsets/dabao.rs index 6c4eb3ba4..24858a9b3 100644 --- a/libs/bao1x-api/src/offsets/dabao.rs +++ b/libs/bao1x-api/src/offsets/dabao.rs @@ -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, };