mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
other boot0 hardening
- harden the check that the boot0 public keys match those in the data array - security mesh setup - insertion of random delays & bollards - upgrade API on signature verification to allow for random delays during the signature check
This commit is contained in:
parent
b00acba907
commit
1c210b3541
2 changed files with 54 additions and 14 deletions
|
|
@ -14,8 +14,10 @@ use alloc::collections::VecDeque;
|
|||
#[cfg(feature = "unsafe-dev")]
|
||||
use core::cell::RefCell;
|
||||
|
||||
use bao1x_api::{BOOT0_PUBKEY_FAIL, signatures::FunctionCode};
|
||||
use bao1x_api::HardenedBool;
|
||||
use bao1x_api::{BOOT0_PUBKEY_FAIL, bollard, signatures::FunctionCode};
|
||||
use bao1x_hal::acram::OneWayCounter;
|
||||
use bao1x_hal::hardening::{check_pll, die, mesh_setup};
|
||||
#[cfg(feature = "unsafe-dev")]
|
||||
use critical_section::Mutex;
|
||||
use platform::*;
|
||||
|
|
@ -53,15 +55,27 @@ pub fn uart_irq_handler() {
|
|||
#[export_name = "rust_entry"]
|
||||
pub unsafe extern "C" fn rust_entry() -> ! {
|
||||
// set the security bits on the RRAM - without these set, most security is bypassed
|
||||
// this issue is fixed on A1 silicon stepping (which is production silicon).
|
||||
// this issue is fixed on A1 silicon stepping (which is production silicon)
|
||||
// glitch_safety: this is fixed by metal mask so no hardening is needed
|
||||
let mut rram = CSR::new(utra::rrc::HW_RRC_BASE as *mut u32);
|
||||
rram.wfo(utra::rrc::SFR_RRCCR_SFR_RRCCR, bao1x_hal::rram::SECURITY_MODE);
|
||||
// set user level so we can access keys
|
||||
|
||||
// set user level so we can access keys.
|
||||
// glitch_safety: failing to execute this would actually reduce access permissions
|
||||
let mut cu = bao1x_hal::coreuser::Coreuser::new();
|
||||
cu.set();
|
||||
|
||||
crate::platform::early_init();
|
||||
let mut csprng = crate::platform::early_init();
|
||||
csprng.random_delay();
|
||||
|
||||
bollard!(4);
|
||||
// Mesh check takes 100ms for the signal to propagate. Setup the mesh check here, then check the
|
||||
// result in boot1. In boot1, the opposite state (`true`) is checked.
|
||||
mesh_setup(false, None);
|
||||
bollard!(4);
|
||||
|
||||
crate::println!("\n~~boot0 up! ({})~~\n", crate::version::SEMVER);
|
||||
csprng.random_delay(); // always random-delay after printing
|
||||
|
||||
#[cfg(feature = "unsafe-dev")]
|
||||
let mut repl = crate::repl::Repl::new();
|
||||
|
|
@ -92,28 +106,45 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
|||
#[cfg(feature = "print-ifr")]
|
||||
print_ifr();
|
||||
|
||||
// glitch_safety: another delay and PLL check, for good measure
|
||||
csprng.random_delay();
|
||||
check_pll();
|
||||
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 = true;
|
||||
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 = false;
|
||||
good_compare = HardenedBool::FALSE;
|
||||
}
|
||||
}
|
||||
if !good_compare {
|
||||
let owc = OneWayCounter::new();
|
||||
// safety: the offset is from a pre-validated constant, which meets the safety requirement
|
||||
unsafe {
|
||||
owc.inc(BOOT0_PUBKEY_FAIL).unwrap();
|
||||
|
||||
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));
|
||||
}
|
||||
// erase secrets if the boot0 pubkey doesn't check out.
|
||||
bao1x_hal::sigcheck::erase_secrets();
|
||||
Some(true) => (),
|
||||
None => die(),
|
||||
}
|
||||
bollard!(die, 4);
|
||||
|
||||
// self-validate the image with the keys we put in, just to make sure our code wasn't tampered with
|
||||
if bao1x_hal::sigcheck::validate_image(
|
||||
bao1x_api::BOOT0_START as *const u32,
|
||||
|
|
@ -122,10 +153,13 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
|||
&[FunctionCode::Boot0 as u32], // only boot0 is allowed for boot0
|
||||
false,
|
||||
None,
|
||||
Some(&mut csprng),
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
seal_boot0_keys();
|
||||
bollard!(die, 4);
|
||||
|
||||
let allowed_functions =
|
||||
[FunctionCode::Boot1 as u32, FunctionCode::UpdatedBoot1 as u32, FunctionCode::Developer as u32];
|
||||
let one_way_access = bao1x_hal::acram::OneWayCounter::new();
|
||||
|
|
@ -139,6 +173,7 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
|||
&allowed_functions,
|
||||
true,
|
||||
None,
|
||||
Some(&mut csprng),
|
||||
)
|
||||
.ok();
|
||||
bao1x_hal::sigcheck::validate_image(
|
||||
|
|
@ -148,6 +183,7 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
|||
&allowed_functions,
|
||||
true,
|
||||
None,
|
||||
Some(&mut csprng),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
|
|
@ -160,6 +196,7 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
|||
&allowed_functions,
|
||||
true,
|
||||
None,
|
||||
Some(&mut csprng),
|
||||
)
|
||||
.ok();
|
||||
bao1x_hal::sigcheck::validate_image(
|
||||
|
|
@ -169,6 +206,7 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
|||
&allowed_functions,
|
||||
true,
|
||||
None,
|
||||
Some(&mut csprng),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,8 +140,9 @@ impl Repl {
|
|||
&[FunctionCode::Boot0 as u32], // only boot0 is allowed for boot0
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
) {
|
||||
Ok(key_number) => crate::println!("sigcheck passed on key {}", key_number),
|
||||
Ok(key_number, _key_number2, _id) => crate::println!("sigcheck passed on key {}", key_number),
|
||||
Err(e) => crate::println!("sigcheck failed: {}", e),
|
||||
},
|
||||
"reps" => {
|
||||
|
|
@ -169,6 +170,7 @@ impl Repl {
|
|||
&[FunctionCode::Boot0 as u32], // only boot0 is allowed for boot0
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.ok();
|
||||
count += 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue