From 6d6b62ae6044c1fa21bea9093104099c3e28c8f0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 3 Feb 2022 22:01:24 +0800 Subject: [PATCH] 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. --- loader/src/secboot.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/loader/src/secboot.rs b/loader/src/secboot.rs index 8b2b49c21..71c39f5bd 100644 --- a/loader/src/secboot.rs +++ b/loader/src/secboot.rs @@ -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(); } } } \ No newline at end of file