From 3a3693ccad1ddeaef238f29b5d7af0ea2dcbde16 Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Wed, 24 Mar 2021 13:14:19 +0100 Subject: [PATCH] modules: trusted-firmware-m: lock scheduler around secure calls Prevent a thread from being preempted, while executing a Secure function. This is required to prevent system crashes that could occur if a thead context switch is triggered in the middle of a Secure call. Signed-off-by: Ioannis Glaropoulos --- modules/trusted-firmware-m/interface/interface.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/trusted-firmware-m/interface/interface.c b/modules/trusted-firmware-m/interface/interface.c index 13bdb1bf1c985e..bf109923ab1f62 100644 --- a/modules/trusted-firmware-m/interface/interface.c +++ b/modules/trusted-firmware-m/interface/interface.c @@ -34,8 +34,19 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn, return (int32_t)TFM_ERROR_GENERIC; } + /* + * Prevent the thread from being preempted, while executing a Secure + * function. This is required to prevent system crashes that could + * occur, if a thead context switch is triggered in the middle of a + * Secure call. + */ + k_sched_lock(); + result = fn(arg0, arg1, arg2, arg3); + /* Unlock the scheduler, to allow the thread to be preempted. */ + k_sched_unlock(); + k_mutex_unlock(&tfm_mutex); return result;