From 362124127e817f91867462005a9ce18aafa0c902 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 4 Dec 2025 14:56:07 +0800 Subject: [PATCH] add redundant counters, paranoid mode, attack counters This allocates some additional one way counters dedicated to hardening: - Paranoid mode is duplicated in slots 65 & 67 - An attack counter is in slot 66 - Redundant revocation counters are seated in slot 68 The primary revocation counters are in slot 116. This means that cutting out the revocation counters would probably require at least two edits to the memory array - simply cutting the word addressing line for those columns might be enough to defeat a counter. Paranoid mode duplicate is stored somewhat close to the primary counter, which means it could be subject to a single line cut to fully defeat the counter, but the space is getting pretty crowded so I'll leave it like that; I really want to leave the bottom 64 slots available for application use. A "flag" key is allocated, plus a dummy flag is committed to the repo. This is a value that, if retrieved, would ostensibly bring the retriever glory and bounty, to the extent that any glory or bounty is to be had (ps: I'm poor and this project is obscure). The actual flag, of course, is not in the repo...I hope! The flag value is different from all other values in that this is the only shared, common secret across all devices. All other device secrets are generated on a per-device basis from the TRNGs. So the flag needs some special treatment such that it's not overwritten during device keying. The flag exists because I'm hoping that anyone who manages to extract it will also provide a helpful explanation of the procedure to get it out, so that the system could be patched (if the error is patchable) or rev'd in future silicon. That being said, a flag retrieval is not necessarily equal to a full break of security across all devices because as mentioned above, most device secrets are on a per-device basis. The flag represents then, the amount of effort necessary to apply to every device to retrieve the secrets within. --- bao1x-boot/blobs/flag1_dummy_3e2080.bin | Bin 0 -> 32 bytes libs/bao1x-api/src/offsets/baosec.rs | 9 ++++-- libs/bao1x-api/src/offsets/common.rs | 37 ++++++++++++++++++++++-- libs/bao1x-api/src/offsets/dabao.rs | 7 +++-- 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 bao1x-boot/blobs/flag1_dummy_3e2080.bin diff --git a/bao1x-boot/blobs/flag1_dummy_3e2080.bin b/bao1x-boot/blobs/flag1_dummy_3e2080.bin new file mode 100644 index 0000000000000000000000000000000000000000..ef744c1020ffa0af2f9339c57a0dd527cce422ae GIT binary patch literal 32 qcmV+*0N?)}x_S2;BPRJQJ>t`Zd5?aaQDV-K%fPhw<5w(Y)UVSHUlG*+ literal 0 HcmV?d00001 diff --git a/libs/bao1x-api/src/offsets/baosec.rs b/libs/bao1x-api/src/offsets/baosec.rs index d7bd88041..1fac3cd1b 100644 --- a/libs/bao1x-api/src/offsets/baosec.rs +++ b/libs/bao1x-api/src/offsets/baosec.rs @@ -60,6 +60,11 @@ pub const CP_COOKIE: SlotIndex = SlotIndex::Data(258, PartitionAccess::Fw0, RwPe /// The swap encryption key. Used to protect swap images beyond the signing key, if we so desire. pub const SWAP_KEY: SlotIndex = SlotIndex::Data(259, PartitionAccess::Fw0, RwPerms::ReadWrite); +/// A test value placed by FT into the memory array. If you can read the original value, you've captured a +/// flag! +/// There is a second flag stored somewhere else. Can you find it? +pub const THE_FLAG_1: SlotIndex = SlotIndex::Data(260, PartitionAccess::Fw0, RwPerms::ReadWrite); + /// `NUISANCE_KEYS` are hashed together with `ROOT_SEED` to derive the core secret. /// Their primary purpose is to annoy microscopists trying to read the secret key by /// directly imaging the RRAM array. They also exist to reduce power side channels @@ -126,5 +131,5 @@ pub const DATA_SLOTS: [SlotIndex; 8] = [ /// In addition to these KEY_SLOTS, the DEVELOPER_MODE one way counter is a security-important parameter /// that should be included as domain separation in any KDF. -pub const KEY_SLOTS: [SlotIndex; 6] = - [CP_COOKIE, RMA_KEY, ROOT_SEED, NUISANCE_KEYS_0, NUISANCE_KEYS_1, CHAFF_KEYS]; +pub const KEY_SLOTS: [SlotIndex; 7] = + [THE_FLAG_1, CP_COOKIE, RMA_KEY, ROOT_SEED, NUISANCE_KEYS_0, NUISANCE_KEYS_1, CHAFF_KEYS]; diff --git a/libs/bao1x-api/src/offsets/common.rs b/libs/bao1x-api/src/offsets/common.rs index ddb4d1be6..d0300f0d2 100644 --- a/libs/bao1x-api/src/offsets/common.rs +++ b/libs/bao1x-api/src/offsets/common.rs @@ -65,6 +65,41 @@ macro_rules! encode_oneway { } // =========== ONE WAY COUNTER SLOTS ============== + +/// Paranoid mode is written twice; either being non-zero invokes paranoid mode +/// In paranoid mode, the glitch detectors are set to trigger aggressively and reset the +/// system through automatic hardware means. This can lead to false positives that can +/// degrade user experience, which is why it's left as a setting. +pub const PARANOID_MODE: usize = 65; + +/// Counter that logs the possible number of attacks seen. This is used in conjunction +/// with paranoid mode to initiate a system wipe. The reason this can be non-zero is that +/// stray light or environmental factors can trigger the system, and so this threshold is +/// tunable. +pub const POSSIBLE_ATTACKS: usize = 66; + +/// Paranoid mode is written twice +pub const PARANOID_MODE_DUPE: usize = 67; + +/// Total number of public key slots in the system. Pubkey revocations are duplicated because +/// being able to override a pubkey revocation is a strong attack vector. +pub const PUBKEY_SLOTS: usize = 4; + +/// The layout of the below duplicate revocation bits *MUST* match that of the primary keys. +/// This property is relied upon by the signature checking routine. +/// Offset in the one-way counter array for loader key revocations. Provisions for up to four +/// key slots, from [68..=72]. +pub const LOADER_REVOCATION_DUPE_OFFSET: usize = 68; +/// Offset in the one-way counter array for boot1 key revocations. Provisions for up to four +/// key slots, from [72..=76]. +pub const BOOT1_REVOCATION_DUPE_OFFSET: usize = LOADER_REVOCATION_DUPE_OFFSET + PUBKEY_SLOTS; +/// Offset in the one-way counter array for boot0 key revocations. Provisions for up to four +/// key slots, from [76..=80]. +pub const BOOT0_REVOCATION_DUPE_OFFSET: usize = BOOT1_REVOCATION_DUPE_OFFSET + PUBKEY_SLOTS; + +/// Fixed offset between the main key and the duplicate key +pub const REVOCATION_DUPE_DISTANCE: usize = LOADER_REVOCATION_OFFSET - LOADER_REVOCATION_DUPE_OFFSET; + encode_oneway! { #[offset = 80] pub enum BootWaitCoding { @@ -142,8 +177,6 @@ encode_oneway! { } } -/// Total number of public key slots in the system. Pubkey revocations are at the "top of range" -pub const PUBKEY_SLOTS: usize = 4; /// Offset in the one-way counter array for loader key revocations. Provisions for up to four /// key slots, from [116..=120]. pub const LOADER_REVOCATION_OFFSET: usize = 116; diff --git a/libs/bao1x-api/src/offsets/dabao.rs b/libs/bao1x-api/src/offsets/dabao.rs index 7e9477da4..6c4eb3ba4 100644 --- a/libs/bao1x-api/src/offsets/dabao.rs +++ b/libs/bao1x-api/src/offsets/dabao.rs @@ -43,6 +43,9 @@ pub const DATA_SLOTS: [SlotIndex; 8] = [ crate::offsets::DEV_PUBKEY, ]; -pub use crate::baosec::{CHAFF_KEYS, NUISANCE_KEYS, NUISANCE_KEYS_0, NUISANCE_KEYS_1, RMA_KEY, ROOT_SEED}; +pub use crate::baosec::{ + CHAFF_KEYS, NUISANCE_KEYS, NUISANCE_KEYS_0, NUISANCE_KEYS_1, RMA_KEY, ROOT_SEED, THE_FLAG_1, +}; -pub const KEY_SLOTS: [SlotIndex; 5] = [ROOT_SEED, RMA_KEY, NUISANCE_KEYS_0, NUISANCE_KEYS_1, CHAFF_KEYS]; +pub const KEY_SLOTS: [SlotIndex; 6] = + [THE_FLAG_1, ROOT_SEED, RMA_KEY, NUISANCE_KEYS_0, NUISANCE_KEYS_1, CHAFF_KEYS];