fix(core): fix firmware build with extapp support
What changed, and why it matters
This commit fixes a firmware build problem when a feature called 'extapp support' is enabled. It changes which source files are compiled and adjusts code guards so that certain applet-related code is only included when both applets and kernel mode are active. There is no direct evidence this fixes a security vulnerability; it appears to be a build-system correction.
Treat as a normal build fix. Verify that firmware builds correctly with and without extapp/applet support and that applet-related security code remains excluded from non-kernel builds. No urgent security response is indicated by the diff alone.
Security signals we found
Conditional compilation guard tightened from USE_APPLETS to USE_APPLETS && KERNEL_MODE in security-relevant modules (secure_aes, coreapp, applet)
Build script corrected to use elf_loader.c source for STM32 app loader
Unconditional include of sys/applet.h removed from syscall internal header
Evidence from the diff
The patch corrects compilation for builds with external application (extapp/applet) support. Key changes: (1) build.rs now selects app_loader/stm32/elf_loader.c instead of app_loader/stm32/app_loader.c for STM32 targets; (2) several applet/coreapp/secure_aes files are wrapped with both USE_APPLETS and KERNEL_MODE rather than USE_APPLETS alone; (3) syscall_internal.h stops including sys/applet.h unconditionally. These are conditional-compilation hygiene fixes that prevent the wrong code from being built in non-kernel/applet configurations.
Changed components
core/embed/io/app_loader/build.rscore/embed/sec/secure_aes/inc/sec/secure_aes.hcore/embed/sec/secure_aes/stm32u5/secure_aes_unpriv.ccore/embed/sys/syscall/stm32/syscall_internal.hcore/embed/sys/task/applet.ccore/embed/sys/task/stm32/coreapp.cInspect captured patch +10 / −11
diff --git a/core/embed/io/app_loader/build.rs b/core/embed/io/app_loader/build.rs
index df59e728..6413feeb 100644
--- a/core/embed/io/app_loader/build.rs
+++ b/core/embed/io/app_loader/build.rs
@@ -18,7 +18,7 @@ pub fn def_module(lib: &mut CLibrary) -> Result<()> {
if cfg!(feature = "emulator") {
lib.add_source("app_loader/unix/elf_loader.c");
} else if cfg!(feature = "mcu_stm32") {
- lib.add_source("app_loader/stm32/app_loader.c");
+ lib.add_source("app_loader/stm32/elf_loader.c");
} else {
bail_unsupported!();
}
diff --git a/core/embed/sec/secure_aes/inc/sec/secure_aes.h b/core/embed/sec/secure_aes/inc/sec/secure_aes.h
index c6fc2fc8..f8408b76 100644
--- a/core/embed/sec/secure_aes/inc/sec/secure_aes.h
+++ b/core/embed/sec/secure_aes/inc/sec/secure_aes.h
@@ -21,7 +21,7 @@
#include <trezor_types.h>
-#ifdef USE_APPLETS
+#if defined(USE_APPLETS) && defined(KERNEL_MODE)
#include <sys/applet.h>
#endif
@@ -38,7 +38,7 @@ secbool secure_aes_init(void);
// Sets the applet to be used for AES operation
// with unprivileged key (XORK_SN).
-#ifdef USE_APPLETS
+#if defined(USE_APPLETS) && defined(KERNEL_MODE)
void secure_aes_set_applet(applet_t* applet);
#endif
diff --git a/core/embed/sec/secure_aes/stm32u5/secure_aes_unpriv.c b/core/embed/sec/secure_aes/stm32u5/secure_aes_unpriv.c
index c753d1ce..14dedc73 100644
--- a/core/embed/sec/secure_aes/stm32u5/secure_aes_unpriv.c
+++ b/core/embed/sec/secure_aes/stm32u5/secure_aes_unpriv.c
@@ -106,7 +106,7 @@ __attribute((no_stack_protector)) void saes_unpriv_callback(void) {
// -----------------------------------------------------------------------
// Code running privileged mode
-#ifdef USE_APPLETS
+#if defined(USE_APPLETS) && defined(KERNEL_MODE)
#include <sys/coreapp.h>
#include <sys/mpu.h>
@@ -182,4 +182,4 @@ secbool secure_aes_unpriv_encrypt(const uint8_t *input, size_t size,
return retval;
}
-#endif // USE_APPLETS
+#endif // USE_APPLETS && KERNEL_MODE
diff --git a/core/embed/sys/syscall/stm32/syscall_internal.h b/core/embed/sys/syscall/stm32/syscall_internal.h
index a37f632f..c0e55018 100644
--- a/core/embed/sys/syscall/stm32/syscall_internal.h
+++ b/core/embed/sys/syscall/stm32/syscall_internal.h
@@ -21,7 +21,6 @@
#include <trezor_types.h>
-#include <sys/applet.h>
#include <sys/syscall.h>
#include <sys/syscall_numbers.h>
diff --git a/core/embed/sys/task/applet.c b/core/embed/sys/task/applet.c
index ebe56f18..b779af9e 100644
--- a/core/embed/sys/task/applet.c
+++ b/core/embed/sys/task/applet.c
@@ -17,14 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#if defined(USE_APPLETS) && defined(KERNEL_MODE)
+
#include <trezor_rtl.h>
#include <sys/applet.h>
#include <sys/sysevent_source.h>
#include <sys/systask.h>
-#ifdef USE_APPLETS
-
void applet_init(applet_t* applet, const applet_privileges_t* privileges,
applet_unload_cb_t unload_cb) {
memset(applet, 0, sizeof(applet_t));
@@ -65,4 +65,4 @@ applet_t* applet_active(void) {
return (applet_t*)task->applet;
}
-#endif // USE_APPLETS
+#endif // USE_APPLETS && KERNEL_MODE
diff --git a/core/embed/sys/task/stm32/coreapp.c b/core/embed/sys/task/stm32/coreapp.c
index 966681b1..2ed25e0c 100644
--- a/core/embed/sys/task/stm32/coreapp.c
+++ b/core/embed/sys/task/stm32/coreapp.c
@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef USE_APPLETS
+#if defined(USE_APPLETS) && defined(KERNEL_MODE)
#include <trezor_model.h>
#include <trezor_rtl.h>
@@ -160,4 +160,4 @@ mpu_area_t coreapp_get_tls_area(void) { return coreapp_tls_area; }
void* coreapp_get_api_getter(void) { return coreapp_api_getter; }
-#endif // USE_APPLETS
+#endif // USE_APPLETS && KERNEL_MODE
Why this scored 18/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.