fix(core/secmon): block smcalls invoked from unprivileged mode
What changed, and why it matters
This commit fixes a security hole in the Trezor hardware wallet's secure monitor (secmom). The secure monitor is a trusted piece of firmware that handles sensitive 'smcall' requests. Previously, these calls could be made from unprivileged (less trusted) code. The patch now blocks smcalls from unprivileged mode and triggers a fatal error or reboot if such a call is attempted. This prevents untrusted code from tricking the secure monitor into performing privileged operations.
Apply this patch promptly. Review other secure-monitor entry points for similar missing privilege checks. Consider whether any legitimate unprivileged code paths relied on smcalls and adjust accordingly.
Security signals we found
Privilege escalation mitigation
Secure monitor hardening
Fault injection hardening (FIH)
Unprivileged smcall blocking
TrustZone non-secure caller privilege enforcement
Evidence from the diff
The patch modifies smcall_invoke in core/embed/sys/smcall/stm32/smcall_dispatch.c to enforce that smcalls may only be invoked from a non-secure privileged context. It adds is_caller_privileged(), which checks whether the CPU is in Thread mode and the non-secure CONTROL register indicates unprivileged execution. The function now performs three privilege checks: one before argument validation, one after (using fault injection hardening / FIH), and one before returning. If unprivileged access is detected, the device either calls system_exit_fatal() or reboot_device(). This mitigates a privilege escalation path where non-secure unprivileged code could invoke secure-monitor calls.
Changed components
core/embed/sys/smcall/stm32/smcall_dispatch.cTrezor secure monitor (secmom)smcall_invoke handlerInspect captured patch +23 / −0
### core/embed/sys/smcall/stm32/smcall_dispatch.c
@@ -478,13 +478,36 @@ __attribute((no_stack_protector)) void smcall_handler(uint32_t *args,
}
}
+// Return true if the non-secure caller is privileged
+static inline bool is_caller_privileged(void) {
+ bool thread_mode = (__get_IPSR() & IPSR_ISR_Msk) == 0;
+ bool ns_unprivileged = (__TZ_get_CONTROL_NS() & CONTROL_nPRIV_Msk) != 0;
+ return !(thread_mode && ns_unprivileged);
+}
+
__attribute__((cmse_nonsecure_entry)) void smcall_invoke(
smcall_args_t *args, smcall_number_t smcall) {
+ // Allow only calls from non-secure privileged context (kernel)
+ if (!is_caller_privileged()) {
+ system_exit_fatal("Unprivileged smcall", __FILE__, __LINE__);
+ }
+
if (!probe_write_access(args, sizeof(*args))) {
system_exit_fatal("Invalid smcall args", __FILE__, __LINE__);
}
+ // FIH: check caller privilege again
+ if (!is_caller_privileged()) {
+ reboot_device();
+ }
+
smcall_handler(args->arg, smcall);
+
+ // FIH: check caller privilege again before returning
+ // (harder to bypass than the first check)
+ if (!is_caller_privileged()) {
+ reboot_device();
+ }
}
#endif // SECMONWhy this scored 76/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.