temporary_stack: whitelist temporary task function calls
What changed, and why it matters
This commit adds a whitelist to a special helper that lets certain functions run with extra memory stack space. Previously, any function could be passed to this helper. Now only a small list of approved functions is allowed, except during internal self-tests. This reduces the chance that an attacker could trick the device into running unexpected code with a larger stack, which could cause crashes or be exploited. It is a hardening change rather than a clear fix for a known active attack.
Treat as a security hardening improvement. Review whether any other call sites still pass arbitrary function pointers to `run_in_temporary_task`, and confirm the debug/selfcheck bypass is not present in production firmware builds. No immediate emergency response is warranted absent evidence of an exploitable vulnerability.
Security signals we found
Addition of function-pointer whitelist
Removal of static linkage on internal functions to enable whitelist comparison
Conditional bypass of whitelist only for debug/selfcheck builds
Hardening of a privileged helper that allocates a larger task stack
Evidence from the diff
The change modifies run_in_temporary_task in temporary_stack.c to validate the function pointer against a whitelist of known large-stack consumers: descriptor_search_for_script_impl, descriptor_to_address_impl, descriptor_to_script_impl, parse_psbt_bytes, and (when SPIRAM is available) verify_explicit_proofs. The affected functions are changed from static to non-static so their addresses can be compared in the whitelist. In debug/libjade selfcheck builds the whitelist is bypassed. This is a defensive measure against function-pointer confusion or misuse of the temporary-stack helper.
Changed components
main/utils/temporary_stack.cmain/descriptor.cmain/process/sign_psbt.cmain/process/sign_utils.cInspect captured patch +26 / −5
### main/descriptor.c
@@ -49,7 +49,7 @@ typedef struct {
char* addr_output;
} descriptor_evaluation_data_t;
-static bool descriptor_to_address_impl(void* ctx)
+bool descriptor_to_address_impl(void* ctx)
{
JADE_ASSERT(ctx);
descriptor_evaluation_data_t* const data = (descriptor_evaluation_data_t*)ctx;
@@ -63,7 +63,7 @@ static bool descriptor_to_address_impl(void* ctx)
== WALLY_OK;
}
-static bool descriptor_to_script_impl(void* ctx)
+bool descriptor_to_script_impl(void* ctx)
{
JADE_ASSERT(ctx);
descriptor_evaluation_data_t* const data = (descriptor_evaluation_data_t*)ctx;
@@ -100,7 +100,7 @@ static bool descriptor_to_script_impl(void* ctx)
return true;
}
-static bool descriptor_search_for_script_impl(void* ctx)
+bool descriptor_search_for_script_impl(void* ctx)
{
JADE_ASSERT(ctx);
descriptor_evaluation_data_t* const data = (descriptor_evaluation_data_t*)ctx;
### main/process/sign_psbt.c
@@ -1143,7 +1143,7 @@ typedef struct {
struct wally_psbt* psbt_out;
} psbt_parse_data_t;
-static bool parse_psbt_bytes(void* ctx)
+bool parse_psbt_bytes(void* ctx)
{
JADE_ASSERT(ctx);
psbt_parse_data_t* data = (psbt_parse_data_t*)ctx;
### main/process/sign_utils.c
@@ -346,7 +346,7 @@ bool asset_summary_validate(asset_summary_t* sums, const size_t num_sums)
// on a temporary stack, as the underlying libsecp calls require over 50kb of stack space.
// NOTE: devices without SPIRAM do not have sufficient free memory to be able to do this verification,
// so atm we exclude it for those devices.
-static bool verify_explicit_proofs(void* ctx)
+bool verify_explicit_proofs(void* ctx)
{
JADE_ASSERT(ctx);
### main/utils/temporary_stack.c
@@ -10,6 +10,15 @@
#define CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE 2048
#endif
+// run_in_temporary_task whitelist
+bool descriptor_search_for_script_impl(void* ctx);
+bool descriptor_to_address_impl(void* ctx);
+bool descriptor_to_script_impl(void* ctx);
+bool parse_psbt_bytes(void* ctx);
+#ifdef CONFIG_SPIRAM
+bool verify_explicit_proofs(void* ctx);
+#endif
+
// Helper to run function which may require a larger amount of stack space in a temporary task.
// Function protected by a mutex so can only be running once (prevents excessive memory
// allocation of multiple large stacks).
@@ -33,7 +42,19 @@ void temp_stack_init(void)
static void temp_task_wrapper(void* ctx)
{
temp_task_args_t* args = (temp_task_args_t*)ctx;
+#if defined(CONFIG_DEBUG_MODE) && defined(CONFIG_LIBJADE) && defined(SELFCHECK)
+ // Allow libjade selfchecks to call anything
JADE_ASSERT(args && args->fn);
+#else
+ // Use a whitelist of allowed calls
+ JADE_ASSERT(args);
+ bool is_allowed = args->fn == &descriptor_search_for_script_impl || args->fn == &descriptor_to_address_impl
+ || args->fn == &descriptor_to_script_impl || args->fn == &parse_psbt_bytes;
+#ifdef CONFIG_SPIRAM
+ is_allowed |= args->fn == &verify_explicit_proofs;
+#endif // CONFIG_SPIRAM
+ JADE_ASSERT(is_allowed);
+#endif // CONFIG_DEBUG_MODE / CONFIG_LIBJADE / SELFCHECK
// Run the passed function, then signal the completion semaphore
args->rslt = args->fn(args->ctx);Why this scored 42/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.