mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
ensure secret erasure if developer mode bit is set
this is the final part of the developer mode bit hardening. If an adversary manages to increment the developer mode bit, the next reboot they have to contend with active counter- measures that would attempt to erase the secrets due to the developer mode bit being set. As noted in the top of the commit set, previously, without this, the attacker would have the luxury of being able to flip the bit and try many times to bypass the developer mode check.
This commit is contained in:
parent
15ac4d8529
commit
66272a82e4
4 changed files with 50 additions and 52 deletions
|
|
@ -15,7 +15,7 @@ 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, bollard};
|
||||
use bao1x_api::{BOOT0_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};
|
||||
|
|
@ -172,6 +172,25 @@ pub unsafe extern "C" fn rust_entry() -> ! {
|
|||
bollard!(die, 4);
|
||||
// == end self validation ==
|
||||
|
||||
// If the developer bit is set, ensure that keys are erased. The edge case we're worried about is
|
||||
// if an attacker sets developer bit, even with signed images - this can allow for an easier
|
||||
// time of booting a malicious kernel because we can't erase secret keys inside the loader
|
||||
// due to access restrictions.
|
||||
csprng.random_delay();
|
||||
let (dev1, dev2) = owc.hardened_get(DEVELOPER_MODE).unwrap();
|
||||
if dev1 != 0 {
|
||||
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
|
||||
}
|
||||
bollard!(die, 4);
|
||||
csprng.random_delay();
|
||||
if dev2 != 0 {
|
||||
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
|
||||
}
|
||||
|
||||
bollard!(die, 4);
|
||||
let boot_order = match owc.get_decoded::<bao1x_api::AltBootCoding>() {
|
||||
// Primary boot selected. Check Boot1 first, then fall back to LOADER/BAREMETAL.
|
||||
|
|
|
|||
|
|
@ -71,7 +71,10 @@ pub fn setup_backup_region() -> u32 {
|
|||
let mut bu_mgr = bao1x_hal::buram::BackupManager::new();
|
||||
if !bu_mgr.is_backup_valid() {
|
||||
// zeroize the backup RAM
|
||||
bu_mgr.bu_ram_as_mut().fill(0);
|
||||
// safety: make_valid is called after this is done.
|
||||
unsafe {
|
||||
bu_mgr.bu_ram_as_mut().fill(0);
|
||||
}
|
||||
// calculate the hash and mark as valid
|
||||
bu_mgr.make_valid();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ pub fn check_slots(board_type: &bao1x_api::BoardTypeCoding) {
|
|||
let mut rram = Reram::new();
|
||||
|
||||
// check the lifecycle status
|
||||
// glitch_safety: this is done in a controlled environment, and not done again later,
|
||||
// so we don't need to harden it. If it is repeated due to a glitch it actually leads to data loss.
|
||||
if owc.get(bao1x_api::CP_BOOT_SETUP_DONE).unwrap() == 0 {
|
||||
crate::println!("CP setup not yet done. Initializing public identifiers...");
|
||||
// CP boot setup is not done. Initialize the basic identifiers.
|
||||
|
|
@ -72,52 +74,6 @@ pub fn check_slots(board_type: &bao1x_api::BoardTypeCoding) {
|
|||
crate::println!("Public ID init done.");
|
||||
}
|
||||
|
||||
// Delegate in-system key setup to the OS. Don't do it in the bootloader. This code is
|
||||
// too hard to get right to be doing it here, and there is no ostensible security advantage
|
||||
// in doing it at this stage versus in the system. Reasoning: the in-system key setup would
|
||||
// be done in the factory, post-wafer probe, regardless. Whether it's hard-coded into the boot1
|
||||
// stage or left to be flexible based on the OS's needs doesn't make a difference because the
|
||||
// point of keying is still going to be the factory.
|
||||
/*
|
||||
if (*board_type == bao1x_api::BoardTypeCoding::Baosec
|
||||
&& owc.get(bao1x_api::IN_SYSTEM_BOOT_SETUP_DONE).unwrap() == 0)
|
||||
|| (*board_type == bao1x_api::BoardTypeCoding::Dabao
|
||||
&& owc.get(bao1x_api::INVOKE_DABAO_KEY_SETUP).unwrap() != 0
|
||||
&& owc.get(bao1x_api::DABAO_KEY_SETUP_DONE).unwrap() == 0)
|
||||
{
|
||||
crate::println!("System setup not yet done. Initializing secret identifiers...");
|
||||
let trng = maybe_trng.get_or_insert_with(|| super::trng::ManagedTrng::new(&board_type));
|
||||
// generate all the keys
|
||||
let key_set = if *board_type == bao1x_api::BoardTypeCoding::Baosec {
|
||||
&bao1x_api::baosec::KEY_SLOTS[..]
|
||||
} else {
|
||||
&bao1x_api::dabao::KEY_SLOTS[..]
|
||||
};
|
||||
for key_range in key_set.iter() {
|
||||
let mut storage = alloc::vec::Vec::with_capacity(key_range.len() * SLOT_ELEMENT_LEN_BYTES);
|
||||
storage.resize(key_range.len() * SLOT_ELEMENT_LEN_BYTES, 0);
|
||||
for chunk in storage.chunks_mut(SLOT_ELEMENT_LEN_BYTES) {
|
||||
chunk.copy_from_slice(&trng.generate_key());
|
||||
}
|
||||
match slot_mgr.write(&mut rram, key_range, &storage) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
crate::println!("Couldn't initialize slot {:?}: {:?}", key_range, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// once all values are written, advance the IN_SYSTEM_BOOT_SETUP_DONE state
|
||||
// safety: the offset is correct because we're pulling it from our pre-defined constants and
|
||||
// those are manually checked.
|
||||
if *board_type == bao1x_api::BoardTypeCoding::Baosec {
|
||||
unsafe { owc.inc(bao1x_api::IN_SYSTEM_BOOT_SETUP_DONE).unwrap() };
|
||||
} else if *board_type == bao1x_api::BoardTypeCoding::Dabao {
|
||||
unsafe { owc.inc(bao1x_api::DABAO_KEY_SETUP_DONE).unwrap() };
|
||||
}
|
||||
crate::println!("Secret ID init done.");
|
||||
}
|
||||
*/
|
||||
|
||||
#[cfg(feature = "print-ifr")]
|
||||
print_ifr();
|
||||
|
||||
|
|
@ -128,11 +84,13 @@ pub fn check_slots(board_type: &bao1x_api::BoardTypeCoding) {
|
|||
// wear-out on the ACL entries as every time a transition is made into a developer images, a set
|
||||
// of keys are checked to be erased. While it is possible to bypass the ACL checks by flipping
|
||||
// the developer mode bit, the key check/erasure would still happen upon launch into developer mode.
|
||||
//
|
||||
// glitch_safety: we don't harden this because this is already a "seatbelt" safety measure
|
||||
// in most cases it should do nothing because the ACLs are already correct. Also, if DEVELOPER_MODE
|
||||
// is tripped, there is a hardened check that ensures keys are erased when that bit is set.
|
||||
#[cfg(feature = "unsafe-debug")]
|
||||
print_slots(&slot_mgr, &bao1x_api::baosec::KEY_SLOTS); // this prints all the keys as they are created
|
||||
if (*board_type == bao1x_api::BoardTypeCoding::Baosec || *board_type == bao1x_api::BoardTypeCoding::Dabao)
|
||||
&& owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0
|
||||
{
|
||||
if owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0 {
|
||||
#[cfg(feature = "unsafe-debug")]
|
||||
print_slots(&slot_mgr, &bao1x_api::baosec::KEY_SLOTS);
|
||||
check_and_fix_acls(&mut rram, &mut slot_mgr, &bao1x_api::baosec::KEY_SLOTS);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use bao1x_api::{PARANOID_MODE, PARANOID_MODE_DUPE, bollard, pubkeys::BOOT1_TO_LOADER_OR_BAREMETAL};
|
||||
use bao1x_api::{
|
||||
DEVELOPER_MODE, PARANOID_MODE, PARANOID_MODE_DUPE, bollard, pubkeys::BOOT1_TO_LOADER_OR_BAREMETAL,
|
||||
};
|
||||
use bao1x_hal::hardening::Csprng;
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -19,6 +21,22 @@ fn seal_boot1_keys() {
|
|||
pub fn try_boot(or_die: bool, csprng: &mut Csprng) {
|
||||
let one_way = bao1x_hal::acram::OneWayCounter::new();
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
|
||||
// If the developer bit is set, ensure that keys are erased. The edge case we're worried about is
|
||||
// if an attacker sets developer bit, even with signed images - this can allow for an easier
|
||||
// time of booting a malicious kernel because we can't erase secret keys inside the loader
|
||||
// due to access restrictions.
|
||||
csprng.random_delay();
|
||||
let (dev1, dev2) = one_way.hardened_get(DEVELOPER_MODE).unwrap();
|
||||
if dev1 != 0 {
|
||||
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
|
||||
}
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
csprng.random_delay();
|
||||
if dev2 != 0 {
|
||||
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
|
||||
}
|
||||
|
||||
csprng.random_delay();
|
||||
let (paranoid1, paranoid2) = one_way.hardened_get2(PARANOID_MODE, PARANOID_MODE_DUPE).unwrap();
|
||||
csprng.random_delay();
|
||||
|
|
|
|||
Loading…
Reference in a new issue