feat(core): handle bkpt instruction in unprivileged mode
What changed, and why it matters
This firmware update changes how the Trezor device handles a special ARM processor instruction called BKPT when it is executed by low-privilege code (unprivileged mode). Previously, such a breakpoint could escalate into a HardFault and reboot the device with a red screen of death (RSOD). Now the firmware enables the DebugMonitor exception and routes it to a controlled task-exit handler, turning a potential crash into a managed fault. The commit does not describe this as a security vulnerability, but it removes a denial-of-service path that could be triggered by unprivileged applets or code.
Treat as a hardening/DoS-mitigation fix. Review whether unprivileged applets or user-loaded code can issue BKPT and confirm the RDP 0.5+ deployment assumption. Consider adding a changelog or advisory note if this was externally reported.
Security signals we found
Prevents unprivileged BKPT from escalating to HardFault/RSOD reboot
Adds DebugMonitor exception handler that exits the faulting task
Comment explicitly notes remaining RSOD behavior at RDP level 0 on Secure-Monitor devices
No changelog entry and no CVE/advisory reference in commit
Evidence from the diff
The patch enables the ARM DebugMonitor exception (CoreDebug->DEMCR.MON_EN) and lowers its priority so that a BKPT instruction executed in unprivileged (thread) mode is caught by DebugMon_Handler instead of escalating to a HardFault. The handler saves MSP/LR and branches to systask_exit_fault, which terminates the offending task. A new fault-type string “DM” is added to system_fault_message for both STM32U5 and STM32H5 fault-reporting paths. The commit notes that on devices with a Secure Monitor, DebugMonitor is routed to Secure state at RDP level 0, so the fix is only effective at RDP 0.5+; at RDP 0 a breakpoint still causes an RSOD reboot.
Changed components
core/embed/sys/task/stm32/systask.ccore/embed/sys/task/stm32/system.cTrezor Core firmware task scheduler / fault handling on STM32Inspect captured patch +22 / −0
### core/embed/sys/task/stm32/systask.c
@@ -106,6 +106,7 @@ void systask_scheduler_init(systask_error_handler_t error_handler) {
// generally a blocking operation
NVIC_SetPriority(SVCall_IRQn, IRQ_PRI_LOWEST);
NVIC_SetPriority(PendSV_IRQn, IRQ_PRI_LOWEST);
+ NVIC_SetPriority(DebugMonitor_IRQn, IRQ_PRI_LOWEST);
// Enable BusFault and UsageFault handlers
SCB->SHCSR |= (SCB_SHCSR_USGFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk);
@@ -115,6 +116,13 @@ void systask_scheduler_init(systask_error_handler_t error_handler) {
SCB->SHCSR |= SCB_SHCSR_SECUREFAULTENA_Msk;
#endif
+ // Enable DebugMonitor so the kernel can handle unprivileged BKPT
+ // instructions without a HardFault.
+ // On devices with a Secure Monitor, this requires RDP level 0.5 or higher.
+ // At RDP level 0, DebugMonitor is routed to Secure state instead.
+ // A breakpoint then causes a reboot with RSOD.
+ CoreDebug->DEMCR |= CoreDebug_DEMCR_MON_EN_Msk;
+
#ifdef USE_APPLETS
scheduler->watchdog = systimer_create(systask_watchdog_callback, NULL);
ensure_true(scheduler->watchdog != NULL, "Failed to create watchdog timer");
@@ -1177,6 +1185,14 @@ __attribute__((naked, no_stack_protector)) void NMI_Handler(void) {
);
}
+__attribute__((naked, no_stack_protector)) void DebugMon_Handler(void) {
+ __asm__ volatile(
+ "MRS R0, MSP \n" // R0 = MSP
+ "MOV R1, LR \n" // R1 = EXC_RETURN code
+ "B systask_exit_fault \n" // Exit task with fault
+ );
+}
+
void Default_IRQHandler(void) { error_shutdown("Unhandled IRQ"); }
#endif // KERNEL_MODE
### core/embed/sys/task/stm32/system.c
@@ -191,6 +191,9 @@ const char* system_fault_message(const system_fault_t* fault) {
case GTZC_IRQn:
fault_type = "IA";
break;
+ case DebugMonitor_IRQn:
+ fault_type = "DM";
+ break;
case NonMaskableInt_IRQn:
fault_type = "CS";
break;
@@ -219,6 +222,9 @@ const char* system_fault_message(const system_fault_t* fault) {
case UsageFault_IRQn:
fault_type = "UF";
break;
+ case DebugMonitor_IRQn:
+ fault_type = "DM";
+ break;
case NonMaskableInt_IRQn:
fault_type = "CS";
break;Why this scored 41/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.