From a208d59690c49f33983b15bed3840d405c39a614 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 18 Nov 2025 23:33:33 +0800 Subject: [PATCH] deny boot to any developer-key signed kernel/detached-app/swap images Secret keys can't be erased after boot1 exits because the protection bits are hardened from modification after that point. thus it is not possible for the loader to switch the device into developer mode. Thus the only way to enter developer mode is through a dev-mode signed loader. A system that has never been put into developer mode will refuse to run any developer-mode xous kernel, app, swap images. Once a system has been exposed to a dev-mode signed loader, the boot1 will flip the developer mode bit and erase the secret keys. Later on, if a production loader is replaced, it doesn't matter that a production loader is loading dev-mode signed successors because the secret keys are already erased. Note that in all cases, the key revocations take precedence so if the developer key is revoked, these cases should never even be encountered. --- loader/src/main.rs | 28 ++++++++++++++++++++++++---- loader/src/platform/bao1x/swap.rs | 16 ++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/loader/src/main.rs b/loader/src/main.rs index 8931ee4af..b0f2d33aa 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -281,8 +281,17 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) if tag == *bao1x_api::pubkeys::KEYSLOT_INITIAL_TAGS[bao1x_api::pubkeys::DEVELOPER_KEY_SLOT] || k == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT { - crate::println!("Developer key detected, ensuring secrets are erased"); - bao1x_hal::sigcheck::erase_secrets(); + // we can't erase keys in the loader, because the keys have already been locked + // out at this point. Thus, ensure that the system is already in developer mode. + let owc = bao1x_hal::acram::OneWayCounter::new(); + if owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0 { + crate::println!( + "Kernel is devkey signed, but system is not in developer mode. Dying!" + ); + bao1x_hal::sigcheck::die_no_std(); + } else { + crate::println!("Developer key detected on kernel. Proceeding in developer mode!"); + } } } Err(e) => { @@ -315,8 +324,19 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32) == *bao1x_api::pubkeys::KEYSLOT_INITIAL_TAGS[bao1x_api::pubkeys::DEVELOPER_KEY_SLOT] || k == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT { - crate::println!("Developer key detected, ensuring secrets are erased"); - bao1x_hal::sigcheck::erase_secrets(); + // we can't erase keys in the loader, because the keys have already been locked + // out at this point. Thus, ensure that the system is already in developer mode. + let owc = bao1x_hal::acram::OneWayCounter::new(); + if owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0 { + crate::println!( + "Detached app is devkey signed, but system is not in developer mode. Dying!" + ); + bao1x_hal::sigcheck::die_no_std(); + } else { + crate::println!( + "Developer key detected on detached app. Proceeding in developer mode!" + ); + } } true } diff --git a/loader/src/platform/bao1x/swap.rs b/loader/src/platform/bao1x/swap.rs index 6c5d261c3..4b0785b00 100644 --- a/loader/src/platform/bao1x/swap.rs +++ b/loader/src/platform/bao1x/swap.rs @@ -256,8 +256,20 @@ impl SwapHal { [bao1x_api::pubkeys::DEVELOPER_KEY_SLOT] || k == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT { - crate::println!("Developer key detected, ensuring secrets are erased"); - bao1x_hal::sigcheck::erase_secrets(); + // we can't erase keys in the loader, because the keys have already been + // locked out at this point. Thus, + // ensure that the system is already in developer mode. + let owc = bao1x_hal::acram::OneWayCounter::new(); + if owc.get(bao1x_api::DEVELOPER_MODE).unwrap() == 0 { + crate::println!( + "Swap is devkey signed, but system is not in developer mode. Dying!" + ); + bao1x_hal::sigcheck::die_no_std(); + } else { + crate::println!( + "Developer key detected on swap. Proceeding in developer mode!" + ); + } } } Err(e) => {