mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add boot1 pubkey integrity checking
this should erase the secret keys if the boot1 pubkeys don't match this enables OEM-signed boot1 images. the policy is that all OEM images signed by baochip are considered to be untrusted, and thus loading them onto a device would wipe any secret keys, making them less useful for extracting secrets. There are 2048 keys and about 500 keys are used by baochip, so there are still plenty of keyslots available for OEMs to use to implement their own version of security.
This commit is contained in:
parent
49e526f60b
commit
0c690d8be4
3 changed files with 76 additions and 33 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue