diff --git a/bao1x-boot/boot0/src/main.rs b/bao1x-boot/boot0/src/main.rs index e47359ea7..f38bbec11 100644 --- a/bao1x-boot/boot0/src/main.rs +++ b/bao1x-boot/boot0/src/main.rs @@ -15,10 +15,10 @@ use alloc::collections::VecDeque; use core::cell::RefCell; use bao1x_api::pubkeys::{BOOT0_SELF_CHECK, BOOT0_TO_ALTBOOT1, BOOT0_TO_BOOT1}; -use bao1x_api::{BOOT0_PUBKEY_FAIL, DEVELOPER_MODE, bollard}; +use bao1x_api::{BOOT0_PUBKEY_FAIL, BOOT1_PUBKEY_FAIL, DEVELOPER_MODE, bollard}; use bao1x_api::{HardenedBool, PARANOID_MODE, PARANOID_MODE_DUPE}; use bao1x_hal::acram::OneWayCounter; -use bao1x_hal::hardening::{check_pll, die, mesh_setup}; +use bao1x_hal::hardening::{Csprng, check_pll, die, mesh_setup}; use bao1x_hal::sigcheck::{hardened_erase_policy, jump_to}; #[cfg(feature = "unsafe-dev")] use critical_section::Mutex; @@ -114,39 +114,26 @@ pub unsafe extern "C" fn rust_entry() -> ! { bollard!(die, 4); let owc = OneWayCounter::new(); - // check that the boot0 pub keys match those burned into the indelible key area - // glitch_safety: I'd imagine that glitching in this routine would lead to good_compare being `false`, - // so no additional hardening is done. - let pubkey_ptr = bao1x_api::BOOT0_START as *const bao1x_api::signatures::SignatureInFlash; - let pk_src: &bao1x_api::signatures::SignatureInFlash = unsafe { pubkey_ptr.as_ref().unwrap() }; - let reference_keys = - [bao1x_api::BAO1_PUBKEY, bao1x_api::BAO2_PUBKEY, bao1x_api::BETA_PUBKEY, bao1x_api::DEV_PUBKEY]; let slot_mgr = bao1x_hal::acram::SlotManager::new(); - let mut good_compare = HardenedBool::TRUE; - for (boot0_key, ref_key) in pk_src.sealed_data.pubkeys.iter().zip(reference_keys.iter()) { - let ref_data = slot_mgr.read(&ref_key).unwrap(); - if ref_data != &boot0_key.pk { - good_compare = HardenedBool::FALSE; - } - } - csprng.random_delay(); - match good_compare.is_true() { - Some(false) => { - bollard!(die, 4); - // safety: the offset is from a pre-validated constant, which meets the safety requirement - unsafe { - owc.inc(BOOT0_PUBKEY_FAIL).unwrap(); - } - // erase secrets if the boot0 pubkey doesn't check out. - bollard!(die, 4); - bao1x_hal::sigcheck::erase_secrets(&mut Some(&mut csprng)) - .inspect_err(|e| crate::println!("{}", e)) - .ok(); // "ok" because the expected error is a check on logic/configuration bugs, not attacks - } - Some(true) => (), - None => die(), - } + // check that the pubkeys in boot0 matches the reference keys + compare_refkeys( + &owc, + &slot_mgr, + &mut csprng, + bao1x_api::BOOT0_START as *const bao1x_api::signatures::SignatureInFlash, + BOOT0_PUBKEY_FAIL, + ); + bollard!(die, 4); + + // check that the pubkeys in boot1 matches the reference keys + compare_refkeys( + &owc, + &slot_mgr, + &mut csprng, + bao1x_api::BOOT1_START as *const bao1x_api::signatures::SignatureInFlash, + BOOT1_PUBKEY_FAIL, + ); bollard!(die, 4); let (paranoid1, paranoid2) = owc.hardened_get2(PARANOID_MODE, PARANOID_MODE_DUPE).unwrap(); @@ -251,3 +238,51 @@ fn print_ifr() { } crate::println!(""); } + +/// check that pub keys in the images match those burned into the indelible key area +/// glitch_safety: I'd imagine that glitching in this routine would lead to good_compare being `false`, +/// so no additional hardening is done. +fn compare_refkeys( + owc: &OneWayCounter, + slot_mgr: &bao1x_hal::acram::SlotManager, + csprng: &mut Csprng, + pubkey_ptr: *const bao1x_api::signatures::SignatureInFlash, + fail_counter: usize, +) { + let reference_keys = + [bao1x_api::BAO1_PUBKEY, bao1x_api::BAO2_PUBKEY, bao1x_api::BETA_PUBKEY, bao1x_api::DEV_PUBKEY]; + // check that the pub keys match those burned into the indelible key area + // glitch_safety: I'd imagine that glitching in this routine would lead to good_compare being `false`, + // so no additional hardening is done. + let pk_src: &bao1x_api::signatures::SignatureInFlash = unsafe { pubkey_ptr.as_ref().unwrap() }; + let mut good_compare = HardenedBool::TRUE; + for (boot0_key, ref_key) in pk_src.sealed_data.pubkeys.iter().zip(reference_keys.iter()) { + let ref_data = slot_mgr.read(&ref_key).unwrap(); + if ref_data != &boot0_key.pk { + good_compare = HardenedBool::FALSE; + } + } + + csprng.random_delay(); + match good_compare.is_true() { + Some(false) => { + bollard!(die, 4); + // don't over-increment this to avoid RRAM wear-out. However, do allow it to increment to higher + // than 1 so we have a higher hamming distance on the counter than a single bit. + if owc.get(fail_counter).unwrap() < 15 { + // safety: the offset is from a pre-validated constant, which meets the safety requirement + unsafe { + owc.inc(fail_counter).unwrap(); + } + } + // erase secrets (or ensure they are erased) if the boot pubkey doesn't check out. + bollard!(die, 4); + bao1x_hal::sigcheck::erase_secrets(&mut Some(csprng)) + .inspect_err(|e| crate::println!("{}", e)) + .ok(); // "ok" because the expected error is a check on logic/configuration bugs, not attacks + } + Some(true) => (), + None => die(), + } + bollard!(die, 4); +} diff --git a/bao1x-boot/boot1/src/repl.rs b/bao1x-boot/boot1/src/repl.rs index 24c23797d..002189865 100644 --- a/bao1x-boot/boot1/src/repl.rs +++ b/bao1x-boot/boot1/src/repl.rs @@ -424,6 +424,10 @@ impl Repl { crate::println!("== BOOT0 REPORTED PUBKEY CHECK FAILURE =="); secure = false; } + if owc.get(BOOT1_PUBKEY_FAIL).unwrap() != 0 { + crate::println!("== BOOT1 REPORTED PUBKEY CHECK FAILURE =="); + secure = false; + } if owc.get(CP_BOOT_SETUP_DONE).unwrap() == 0 { crate::println!("== CP SETUP FAILED =="); secure = false; diff --git a/libs/bao1x-api/src/offsets/common.rs b/libs/bao1x-api/src/offsets/common.rs index e1d1a2831..364941872 100644 --- a/libs/bao1x-api/src/offsets/common.rs +++ b/libs/bao1x-api/src/offsets/common.rs @@ -151,6 +151,10 @@ pub const OEM_MODE: usize = 86; /// This is incremented if the boot0 public keys failed to compare against the static keys in /// the data store. pub const BOOT0_PUBKEY_FAIL: usize = 87; +/// This is incremented if the boot1 public keys failed to compare against the static keys in +/// the data store. Note that on Alpha-rev dabaos, this was used to track the initialization +/// of dabao security state, and so this may be set already due to that use. +pub const BOOT1_PUBKEY_FAIL: usize = 88; encode_oneway! { #[offset = 90]