add routine to lock keys if loader cannot verify kernel

Doesn't do enough to protect against glitch attacks but at least
it narrows the window where the keys are trivially readable if
code exec is achieved.
This commit is contained in:
bunnie 2022-02-03 22:01:24 +08:00
parent 8fa4499c14
commit 6d6b62ae60

View file

@ -241,6 +241,12 @@ impl Keyrom {
}
ed25519_dalek::PublicKey::from_bytes(&pk_bytes).or(Err("invalid public key"))
}
/// locks all the keys from future read-out
pub fn lock(&mut self) {
for i in 0..256 {
self.csr.wfo(utra::keyrom::LOCKADDR_LOCKADDR, i);
}
}
}
// returns true if the kernel is valid
@ -435,11 +441,13 @@ fn die() {
let mut power = CSR::new(utra::power::HW_POWER_BASE as *mut u32);
let mut com = CSR::new(utra::com::HW_COM_BASE as *mut u32);
let mut start = ticktimer.rf(utra::ticktimer::TIME0_TIME);
let mut keyrom = Keyrom::new();
keyrom.lock();
loop {
// every 15 seconds, attempt to send a power down command
// any attempt to re-flash the system must halt the CPU before we time-out to this point!
if ticktimer.rf(utra::ticktimer::TIME0_TIME) - start > 15_000 {
println!("Powering down...");
println!("Powering down, keyrom locked...");
power.rmwf(utra::power::POWER_STATE, 0);
power.rmwf(utra::power::POWER_SELF, 0);
@ -448,6 +456,7 @@ fn die() {
while com.rf(utra::com::STATUS_TIP) == 1 {}
let _ = com.rf(utra::com::RX_RX); // discard the RX result
start = ticktimer.rf(utra::ticktimer::TIME0_TIME);
keyrom.lock();
}
}
}